# HG changeset patch # User tron # Date 1107619139 0 # Node ID 39c06aba09aac22a1624b5f050abc59fc958f2d2 # Parent d04721ba07f96cf98c2dbf8088f1f32d69651748 (svn r1803) Move debugging stuff into files of it's own diff -r d04721ba07f9 -r 39c06aba09aa Makefile --- a/Makefile Sat Feb 05 15:49:57 2005 +0000 +++ b/Makefile Sat Feb 05 15:58:59 2005 +0000 @@ -561,6 +561,7 @@ C_SOURCES += command.c C_SOURCES += console.c C_SOURCES += console_cmds.c +C_SOURCES += debug.c C_SOURCES += dedicated.c C_SOURCES += disaster_cmd.c C_SOURCES += dock_gui.c diff -r d04721ba07f9 -r 39c06aba09aa ai_build.c --- a/ai_build.c Sat Feb 05 15:49:57 2005 +0000 +++ b/ai_build.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "map.h" #include "tile.h" #include "command.h" diff -r d04721ba07f9 -r 39c06aba09aa ai_new.c --- a/ai_new.c Sat Feb 05 15:49:57 2005 +0000 +++ b/ai_new.c Sat Feb 05 15:58:59 2005 +0000 @@ -15,6 +15,7 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "tile.h" diff -r d04721ba07f9 -r 39c06aba09aa ai_pathfinder.c --- a/ai_pathfinder.c Sat Feb 05 15:49:57 2005 +0000 +++ b/ai_pathfinder.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "map.h" #include "tile.h" #include "command.h" diff -r d04721ba07f9 -r 39c06aba09aa ai_shared.c --- a/ai_shared.c Sat Feb 05 15:49:57 2005 +0000 +++ b/ai_shared.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "map.h" #include "ai.h" #include "vehicle.h" diff -r d04721ba07f9 -r 39c06aba09aa aircraft_cmd.c --- a/aircraft_cmd.c Sat Feb 05 15:49:57 2005 +0000 +++ b/aircraft_cmd.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "tile.h" diff -r d04721ba07f9 -r 39c06aba09aa aircraft_gui.c --- a/aircraft_gui.c Sat Feb 05 15:49:57 2005 +0000 +++ b/aircraft_gui.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "tile.h" diff -r d04721ba07f9 -r 39c06aba09aa airport.c --- a/airport.c Sat Feb 05 15:49:57 2005 +0000 +++ b/airport.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "map.h" #include "airport.h" diff -r d04721ba07f9 -r 39c06aba09aa console.h --- a/console.h Sat Feb 05 15:49:57 2005 +0000 +++ b/console.h Sat Feb 05 15:58:59 2005 +0000 @@ -104,10 +104,6 @@ VARDEF byte _iconsole_color_commands; VARDEF _iconsole_modes _iconsole_mode; -// ** ttd.c functions ** // - -void SetDebugString(const char* s); - // ** console functions ** // void IConsoleInit(void); diff -r d04721ba07f9 -r 39c06aba09aa console_cmds.c --- a/console_cmds.c Sat Feb 05 15:49:57 2005 +0000 +++ b/console_cmds.c Sat Feb 05 15:58:59 2005 +0000 @@ -2,6 +2,7 @@ #include "stdafx.h" #include "ttd.h" #include "console.h" +#include "debug.h" #include "engine.h" #include "functions.h" #include "variables.h" diff -r d04721ba07f9 -r 39c06aba09aa debug.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debug.c Sat Feb 05 15:58:59 2005 +0000 @@ -0,0 +1,93 @@ +#include +#include "stdafx.h" +#include "ttd.h" +#include "console.h" +#include "debug.h" + +int _debug_ai_level; +int _debug_grf_level; +int _debug_map_level; +int _debug_misc_level; +int _debug_ms_level; +int _debug_net_level; +int _debug_spritecache_level; + + +void CDECL debug(const char *s, ...) +{ + va_list va; + char buf[1024]; + + va_start(va, s); + vsnprintf(buf, lengthof(buf), s, va); + va_end(va); + fprintf(stderr, "dbg: %s\n", buf); + IConsoleDebug(buf); +} + + +void SetDebugString(const char *s) +{ + int v; + char *end; + const char *t; + + typedef struct DebugLevel { + const char* name; + int* level; + } DebugLevel; + + #define DEBUG_LEVEL(x) { #x, &_debug_##x##_level } + static const DebugLevel debug_level[] = { + DEBUG_LEVEL(ai), + DEBUG_LEVEL(grf), + DEBUG_LEVEL(map), + DEBUG_LEVEL(misc), + DEBUG_LEVEL(ms), + DEBUG_LEVEL(net), + DEBUG_LEVEL(spritecache) + }; + #undef DEBUG_LEVEL + + // global debugging level? + if (*s >= '0' && *s <= '9') { + const DebugLevel *i; + + v = strtoul(s, &end, 0); + s = end; + + for (i = debug_level; i != endof(debug_level); ++i) + *i->level = v; + } + + // individual levels + for(;;) { + const DebugLevel *i; + int *p; + + // skip delimiters + while (*s == ' ' || *s == ',' || *s == '\t') s++; + if (*s == '\0') break; + + t = s; + while (*s >= 'a' && *s <= 'z') s++; + + // check debugging levels + p = NULL; + for (i = debug_level; i != endof(debug_level); ++i) + if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) { + p = i->level; + break; + } + + if (*s == '=') s++; + v = strtoul(s, &end, 0); + s = end; + if (p != NULL) + *p = v; + else { + ShowInfoF("Unknown debug level '%.*s'", s - t, t); + return; + } + } +} diff -r d04721ba07f9 -r 39c06aba09aa debug.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/debug.h Sat Feb 05 15:58:59 2005 +0000 @@ -0,0 +1,22 @@ +#ifndef DEBUG_H +#define DEBUG_H + +#ifdef NO_DEBUG_MESSAGES + #define DEBUG(name, level) +#else + #define DEBUG(name, level) if (level == 0 || _debug_ ## name ## _level >= level) debug + + extern int _debug_ai_level; + extern int _debug_grf_level; + extern int _debug_map_level; + extern int _debug_misc_level; + extern int _debug_ms_level; + extern int _debug_net_level; + extern int _debug_spritecache_level; +#endif + +void CDECL debug(const char *s, ...); + +void SetDebugString(const char *s); + +#endif diff -r d04721ba07f9 -r 39c06aba09aa dedicated.c --- a/dedicated.c Sat Feb 05 15:49:57 2005 +0000 +++ b/dedicated.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "network.h" #include "hal.h" diff -r d04721ba07f9 -r 39c06aba09aa engine.c --- a/engine.c Sat Feb 05 15:49:57 2005 +0000 +++ b/engine.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "engine.h" #include "table/engines.h" diff -r d04721ba07f9 -r 39c06aba09aa industry_gui.c --- a/industry_gui.c Sat Feb 05 15:49:57 2005 +0000 +++ b/industry_gui.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" //#include "gui.h" diff -r d04721ba07f9 -r 39c06aba09aa map.c --- a/map.c Sat Feb 05 15:49:57 2005 +0000 +++ b/map.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "functions.h" #include "map.h" diff -r d04721ba07f9 -r 39c06aba09aa misc_gui.c --- a/misc_gui.c Sat Feb 05 15:49:57 2005 +0000 +++ b/misc_gui.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "window.h" diff -r d04721ba07f9 -r 39c06aba09aa namegen.c --- a/namegen.c Sat Feb 05 15:49:57 2005 +0000 +++ b/namegen.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,6 +1,6 @@ #include "stdafx.h" #include "ttd.h" - +#include "debug.h" #include "table/namegen.h" static inline uint32 SeedChance(int shift_by, int max, uint32 seed) diff -r d04721ba07f9 -r 39c06aba09aa network.c --- a/network.c Sat Feb 05 15:49:57 2005 +0000 +++ b/network.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "debug.h" #include "map.h" #include "network_data.h" diff -r d04721ba07f9 -r 39c06aba09aa network_client.c --- a/network_client.c Sat Feb 05 15:49:57 2005 +0000 +++ b/network_client.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "debug.h" #include "network_data.h" #ifdef ENABLE_NETWORK diff -r d04721ba07f9 -r 39c06aba09aa network_data.c --- a/network_data.c Sat Feb 05 15:49:57 2005 +0000 +++ b/network_data.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "debug.h" #include "network_data.h" // Is the network enabled? diff -r d04721ba07f9 -r 39c06aba09aa network_gamelist.c --- a/network_gamelist.c Sat Feb 05 15:49:57 2005 +0000 +++ b/network_gamelist.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "debug.h" #include "network_data.h" #ifdef ENABLE_NETWORK diff -r d04721ba07f9 -r 39c06aba09aa network_server.c --- a/network_server.c Sat Feb 05 15:49:57 2005 +0000 +++ b/network_server.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "debug.h" #include "network_data.h" #ifdef ENABLE_NETWORK diff -r d04721ba07f9 -r 39c06aba09aa network_udp.c --- a/network_udp.c Sat Feb 05 15:49:57 2005 +0000 +++ b/network_udp.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "debug.h" #include "network_data.h" #ifdef ENABLE_NETWORK diff -r d04721ba07f9 -r 39c06aba09aa newgrf.c --- a/newgrf.c Sat Feb 05 15:49:57 2005 +0000 +++ b/newgrf.c Sat Feb 05 15:58:59 2005 +0000 @@ -3,6 +3,7 @@ #include #include "ttd.h" +#include "debug.h" #include "gfx.h" #include "fileio.h" #include "engine.h" diff -r d04721ba07f9 -r 39c06aba09aa npf.c --- a/npf.c Sat Feb 05 15:49:57 2005 +0000 +++ b/npf.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "npf.h" #include "aystar.h" #include "macros.h" diff -r d04721ba07f9 -r 39c06aba09aa pool.c --- a/pool.c Sat Feb 05 15:49:57 2005 +0000 +++ b/pool.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "pool.h" /** diff -r d04721ba07f9 -r 39c06aba09aa roadveh_cmd.c --- a/roadveh_cmd.c Sat Feb 05 15:49:57 2005 +0000 +++ b/roadveh_cmd.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "tile.h" diff -r d04721ba07f9 -r 39c06aba09aa roadveh_gui.c --- a/roadveh_gui.c Sat Feb 05 15:49:57 2005 +0000 +++ b/roadveh_gui.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "window.h" diff -r d04721ba07f9 -r 39c06aba09aa saveload.c --- a/saveload.c Sat Feb 05 15:49:57 2005 +0000 +++ b/saveload.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "vehicle.h" #include "station.h" #include "town.h" diff -r d04721ba07f9 -r 39c06aba09aa screenshot.c --- a/screenshot.c Sat Feb 05 15:49:57 2005 +0000 +++ b/screenshot.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "gfx.h" #include "viewport.h" diff -r d04721ba07f9 -r 39c06aba09aa sdl.c --- a/sdl.c Sat Feb 05 15:49:57 2005 +0000 +++ b/sdl.c Sat Feb 05 15:58:59 2005 +0000 @@ -2,6 +2,7 @@ #if defined(WITH_SDL) #include "ttd.h" +#include "debug.h" #include "gfx.h" #include "sound.h" #include "window.h" diff -r d04721ba07f9 -r 39c06aba09aa ship_gui.c --- a/ship_gui.c Sat Feb 05 15:49:57 2005 +0000 +++ b/ship_gui.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "window.h" diff -r d04721ba07f9 -r 39c06aba09aa spritecache.c --- a/spritecache.c Sat Feb 05 15:49:57 2005 +0000 +++ b/spritecache.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "gfx.h" #include "fileio.h" #include "newgrf.h" diff -r d04721ba07f9 -r 39c06aba09aa station_cmd.c --- a/station_cmd.c Sat Feb 05 15:49:57 2005 +0000 +++ b/station_cmd.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "tile.h" diff -r d04721ba07f9 -r 39c06aba09aa station_gui.c --- a/station_gui.c Sat Feb 05 15:49:57 2005 +0000 +++ b/station_gui.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "window.h" #include "gui.h" diff -r d04721ba07f9 -r 39c06aba09aa town_gui.c --- a/town_gui.c Sat Feb 05 15:49:57 2005 +0000 +++ b/town_gui.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "town.h" #include "window.h" diff -r d04721ba07f9 -r 39c06aba09aa train_gui.c --- a/train_gui.c Sat Feb 05 15:49:57 2005 +0000 +++ b/train_gui.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "window.h" diff -r d04721ba07f9 -r 39c06aba09aa ttd.c --- a/ttd.c Sat Feb 05 15:49:57 2005 +0000 +++ b/ttd.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "table/strings.h" +#include "debug.h" #include "map.h" #include "tile.h" @@ -71,17 +72,6 @@ exit(1); } -void CDECL debug(const char *s, ...) -{ - va_list va; - char buf[1024]; - va_start(va, s); - vsprintf(buf, s, va); - va_end(va); - fprintf(stderr, "dbg: %s\n", buf); - IConsoleDebug(buf); -} - void CDECL ShowInfoF(const char *str, ...) { va_list va; @@ -431,71 +421,6 @@ } } -void SetDebugString(const char *s) -{ - int v; - char *end; - const char *t; - - typedef struct DebugLevel { - const char* name; - int* level; - } DebugLevel; - - #define DEBUG_LEVEL(x) { #x, &_debug_##x##_level } - static const DebugLevel debug_level[] = { - DEBUG_LEVEL(ai), - DEBUG_LEVEL(grf), - DEBUG_LEVEL(map), - DEBUG_LEVEL(misc), - DEBUG_LEVEL(ms), - DEBUG_LEVEL(net), - DEBUG_LEVEL(spritecache) - }; - #undef DEBUG_LEVEL - - // global debugging level? - if (*s >= '0' && *s <= '9') { - const DebugLevel *i; - - v = strtoul(s, &end, 0); - s = end; - - for (i = debug_level; i != endof(debug_level); ++i) - *i->level = v; - } - - // individual levels - for(;;) { - const DebugLevel *i; - int *p; - - // skip delimiters - while (*s == ' ' || *s == ',' || *s == '\t') s++; - if (*s == 0) break; - - t = s; - while (*s >= 'a' && *s <= 'z') s++; - - // check debugging levels - p = NULL; - for (i = debug_level; i != endof(debug_level); ++i) - if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) { - p = i->level; - break; - } - - if (*s == '=') s++; - v = strtoul(s, &end, 0); - s = end; - if (p != NULL) - *p = v; - else { - ShowInfoF("Unknown debug level '%.*s'", s - t, t); - return; - } - } -} static void ParseResolution(int res[2], char *s) { diff -r d04721ba07f9 -r 39c06aba09aa variables.h --- a/variables.h Sat Feb 05 15:49:57 2005 +0000 +++ b/variables.h Sat Feb 05 15:58:59 2005 +0000 @@ -452,15 +452,6 @@ VARDEF uint16 _player_num_engines[256]; VARDEF byte _railtype_selected_in_replace_gui; -/* Debugging levels */ -VARDEF int _debug_spritecache_level; -VARDEF int _debug_misc_level; -VARDEF int _debug_grf_level; -VARDEF int _debug_ai_level; -VARDEF int _debug_net_level; -VARDEF int _debug_map_level; -VARDEF int _debug_ms_level; - /* Forking stuff */ VARDEF bool _dedicated_forks; VARDEF bool _dedicated_enabled; @@ -468,11 +459,4 @@ VARDEF pid_t _dedicated_pid; #endif -void CDECL debug(const char *s, ...); -#ifdef NO_DEBUG_MESSAGES - #define DEBUG(name, level) -#else - #define DEBUG(name, level) if (level == 0 || _debug_ ## name ## _level >= level) debug -#endif - #endif /* VARIABLES_H */ diff -r d04721ba07f9 -r 39c06aba09aa vehicle_gui.c --- a/vehicle_gui.c Sat Feb 05 15:49:57 2005 +0000 +++ b/vehicle_gui.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "vehicle.h" #include "window.h" diff -r d04721ba07f9 -r 39c06aba09aa viewport.c --- a/viewport.c Sat Feb 05 15:49:57 2005 +0000 +++ b/viewport.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "viewport.h" diff -r d04721ba07f9 -r 39c06aba09aa window.c --- a/window.c Sat Feb 05 15:49:57 2005 +0000 +++ b/window.c Sat Feb 05 15:58:59 2005 +0000 @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "map.h" #include "window.h" #include "gfx.h"