author | tron |
Mon, 14 Feb 2005 18:55:10 +0000 | |
changeset 1370 | c86b2c30fd01 |
parent 1322 | a7fef520f54c |
child 1678 | 187385f01cc9 |
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; |
1299 | 16 |
|
17 |
||
18 |
void CDECL debug(const char *s, ...) |
|
19 |
{ |
|
20 |
va_list va; |
|
21 |
char buf[1024]; |
|
22 |
||
23 |
va_start(va, s); |
|
24 |
vsnprintf(buf, lengthof(buf), s, va); |
|
25 |
va_end(va); |
|
26 |
fprintf(stderr, "dbg: %s\n", buf); |
|
27 |
IConsoleDebug(buf); |
|
28 |
} |
|
29 |
||
30 |
||
31 |
void SetDebugString(const char *s) |
|
32 |
{ |
|
33 |
int v; |
|
34 |
char *end; |
|
35 |
const char *t; |
|
36 |
||
37 |
typedef struct DebugLevel { |
|
38 |
const char* name; |
|
39 |
int* level; |
|
40 |
} DebugLevel; |
|
41 |
||
42 |
#define DEBUG_LEVEL(x) { #x, &_debug_##x##_level } |
|
43 |
static const DebugLevel debug_level[] = { |
|
44 |
DEBUG_LEVEL(ai), |
|
45 |
DEBUG_LEVEL(grf), |
|
46 |
DEBUG_LEVEL(map), |
|
47 |
DEBUG_LEVEL(misc), |
|
48 |
DEBUG_LEVEL(ms), |
|
49 |
DEBUG_LEVEL(net), |
|
1322
a7fef520f54c
(svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents:
1302
diff
changeset
|
50 |
DEBUG_LEVEL(spritecache), |
a7fef520f54c
(svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents:
1302
diff
changeset
|
51 |
DEBUG_LEVEL(oldloader) |
1299 | 52 |
}; |
53 |
#undef DEBUG_LEVEL |
|
54 |
||
55 |
// global debugging level? |
|
56 |
if (*s >= '0' && *s <= '9') { |
|
57 |
const DebugLevel *i; |
|
58 |
||
59 |
v = strtoul(s, &end, 0); |
|
60 |
s = end; |
|
61 |
||
62 |
for (i = debug_level; i != endof(debug_level); ++i) |
|
63 |
*i->level = v; |
|
64 |
} |
|
65 |
||
66 |
// individual levels |
|
67 |
for(;;) { |
|
68 |
const DebugLevel *i; |
|
69 |
int *p; |
|
70 |
||
71 |
// skip delimiters |
|
72 |
while (*s == ' ' || *s == ',' || *s == '\t') s++; |
|
73 |
if (*s == '\0') break; |
|
74 |
||
75 |
t = s; |
|
76 |
while (*s >= 'a' && *s <= 'z') s++; |
|
77 |
||
78 |
// check debugging levels |
|
79 |
p = NULL; |
|
80 |
for (i = debug_level; i != endof(debug_level); ++i) |
|
81 |
if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) { |
|
82 |
p = i->level; |
|
83 |
break; |
|
84 |
} |
|
85 |
||
86 |
if (*s == '=') s++; |
|
87 |
v = strtoul(s, &end, 0); |
|
88 |
s = end; |
|
89 |
if (p != NULL) |
|
90 |
*p = v; |
|
91 |
else { |
|
92 |
ShowInfoF("Unknown debug level '%.*s'", s - t, t); |
|
93 |
return; |
|
94 |
} |
|
95 |
} |
|
96 |
} |