diff options
author | tron <tron@openttd.org> | 2005-02-05 15:58:59 +0000 |
---|---|---|
committer | tron <tron@openttd.org> | 2005-02-05 15:58:59 +0000 |
commit | f0f85a7ef3dd7502657138bea7575dd54f6f8bdb (patch) | |
tree | 3f6b444dbf38fd09dbe9c5e0be19e8b6fa53c8a4 | |
parent | 77b3a76919bc243d16c216ae61b588f6e3be9cb0 (diff) | |
download | openttd-f0f85a7ef3dd7502657138bea7575dd54f6f8bdb.tar.xz |
(svn r1803) Move debugging stuff into files of it's own
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | ai_build.c | 1 | ||||
-rw-r--r-- | ai_new.c | 1 | ||||
-rw-r--r-- | ai_pathfinder.c | 1 | ||||
-rw-r--r-- | ai_shared.c | 1 | ||||
-rw-r--r-- | aircraft_cmd.c | 1 | ||||
-rw-r--r-- | aircraft_gui.c | 1 | ||||
-rw-r--r-- | airport.c | 1 | ||||
-rw-r--r-- | console.h | 4 | ||||
-rw-r--r-- | console_cmds.c | 1 | ||||
-rw-r--r-- | debug.c | 93 | ||||
-rw-r--r-- | debug.h | 22 | ||||
-rw-r--r-- | dedicated.c | 1 | ||||
-rw-r--r-- | engine.c | 1 | ||||
-rw-r--r-- | industry_gui.c | 1 | ||||
-rw-r--r-- | map.c | 1 | ||||
-rw-r--r-- | misc_gui.c | 1 | ||||
-rw-r--r-- | namegen.c | 2 | ||||
-rw-r--r-- | network.c | 1 | ||||
-rw-r--r-- | network_client.c | 1 | ||||
-rw-r--r-- | network_data.c | 1 | ||||
-rw-r--r-- | network_gamelist.c | 1 | ||||
-rw-r--r-- | network_server.c | 1 | ||||
-rw-r--r-- | network_udp.c | 1 | ||||
-rw-r--r-- | newgrf.c | 1 | ||||
-rw-r--r-- | npf.c | 1 | ||||
-rw-r--r-- | pool.c | 1 | ||||
-rw-r--r-- | roadveh_cmd.c | 1 | ||||
-rw-r--r-- | roadveh_gui.c | 1 | ||||
-rw-r--r-- | saveload.c | 1 | ||||
-rw-r--r-- | screenshot.c | 1 | ||||
-rw-r--r-- | sdl.c | 1 | ||||
-rw-r--r-- | ship_gui.c | 1 | ||||
-rw-r--r-- | spritecache.c | 1 | ||||
-rw-r--r-- | station_cmd.c | 1 | ||||
-rw-r--r-- | station_gui.c | 1 | ||||
-rw-r--r-- | town_gui.c | 1 | ||||
-rw-r--r-- | train_gui.c | 1 | ||||
-rw-r--r-- | ttd.c | 77 | ||||
-rw-r--r-- | variables.h | 16 | ||||
-rw-r--r-- | vehicle_gui.c | 1 | ||||
-rw-r--r-- | viewport.c | 1 | ||||
-rw-r--r-- | window.c | 1 |
43 files changed, 154 insertions, 97 deletions
@@ -561,6 +561,7 @@ C_SOURCES += clear_cmd.c 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 --git a/ai_build.c b/ai_build.c index e4dcf42cd..55fab3fbc 100644 --- a/ai_build.c +++ b/ai_build.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "map.h" #include "tile.h" #include "command.h" @@ -15,6 +15,7 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "tile.h" diff --git a/ai_pathfinder.c b/ai_pathfinder.c index 6266352dd..1a4dcd684 100644 --- a/ai_pathfinder.c +++ b/ai_pathfinder.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "map.h" #include "tile.h" #include "command.h" diff --git a/ai_shared.c b/ai_shared.c index 30dc3adcb..9a82f744a 100644 --- a/ai_shared.c +++ b/ai_shared.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "map.h" #include "ai.h" #include "vehicle.h" diff --git a/aircraft_cmd.c b/aircraft_cmd.c index fbde61536..7656c689e 100644 --- a/aircraft_cmd.c +++ b/aircraft_cmd.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "tile.h" diff --git a/aircraft_gui.c b/aircraft_gui.c index 000415e73..1d3302f07 100644 --- a/aircraft_gui.c +++ b/aircraft_gui.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "tile.h" @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "map.h" #include "airport.h" @@ -104,10 +104,6 @@ VARDEF byte _iconsole_color_debug; VARDEF byte _iconsole_color_commands; VARDEF _iconsole_modes _iconsole_mode; -// ** ttd.c functions ** // - -void SetDebugString(const char* s); - // ** console functions ** // void IConsoleInit(void); diff --git a/console_cmds.c b/console_cmds.c index b8ea17826..e73896b21 100644 --- a/console_cmds.c +++ b/console_cmds.c @@ -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 --git a/debug.c b/debug.c new file mode 100644 index 000000000..6639f0426 --- /dev/null +++ b/debug.c @@ -0,0 +1,93 @@ +#include <stdarg.h> +#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 --git a/debug.h b/debug.h new file mode 100644 index 000000000..f48cb741a --- /dev/null +++ b/debug.h @@ -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 --git a/dedicated.c b/dedicated.c index 17944b393..9ee6f4da1 100644 --- a/dedicated.c +++ b/dedicated.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "network.h" #include "hal.h" @@ -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 --git a/industry_gui.c b/industry_gui.c index 1d5e73842..b503f1f57 100644 --- a/industry_gui.c +++ b/industry_gui.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" //#include "gui.h" @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "functions.h" #include "map.h" diff --git a/misc_gui.c b/misc_gui.c index 53bdc0f7e..8a5ef640e 100644 --- a/misc_gui.c +++ b/misc_gui.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "window.h" @@ -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) @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "debug.h" #include "map.h" #include "network_data.h" diff --git a/network_client.c b/network_client.c index 29821a5a5..8deec2fd3 100644 --- a/network_client.c +++ b/network_client.c @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "debug.h" #include "network_data.h" #ifdef ENABLE_NETWORK diff --git a/network_data.c b/network_data.c index f2d370749..9de3d4005 100644 --- a/network_data.c +++ b/network_data.c @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "debug.h" #include "network_data.h" // Is the network enabled? diff --git a/network_gamelist.c b/network_gamelist.c index b10b0cb64..f135c4851 100644 --- a/network_gamelist.c +++ b/network_gamelist.c @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "debug.h" #include "network_data.h" #ifdef ENABLE_NETWORK diff --git a/network_server.c b/network_server.c index 219ba9844..0fee52779 100644 --- a/network_server.c +++ b/network_server.c @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "debug.h" #include "network_data.h" #ifdef ENABLE_NETWORK diff --git a/network_udp.c b/network_udp.c index 4f2b942d3..aa0af4521 100644 --- a/network_udp.c +++ b/network_udp.c @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "debug.h" #include "network_data.h" #ifdef ENABLE_NETWORK @@ -3,6 +3,7 @@ #include <stdarg.h> #include "ttd.h" +#include "debug.h" #include "gfx.h" #include "fileio.h" #include "engine.h" @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "npf.h" #include "aystar.h" #include "macros.h" @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "pool.h" /** diff --git a/roadveh_cmd.c b/roadveh_cmd.c index bdeac3757..3a71c58b2 100644 --- a/roadveh_cmd.c +++ b/roadveh_cmd.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "tile.h" diff --git a/roadveh_gui.c b/roadveh_gui.c index 0b0c4704e..2bbdceab4 100644 --- a/roadveh_gui.c +++ b/roadveh_gui.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "window.h" diff --git a/saveload.c b/saveload.c index ef621afcd..33e14e965 100644 --- a/saveload.c +++ b/saveload.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "vehicle.h" #include "station.h" #include "town.h" diff --git a/screenshot.c b/screenshot.c index 26bf99fc9..d0e0107d3 100644 --- a/screenshot.c +++ b/screenshot.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "gfx.h" #include "viewport.h" @@ -2,6 +2,7 @@ #if defined(WITH_SDL) #include "ttd.h" +#include "debug.h" #include "gfx.h" #include "sound.h" #include "window.h" diff --git a/ship_gui.c b/ship_gui.c index e5de0fdfe..9c953e9f1 100644 --- a/ship_gui.c +++ b/ship_gui.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "window.h" diff --git a/spritecache.c b/spritecache.c index 2ab89f4ff..c580813f8 100644 --- a/spritecache.c +++ b/spritecache.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "gfx.h" #include "fileio.h" #include "newgrf.h" diff --git a/station_cmd.c b/station_cmd.c index 587c6acf4..d592dc3eb 100644 --- a/station_cmd.c +++ b/station_cmd.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "tile.h" diff --git a/station_gui.c b/station_gui.c index fe57f4dbe..8453c555f 100644 --- a/station_gui.c +++ b/station_gui.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "window.h" #include "gui.h" diff --git a/town_gui.c b/town_gui.c index cd08386b1..84b5a319c 100644 --- a/town_gui.c +++ b/town_gui.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "town.h" #include "window.h" diff --git a/train_gui.c b/train_gui.c index cc98d3471..f6656cb42 100644 --- a/train_gui.c +++ b/train_gui.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "window.h" @@ -1,5 +1,6 @@ #include "stdafx.h" #include "table/strings.h" +#include "debug.h" #include "map.h" #include "tile.h" @@ -71,17 +72,6 @@ void CDECL error(const char *s, ...) { 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 @@ md_continue_here:; } } -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 --git a/variables.h b/variables.h index c28105e5f..b9cee1f0e 100644 --- a/variables.h +++ b/variables.h @@ -452,15 +452,6 @@ VARDEF byte _autoreplace_array[256]; 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 bool _dedicated_enabled; 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 --git a/vehicle_gui.c b/vehicle_gui.c index e88d3a8d4..9344fc2b9 100644 --- a/vehicle_gui.c +++ b/vehicle_gui.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "vehicle.h" #include "window.h" diff --git a/viewport.c b/viewport.c index 2bc10ad0d..737a5c350 100644 --- a/viewport.c +++ b/viewport.c @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "table/strings.h" #include "map.h" #include "viewport.h" @@ -1,5 +1,6 @@ #include "stdafx.h" #include "ttd.h" +#include "debug.h" #include "map.h" #include "window.h" #include "gfx.h" |