author | Darkvater |
Tue, 31 Oct 2006 23:04:47 +0000 | |
changeset 5009 | 0ae33f104d4f |
parent 3900 | 2c84ed52709d |
child 5108 | aeaef6fe53b7 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
1302 | 3 |
#include "stdafx.h" |
4 |
#include <stdio.h> |
|
1299 | 5 |
#include <stdarg.h> |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1847
diff
changeset
|
6 |
#include "openttd.h" |
1299 | 7 |
#include "console.h" |
8 |
#include "debug.h" |
|
2163
b17b313113a0
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2125
diff
changeset
|
9 |
#include "functions.h" |
1847
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
10 |
#include "string.h" |
1299 | 11 |
|
12 |
int _debug_ai_level; |
|
2210
b76184e0929c
(svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents:
2186
diff
changeset
|
13 |
int _debug_driver_level; |
1299 | 14 |
int _debug_grf_level; |
15 |
int _debug_map_level; |
|
16 |
int _debug_misc_level; |
|
17 |
int _debug_ms_level; |
|
18 |
int _debug_net_level; |
|
19 |
int _debug_spritecache_level; |
|
1322
a7fef520f54c
(svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents:
1302
diff
changeset
|
20 |
int _debug_oldloader_level; |
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2066
diff
changeset
|
21 |
int _debug_ntp_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
|
22 |
int _debug_npf_level; |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
2916
diff
changeset
|
23 |
int _debug_yapf_level; |
1299 | 24 |
|
25 |
||
26 |
void CDECL debug(const char *s, ...) |
|
27 |
{ |
|
28 |
va_list va; |
|
29 |
char buf[1024]; |
|
30 |
||
31 |
va_start(va, s); |
|
32 |
vsnprintf(buf, lengthof(buf), s, va); |
|
33 |
va_end(va); |
|
34 |
fprintf(stderr, "dbg: %s\n", buf); |
|
35 |
IConsoleDebug(buf); |
|
36 |
} |
|
37 |
||
1847
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
38 |
typedef struct DebugLevel { |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
39 |
const char *name; |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
40 |
int *level; |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
41 |
} DebugLevel; |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
42 |
|
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
43 |
#define DEBUG_LEVEL(x) { #x, &_debug_##x##_level } |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
44 |
static const DebugLevel debug_level[] = { |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
45 |
DEBUG_LEVEL(ai), |
2210
b76184e0929c
(svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents:
2186
diff
changeset
|
46 |
DEBUG_LEVEL(driver), |
1847
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
47 |
DEBUG_LEVEL(grf), |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
48 |
DEBUG_LEVEL(map), |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
49 |
DEBUG_LEVEL(misc), |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
50 |
DEBUG_LEVEL(ms), |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
51 |
DEBUG_LEVEL(net), |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
52 |
DEBUG_LEVEL(spritecache), |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
53 |
DEBUG_LEVEL(oldloader), |
2125
edc17858f9f6
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2066
diff
changeset
|
54 |
DEBUG_LEVEL(ntp), |
3900
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
2916
diff
changeset
|
55 |
DEBUG_LEVEL(npf), |
2c84ed52709d
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
2916
diff
changeset
|
56 |
DEBUG_LEVEL(yapf) |
1847
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
57 |
}; |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
58 |
#undef DEBUG_LEVEL |
1299 | 59 |
|
60 |
void SetDebugString(const char *s) |
|
61 |
{ |
|
62 |
int v; |
|
63 |
char *end; |
|
64 |
const char *t; |
|
65 |
||
66 |
// global debugging level? |
|
67 |
if (*s >= '0' && *s <= '9') { |
|
68 |
const DebugLevel *i; |
|
69 |
||
70 |
v = strtoul(s, &end, 0); |
|
71 |
s = end; |
|
72 |
||
2639 | 73 |
for (i = debug_level; i != endof(debug_level); ++i) *i->level = v; |
1299 | 74 |
} |
75 |
||
76 |
// individual levels |
|
2639 | 77 |
for (;;) { |
1299 | 78 |
const DebugLevel *i; |
79 |
int *p; |
|
80 |
||
81 |
// skip delimiters |
|
82 |
while (*s == ' ' || *s == ',' || *s == '\t') s++; |
|
83 |
if (*s == '\0') break; |
|
84 |
||
85 |
t = s; |
|
86 |
while (*s >= 'a' && *s <= 'z') s++; |
|
87 |
||
88 |
// check debugging levels |
|
89 |
p = NULL; |
|
90 |
for (i = debug_level; i != endof(debug_level); ++i) |
|
91 |
if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) { |
|
92 |
p = i->level; |
|
93 |
break; |
|
94 |
} |
|
95 |
||
96 |
if (*s == '=') s++; |
|
97 |
v = strtoul(s, &end, 0); |
|
98 |
s = end; |
|
2639 | 99 |
if (p != NULL) { |
1299 | 100 |
*p = v; |
2639 | 101 |
} else { |
1299 | 102 |
ShowInfoF("Unknown debug level '%.*s'", s - t, t); |
103 |
return; |
|
104 |
} |
|
105 |
} |
|
106 |
} |
|
1847
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
107 |
|
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
108 |
/** Print out the current debug-level |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
109 |
* Just return a string with the values of all the debug categorites |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
110 |
* @return string with debug-levels |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
111 |
*/ |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
112 |
const char *GetDebugString(void) |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
113 |
{ |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
114 |
const DebugLevel *i; |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
115 |
static char dbgstr[100]; |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
116 |
char dbgval[20]; |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
117 |
|
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
118 |
memset(dbgstr, 0, sizeof(dbgstr)); |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
119 |
i = debug_level; |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
120 |
snprintf(dbgstr, sizeof(dbgstr), "%s=%d", i->name, *i->level); |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
121 |
|
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
122 |
for (i++; i != endof(debug_level); i++) { |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
123 |
snprintf(dbgval, sizeof(dbgval), ", %s=%d", i->name, *i->level); |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
124 |
ttd_strlcat(dbgstr, dbgval, sizeof(dbgstr)); |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
125 |
} |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
126 |
|
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
127 |
return dbgstr; |
d94ed71b61e7
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
128 |
} |