author | tron |
Fri, 22 Apr 2005 05:41:09 +0000 | |
changeset 1718 | 96d76767ea93 |
parent 1678 | 187385f01cc9 |
child 1847 | d94ed71b61e7 |
permissions | -rw-r--r-- |
1302 | 1 |
#include "stdafx.h" |
2 |
#include <stdio.h> |
|
1299 | 3 |
#include <stdarg.h> |
4 |
#include "ttd.h" |
|
5 |
#include "console.h" |
|
6 |
#include "debug.h" |
|
7 |
||
8 |
int _debug_ai_level; |
|
9 |
int _debug_grf_level; |
|
10 |
int _debug_map_level; |
|
11 |
int _debug_misc_level; |
|
12 |
int _debug_ms_level; |
|
13 |
int _debug_net_level; |
|
14 |
int _debug_spritecache_level; |
|
1322
a7fef520f54c
(svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents:
1302
diff
changeset
|
15 |
int _debug_oldloader_level; |
1678
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1322
diff
changeset
|
16 |
int _debug_npf_level; |
1299 | 17 |
|
18 |
||
19 |
void CDECL debug(const char *s, ...) |
|
20 |
{ |
|
21 |
va_list va; |
|
22 |
char buf[1024]; |
|
23 |
||
24 |
va_start(va, s); |
|
25 |
vsnprintf(buf, lengthof(buf), s, va); |
|
26 |
va_end(va); |
|
27 |
fprintf(stderr, "dbg: %s\n", buf); |
|
28 |
IConsoleDebug(buf); |
|
29 |
} |
|
30 |
||
31 |
||
32 |
void SetDebugString(const char *s) |
|
33 |
{ |
|
34 |
int v; |
|
35 |
char *end; |
|
36 |
const char *t; |
|
37 |
||
38 |
typedef struct DebugLevel { |
|
39 |
const char* name; |
|
40 |
int* level; |
|
41 |
} DebugLevel; |
|
42 |
||
43 |
#define DEBUG_LEVEL(x) { #x, &_debug_##x##_level } |
|
44 |
static const DebugLevel debug_level[] = { |
|
45 |
DEBUG_LEVEL(ai), |
|
46 |
DEBUG_LEVEL(grf), |
|
47 |
DEBUG_LEVEL(map), |
|
48 |
DEBUG_LEVEL(misc), |
|
49 |
DEBUG_LEVEL(ms), |
|
50 |
DEBUG_LEVEL(net), |
|
1322
a7fef520f54c
(svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents:
1302
diff
changeset
|
51 |
DEBUG_LEVEL(spritecache), |
1678
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1322
diff
changeset
|
52 |
DEBUG_LEVEL(oldloader), |
187385f01cc9
(svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents:
1322
diff
changeset
|
53 |
DEBUG_LEVEL(npf) |
1299 | 54 |
}; |
55 |
#undef DEBUG_LEVEL |
|
56 |
||
57 |
// global debugging level? |
|
58 |
if (*s >= '0' && *s <= '9') { |
|
59 |
const DebugLevel *i; |
|
60 |
||
61 |
v = strtoul(s, &end, 0); |
|
62 |
s = end; |
|
63 |
||
64 |
for (i = debug_level; i != endof(debug_level); ++i) |
|
65 |
*i->level = v; |
|
66 |
} |
|
67 |
||
68 |
// individual levels |
|
69 |
for(;;) { |
|
70 |
const DebugLevel *i; |
|
71 |
int *p; |
|
72 |
||
73 |
// skip delimiters |
|
74 |
while (*s == ' ' || *s == ',' || *s == '\t') s++; |
|
75 |
if (*s == '\0') break; |
|
76 |
||
77 |
t = s; |
|
78 |
while (*s >= 'a' && *s <= 'z') s++; |
|
79 |
||
80 |
// check debugging levels |
|
81 |
p = NULL; |
|
82 |
for (i = debug_level; i != endof(debug_level); ++i) |
|
83 |
if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) { |
|
84 |
p = i->level; |
|
85 |
break; |
|
86 |
} |
|
87 |
||
88 |
if (*s == '=') s++; |
|
89 |
v = strtoul(s, &end, 0); |
|
90 |
s = end; |
|
91 |
if (p != NULL) |
|
92 |
*p = v; |
|
93 |
else { |
|
94 |
ShowInfoF("Unknown debug level '%.*s'", s - t, t); |
|
95 |
return; |
|
96 |
} |
|
97 |
} |
|
98 |
} |