1299
|
1 |
#include <stdarg.h>
|
|
2 |
#include "stdafx.h"
|
|
3 |
#include "ttd.h"
|
|
4 |
#include "console.h"
|
|
5 |
#include "debug.h"
|
|
6 |
|
|
7 |
int _debug_ai_level;
|
|
8 |
int _debug_grf_level;
|
|
9 |
int _debug_map_level;
|
|
10 |
int _debug_misc_level;
|
|
11 |
int _debug_ms_level;
|
|
12 |
int _debug_net_level;
|
|
13 |
int _debug_spritecache_level;
|
|
14 |
|
|
15 |
|
|
16 |
void CDECL debug(const char *s, ...)
|
|
17 |
{
|
|
18 |
va_list va;
|
|
19 |
char buf[1024];
|
|
20 |
|
|
21 |
va_start(va, s);
|
|
22 |
vsnprintf(buf, lengthof(buf), s, va);
|
|
23 |
va_end(va);
|
|
24 |
fprintf(stderr, "dbg: %s\n", buf);
|
|
25 |
IConsoleDebug(buf);
|
|
26 |
}
|
|
27 |
|
|
28 |
|
|
29 |
void SetDebugString(const char *s)
|
|
30 |
{
|
|
31 |
int v;
|
|
32 |
char *end;
|
|
33 |
const char *t;
|
|
34 |
|
|
35 |
typedef struct DebugLevel {
|
|
36 |
const char* name;
|
|
37 |
int* level;
|
|
38 |
} DebugLevel;
|
|
39 |
|
|
40 |
#define DEBUG_LEVEL(x) { #x, &_debug_##x##_level }
|
|
41 |
static const DebugLevel debug_level[] = {
|
|
42 |
DEBUG_LEVEL(ai),
|
|
43 |
DEBUG_LEVEL(grf),
|
|
44 |
DEBUG_LEVEL(map),
|
|
45 |
DEBUG_LEVEL(misc),
|
|
46 |
DEBUG_LEVEL(ms),
|
|
47 |
DEBUG_LEVEL(net),
|
|
48 |
DEBUG_LEVEL(spritecache)
|
|
49 |
};
|
|
50 |
#undef DEBUG_LEVEL
|
|
51 |
|
|
52 |
// global debugging level?
|
|
53 |
if (*s >= '0' && *s <= '9') {
|
|
54 |
const DebugLevel *i;
|
|
55 |
|
|
56 |
v = strtoul(s, &end, 0);
|
|
57 |
s = end;
|
|
58 |
|
|
59 |
for (i = debug_level; i != endof(debug_level); ++i)
|
|
60 |
*i->level = v;
|
|
61 |
}
|
|
62 |
|
|
63 |
// individual levels
|
|
64 |
for(;;) {
|
|
65 |
const DebugLevel *i;
|
|
66 |
int *p;
|
|
67 |
|
|
68 |
// skip delimiters
|
|
69 |
while (*s == ' ' || *s == ',' || *s == '\t') s++;
|
|
70 |
if (*s == '\0') break;
|
|
71 |
|
|
72 |
t = s;
|
|
73 |
while (*s >= 'a' && *s <= 'z') s++;
|
|
74 |
|
|
75 |
// check debugging levels
|
|
76 |
p = NULL;
|
|
77 |
for (i = debug_level; i != endof(debug_level); ++i)
|
|
78 |
if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) {
|
|
79 |
p = i->level;
|
|
80 |
break;
|
|
81 |
}
|
|
82 |
|
|
83 |
if (*s == '=') s++;
|
|
84 |
v = strtoul(s, &end, 0);
|
|
85 |
s = end;
|
|
86 |
if (p != NULL)
|
|
87 |
*p = v;
|
|
88 |
else {
|
|
89 |
ShowInfoF("Unknown debug level '%.*s'", s - t, t);
|
|
90 |
return;
|
|
91 |
}
|
|
92 |
}
|
|
93 |
}
|