author | matthijs |
Wed, 22 Mar 2006 21:04:13 +0000 | |
branch | 0.4.5 |
changeset 9951 | 7a623ae69d11 |
parent 2916 | 8f1aa489701f |
child 3900 | 4984308f9125 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
1302 | 3 |
#include "stdafx.h" |
4 |
#include <stdio.h> |
|
1299 | 5 |
#include <stdarg.h> |
1891
92a3b0aa0946
(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
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2125
diff
changeset
|
9 |
#include "functions.h" |
1847
47703af63895
(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
58a293892a66
(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
8697b73baa64
(svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents:
1302
diff
changeset
|
20 |
int _debug_oldloader_level; |
2125
3098398bf7ff
(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
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), |
2210
58a293892a66
(svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents:
2186
diff
changeset
|
45 |
DEBUG_LEVEL(driver), |
1847
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
46 |
DEBUG_LEVEL(grf), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
47 |
DEBUG_LEVEL(map), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
48 |
DEBUG_LEVEL(misc), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
49 |
DEBUG_LEVEL(ms), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
50 |
DEBUG_LEVEL(net), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
51 |
DEBUG_LEVEL(spritecache), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
52 |
DEBUG_LEVEL(oldloader), |
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), |
1847
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
54 |
DEBUG_LEVEL(npf) |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
55 |
}; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
56 |
#undef DEBUG_LEVEL |
1299 | 57 |
|
58 |
void SetDebugString(const char *s) |
|
59 |
{ |
|
60 |
int v; |
|
61 |
char *end; |
|
62 |
const char *t; |
|
63 |
||
64 |
// global debugging level? |
|
65 |
if (*s >= '0' && *s <= '9') { |
|
66 |
const DebugLevel *i; |
|
67 |
||
68 |
v = strtoul(s, &end, 0); |
|
69 |
s = end; |
|
70 |
||
2639 | 71 |
for (i = debug_level; i != endof(debug_level); ++i) *i->level = v; |
1299 | 72 |
} |
73 |
||
74 |
// individual levels |
|
2639 | 75 |
for (;;) { |
1299 | 76 |
const DebugLevel *i; |
77 |
int *p; |
|
78 |
||
79 |
// skip delimiters |
|
80 |
while (*s == ' ' || *s == ',' || *s == '\t') s++; |
|
81 |
if (*s == '\0') break; |
|
82 |
||
83 |
t = s; |
|
84 |
while (*s >= 'a' && *s <= 'z') s++; |
|
85 |
||
86 |
// check debugging levels |
|
87 |
p = NULL; |
|
88 |
for (i = debug_level; i != endof(debug_level); ++i) |
|
89 |
if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) { |
|
90 |
p = i->level; |
|
91 |
break; |
|
92 |
} |
|
93 |
||
94 |
if (*s == '=') s++; |
|
95 |
v = strtoul(s, &end, 0); |
|
96 |
s = end; |
|
2639 | 97 |
if (p != NULL) { |
1299 | 98 |
*p = v; |
2639 | 99 |
} else { |
1299 | 100 |
ShowInfoF("Unknown debug level '%.*s'", s - t, t); |
101 |
return; |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
1847
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
105 |
|
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
106 |
/** 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
|
107 |
* 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
|
108 |
* @return string with debug-levels |
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 |
const char *GetDebugString(void) |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
111 |
{ |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
112 |
const DebugLevel *i; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
113 |
static char dbgstr[100]; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
114 |
char dbgval[20]; |
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 |
memset(dbgstr, 0, sizeof(dbgstr)); |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
117 |
i = debug_level; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
118 |
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
|
119 |
|
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
} |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
124 |
|
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
125 |
return dbgstr; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
126 |
} |