tron@1302: #include "stdafx.h" tron@1302: #include tron@1299: #include tron@1299: #include "ttd.h" tron@1299: #include "console.h" tron@1299: #include "debug.h" tron@1299: tron@1299: int _debug_ai_level; tron@1299: int _debug_grf_level; tron@1299: int _debug_map_level; tron@1299: int _debug_misc_level; tron@1299: int _debug_ms_level; tron@1299: int _debug_net_level; tron@1299: int _debug_spritecache_level; truelight@1322: int _debug_oldloader_level; tron@1299: tron@1299: tron@1299: void CDECL debug(const char *s, ...) tron@1299: { tron@1299: va_list va; tron@1299: char buf[1024]; tron@1299: tron@1299: va_start(va, s); tron@1299: vsnprintf(buf, lengthof(buf), s, va); tron@1299: va_end(va); tron@1299: fprintf(stderr, "dbg: %s\n", buf); tron@1299: IConsoleDebug(buf); tron@1299: } tron@1299: tron@1299: tron@1299: void SetDebugString(const char *s) tron@1299: { tron@1299: int v; tron@1299: char *end; tron@1299: const char *t; tron@1299: tron@1299: typedef struct DebugLevel { tron@1299: const char* name; tron@1299: int* level; tron@1299: } DebugLevel; tron@1299: tron@1299: #define DEBUG_LEVEL(x) { #x, &_debug_##x##_level } tron@1299: static const DebugLevel debug_level[] = { tron@1299: DEBUG_LEVEL(ai), tron@1299: DEBUG_LEVEL(grf), tron@1299: DEBUG_LEVEL(map), tron@1299: DEBUG_LEVEL(misc), tron@1299: DEBUG_LEVEL(ms), tron@1299: DEBUG_LEVEL(net), truelight@1322: DEBUG_LEVEL(spritecache), truelight@1322: DEBUG_LEVEL(oldloader) tron@1299: }; tron@1299: #undef DEBUG_LEVEL tron@1299: tron@1299: // global debugging level? tron@1299: if (*s >= '0' && *s <= '9') { tron@1299: const DebugLevel *i; tron@1299: tron@1299: v = strtoul(s, &end, 0); tron@1299: s = end; tron@1299: tron@1299: for (i = debug_level; i != endof(debug_level); ++i) tron@1299: *i->level = v; tron@1299: } tron@1299: tron@1299: // individual levels tron@1299: for(;;) { tron@1299: const DebugLevel *i; tron@1299: int *p; tron@1299: tron@1299: // skip delimiters tron@1299: while (*s == ' ' || *s == ',' || *s == '\t') s++; tron@1299: if (*s == '\0') break; tron@1299: tron@1299: t = s; tron@1299: while (*s >= 'a' && *s <= 'z') s++; tron@1299: tron@1299: // check debugging levels tron@1299: p = NULL; tron@1299: for (i = debug_level; i != endof(debug_level); ++i) tron@1299: if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) { tron@1299: p = i->level; tron@1299: break; tron@1299: } tron@1299: tron@1299: if (*s == '=') s++; tron@1299: v = strtoul(s, &end, 0); tron@1299: s = end; tron@1299: if (p != NULL) tron@1299: *p = v; tron@1299: else { tron@1299: ShowInfoF("Unknown debug level '%.*s'", s - t, t); tron@1299: return; tron@1299: } tron@1299: } tron@1299: }