author | Darkvater |
Thu, 02 Jun 2005 19:30:21 +0000 | |
changeset 1891 | 92a3b0aa0946 |
parent 1847 | 47703af63895 |
child 2008 | c9d6585c96c8 |
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; |
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
|
17 |
int _debug_npf_level; |
1299 | 18 |
|
19 |
||
20 |
void CDECL debug(const char *s, ...) |
|
21 |
{ |
|
22 |
va_list va; |
|
23 |
char buf[1024]; |
|
24 |
||
25 |
va_start(va, s); |
|
26 |
vsnprintf(buf, lengthof(buf), s, va); |
|
27 |
va_end(va); |
|
28 |
fprintf(stderr, "dbg: %s\n", buf); |
|
29 |
IConsoleDebug(buf); |
|
30 |
} |
|
31 |
||
1847
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
32 |
typedef struct DebugLevel { |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
33 |
const char *name; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
34 |
int *level; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
35 |
} DebugLevel; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
36 |
|
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
37 |
#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
|
38 |
static const DebugLevel debug_level[] = { |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
39 |
DEBUG_LEVEL(ai), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
40 |
DEBUG_LEVEL(grf), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
41 |
DEBUG_LEVEL(map), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
42 |
DEBUG_LEVEL(misc), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
43 |
DEBUG_LEVEL(ms), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
44 |
DEBUG_LEVEL(net), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
45 |
DEBUG_LEVEL(spritecache), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
46 |
DEBUG_LEVEL(oldloader), |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
47 |
DEBUG_LEVEL(npf) |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
48 |
}; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
49 |
#undef DEBUG_LEVEL |
1299 | 50 |
|
51 |
void SetDebugString(const char *s) |
|
52 |
{ |
|
53 |
int v; |
|
54 |
char *end; |
|
55 |
const char *t; |
|
56 |
||
57 |
// global debugging level? |
|
58 |
if (*s >= '0' && *s <= '9') { |
|
59 |
const DebugLevel *i; |
|
60 |
||
61 |
v = strtoul(s, &end, 0); |
|
62 |
s = end; |
|
63 |
||
64 |
for (i = debug_level; i != endof(debug_level); ++i) |
|
65 |
*i->level = v; |
|
66 |
} |
|
67 |
||
68 |
// individual levels |
|
69 |
for(;;) { |
|
70 |
const DebugLevel *i; |
|
71 |
int *p; |
|
72 |
||
73 |
// skip delimiters |
|
74 |
while (*s == ' ' || *s == ',' || *s == '\t') s++; |
|
75 |
if (*s == '\0') break; |
|
76 |
||
77 |
t = s; |
|
78 |
while (*s >= 'a' && *s <= 'z') s++; |
|
79 |
||
80 |
// check debugging levels |
|
81 |
p = NULL; |
|
82 |
for (i = debug_level; i != endof(debug_level); ++i) |
|
83 |
if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) { |
|
84 |
p = i->level; |
|
85 |
break; |
|
86 |
} |
|
87 |
||
88 |
if (*s == '=') s++; |
|
89 |
v = strtoul(s, &end, 0); |
|
90 |
s = end; |
|
91 |
if (p != NULL) |
|
92 |
*p = v; |
|
93 |
else { |
|
94 |
ShowInfoF("Unknown debug level '%.*s'", s - t, t); |
|
95 |
return; |
|
96 |
} |
|
97 |
} |
|
98 |
} |
|
1847
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
99 |
|
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
100 |
/** 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
|
101 |
* 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
|
102 |
* @return string with debug-levels |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
103 |
*/ |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
104 |
const char *GetDebugString(void) |
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 |
const DebugLevel *i; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
107 |
static char dbgstr[100]; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
108 |
char dbgval[20]; |
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 |
memset(dbgstr, 0, sizeof(dbgstr)); |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
111 |
i = debug_level; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
112 |
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
|
113 |
|
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
114 |
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
|
115 |
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
|
116 |
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
|
117 |
} |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
118 |
|
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
119 |
return dbgstr; |
47703af63895
(svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents:
1678
diff
changeset
|
120 |
} |