author | ludde |
Tue, 19 Jul 2005 11:42:40 +0000 | |
changeset 2125 | 3098398bf7ff |
parent 2066 | 9ee1aea9701f |
child 2163 | 637ec3c361f5 |
permissions | -rw-r--r-- |
1302 | 1 |
#include "stdafx.h" |
2 |
#include <stdio.h> |
|
1299 | 3 |
#include <stdarg.h> |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1847
diff
changeset
|
4 |
#include "openttd.h" |
1299 | 5 |
#include "console.h" |
6 |
#include "debug.h" |
|
1847
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
7 |
#include "string.h" |
1299 | 8 |
|
9 |
int _debug_ai_level; |
|
10 |
int _debug_grf_level; |
|
11 |
int _debug_map_level; |
|
12 |
int _debug_misc_level; |
|
13 |
int _debug_ms_level; |
|
14 |
int _debug_net_level; |
|
15 |
int _debug_spritecache_level; |
|
1322
8697b73baa64
(svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents:
1302
diff
changeset
|
16 |
int _debug_oldloader_level; |
2008
c9d6585c96c8
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1891
diff
changeset
|
17 |
int _debug_pbs_level; |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2066
diff
changeset
|
18 |
int _debug_ntp_level; |
2033
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2008
diff
changeset
|
19 |
#ifdef GPMI |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2008
diff
changeset
|
20 |
int _debug_gpmi_level; |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2008
diff
changeset
|
21 |
#endif /* GPMI */ |
1678
838dd6f46081
(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; |
1299 | 23 |
|
24 |
||
25 |
void CDECL debug(const char *s, ...) |
|
26 |
{ |
|
27 |
va_list va; |
|
28 |
char buf[1024]; |
|
29 |
||
30 |
va_start(va, s); |
|
31 |
vsnprintf(buf, lengthof(buf), s, va); |
|
32 |
va_end(va); |
|
33 |
fprintf(stderr, "dbg: %s\n", buf); |
|
34 |
IConsoleDebug(buf); |
|
35 |
} |
|
36 |
||
1847
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
37 |
typedef struct DebugLevel { |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
38 |
const char *name; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
39 |
int *level; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
40 |
} DebugLevel; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
41 |
|
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
42 |
#define DEBUG_LEVEL(x) { #x, &_debug_##x##_level } |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
43 |
static const DebugLevel debug_level[] = { |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
44 |
DEBUG_LEVEL(ai), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
45 |
DEBUG_LEVEL(grf), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
46 |
DEBUG_LEVEL(map), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
47 |
DEBUG_LEVEL(misc), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
48 |
DEBUG_LEVEL(ms), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
49 |
DEBUG_LEVEL(net), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
50 |
DEBUG_LEVEL(spritecache), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
51 |
DEBUG_LEVEL(oldloader), |
2008
c9d6585c96c8
(svn r2516) - Feature: [pbs] Implement path-based-signalling. This allows multiple trains within the same signal block, provided their paths dont intersect. For this the block must have all exit and entry signals be pbs signals. Place these by ctrl-clicking 4 times on a normal signal.
hackykid
parents:
1891
diff
changeset
|
52 |
DEBUG_LEVEL(pbs), |
2125
3098398bf7ff
(svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents:
2066
diff
changeset
|
53 |
DEBUG_LEVEL(ntp), |
2033
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2008
diff
changeset
|
54 |
#ifdef GPMI |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2008
diff
changeset
|
55 |
DEBUG_LEVEL(gpmi), |
2066
9ee1aea9701f
(svn r2576) -Fix: Whitespace. Somehow a commit bypassed the pre-commit hook
celestar
parents:
2033
diff
changeset
|
56 |
#endif |
1847
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
57 |
DEBUG_LEVEL(npf) |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
58 |
}; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
59 |
#undef DEBUG_LEVEL |
1299 | 60 |
|
61 |
void SetDebugString(const char *s) |
|
62 |
{ |
|
63 |
int v; |
|
64 |
char *end; |
|
65 |
const char *t; |
|
66 |
||
67 |
// global debugging level? |
|
68 |
if (*s >= '0' && *s <= '9') { |
|
69 |
const DebugLevel *i; |
|
70 |
||
71 |
v = strtoul(s, &end, 0); |
|
72 |
s = end; |
|
73 |
||
74 |
for (i = debug_level; i != endof(debug_level); ++i) |
|
75 |
*i->level = v; |
|
76 |
} |
|
77 |
||
78 |
// individual levels |
|
79 |
for(;;) { |
|
80 |
const DebugLevel *i; |
|
81 |
int *p; |
|
82 |
||
83 |
// skip delimiters |
|
84 |
while (*s == ' ' || *s == ',' || *s == '\t') s++; |
|
85 |
if (*s == '\0') break; |
|
86 |
||
87 |
t = s; |
|
88 |
while (*s >= 'a' && *s <= 'z') s++; |
|
89 |
||
90 |
// check debugging levels |
|
91 |
p = NULL; |
|
92 |
for (i = debug_level; i != endof(debug_level); ++i) |
|
93 |
if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) { |
|
94 |
p = i->level; |
|
95 |
break; |
|
96 |
} |
|
97 |
||
98 |
if (*s == '=') s++; |
|
99 |
v = strtoul(s, &end, 0); |
|
100 |
s = end; |
|
101 |
if (p != NULL) |
|
102 |
*p = v; |
|
103 |
else { |
|
104 |
ShowInfoF("Unknown debug level '%.*s'", s - t, t); |
|
105 |
return; |
|
106 |
} |
|
107 |
} |
|
108 |
} |
|
1847
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
109 |
|
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
110 |
/** Print out the current debug-level |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
111 |
* Just return a string with the values of all the debug categorites |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
112 |
* @return string with debug-levels |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
113 |
*/ |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
114 |
const char *GetDebugString(void) |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
115 |
{ |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
116 |
const DebugLevel *i; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
117 |
static char dbgstr[100]; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
118 |
char dbgval[20]; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
119 |
|
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
120 |
memset(dbgstr, 0, sizeof(dbgstr)); |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
121 |
i = debug_level; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
122 |
snprintf(dbgstr, sizeof(dbgstr), "%s=%d", i->name, *i->level); |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
123 |
|
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
124 |
for (i++; i != endof(debug_level); i++) { |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
125 |
snprintf(dbgval, sizeof(dbgval), ", %s=%d", i->name, *i->level); |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
126 |
ttd_strlcat(dbgstr, dbgval, sizeof(dbgstr)); |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
127 |
} |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
128 |
|
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
129 |
return dbgstr; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
130 |
} |
2033
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2008
diff
changeset
|
131 |
|
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2008
diff
changeset
|
132 |
#ifdef GPMI |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2008
diff
changeset
|
133 |
void gpmi_debug_openttd(int level, char *s) |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2008
diff
changeset
|
134 |
{ |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2008
diff
changeset
|
135 |
DEBUG(gpmi, level)("[GPMI] %s", s); |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2008
diff
changeset
|
136 |
} |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2008
diff
changeset
|
137 |
#endif /* GPMI */ |