summaryrefslogtreecommitdiff
path: root/src/log.cpp
blob: 785418cc5099b5a4bc88e96b3702484214099fba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/**

	The Mana World
	Copyright 2004 The Mana World Development Team

    This file is part of The Mana World.

    The Mana World is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    any later version.

    The Mana World is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with The Mana World; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

#include "log.h"

int warning_n; // Keep warning number

#define LOG_FILE "The Mana World.log"
#define LOG_VERSION "0.3"

void init_log() {
#ifdef WIN32
  remove(LOG_FILE);
#else 
	unlink(LOG_FILE);
#endif

  push_config_state();
  set_config_file(LOG_FILE);
#ifdef WIN32 // for the moment i cant find a valuable unix function for _strdate // Sull
	char date[9];
  set_config_string("Core", "date", _strdate(date));
#endif
	set_config_string("Core", "log_version", LOG_VERSION);
	set_config_string("Core", "Allegro_ID", allegro_id);
	switch(os_type) {
		case OSTYPE_UNKNOWN:
			set_config_string("Core", "Os", "unknown, or regular MSDOS");
			break;
		case OSTYPE_WIN3:
			set_config_string("Core", "Os", "Windows 3.1 or earlier");
			break;
		case OSTYPE_WIN95:
			set_config_string("Core", "Os", "Windows 95");
			break;
		case OSTYPE_WIN98:
			set_config_string("Core", "Os", "Windows 98");
			break;
		case OSTYPE_WINME:
			set_config_string("Core", "Os", "Windows ME");
			break;
		case OSTYPE_WINNT:
			set_config_string("Core", "Os", "Windows NT");
			break;
		case OSTYPE_WIN2000:
			set_config_string("Core", "Os", "Windows 2000");
			break;
		case OSTYPE_WINXP:
			set_config_string("Core", "Os", "Windows XP");
			break;
		case OSTYPE_OS2:
			set_config_string("Core", "Os", "OS/2");
			break;
		case OSTYPE_WARP:
			set_config_string("Core", "Os", "OS/2 Warp 3");
			break;
		case OSTYPE_DOSEMU:
			set_config_string("Core", "Os", "Linux DOSEMU");
			break;
		case OSTYPE_OPENDOS:
			set_config_string("Core", "Os", "Caldera OpenDOS");
			break;
		case OSTYPE_LINUX:
			set_config_string("Core", "Os", "Linux");
			break;
		case OSTYPE_SUNOS:
			set_config_string("Core", "Os", "SunOS/Solaris");
			break;
		case OSTYPE_FREEBSD:
			set_config_string("Core", "Os", "FreeBSD");
			break;
		case OSTYPE_NETBSD:
			set_config_string("Core", "Os", "NetBSD");
			break;
		case OSTYPE_IRIX:
			set_config_string("Core", "Os", "IRIX");
			break;
		case OSTYPE_QNX:
			set_config_string("Core", "Os", "QNX");
			break;
		case OSTYPE_UNIX:
			set_config_string("Core", "Os", "Unknown Unix variant");
			break;
		case OSTYPE_BEOS:
			set_config_string("Core", "Os", "BeOS");
			break;
		case OSTYPE_MACOS:
			set_config_string("Core", "Os", "MacOS");
			break;
		default:
			set_config_string("Core", "Os", "Unknown");
			break;
	}
	set_config_int("Core", "Os_version", os_version);
	set_config_int("Core", "Os_revision", os_revision);
	if(os_multitasking)set_config_string("Core", "Multitasking", "TRUE");
	else set_config_string("Core", "Multitasking", "FALSE");

	set_config_string("Core", "CPU_Vendor", cpu_vendor);
	switch(cpu_family) {
		case 3:
			set_config_string("Core", "CPU_Family", "386");
			break;
		case 4:
            set_config_string("Core", "CPU_Family", "486");
			break;
		case 5:
			set_config_string("Core", "CPU_Family", "Pentium");
			break;
		case 6:
			set_config_string("Core", "CPU_Family", "Pentium II/III/PRO/Athlon");
			break;
		case 15:
			set_config_string("Core", "CPU_Family", "Pentium IV");
			break;
		default:
			set_config_string("Core", "CPU_Family", "Unknown");
			set_config_int("Core", "CPU_Family_ID", cpu_family);
			break;
	}

    set_config_int("Core", "CPU_model", cpu_model);	

	set_config_int("Core", "CPU_capabilities", cpu_capabilities);
	pop_config_state();

	warning_n = 0;
}

void log(const char *log_section, const char *log_name, const char *log_text) {
    push_config_state();
    set_config_file(LOG_FILE);
	set_config_string(log_section, log_name, log_text);
	pop_config_state();
}

void log_hex(const char *log_section, const char *log_name, const short log_value) {
	push_config_state();
  set_config_file(LOG_FILE);
	set_config_hex(log_section, log_name, log_value);
	pop_config_state();
}

void log_int(const char *log_section, const char *log_name, const int log_value) {
	push_config_state();
    set_config_file(LOG_FILE);
	set_config_int(log_section, log_name, log_value);
	pop_config_state();
}

void error(const char *error_text) {
	log("Error", "Last_error", error_text);
#ifdef WIN32
	MessageBox(NULL, error_text, "Error", MB_ICONERROR|MB_OK);
#else
	printf("Error: %s", error_text);
#endif
	exit(1);
}

void warning(const char *warning_text) {
	char warning_name[40];
	sprintf(warning_name, "warning_%i", warning_n);
	log("Error", warning_name, warning_text);
}

void status(const char *status_text) {
	log("Status", "last_function", status_text);
}