(svn r1803) Move debugging stuff into files of it's own
authortron
Sat, 05 Feb 2005 15:58:59 +0000
changeset 1299 39c06aba09aa
parent 1298 d04721ba07f9
child 1300 84a869767c56
(svn r1803) Move debugging stuff into files of it's own
Makefile
ai_build.c
ai_new.c
ai_pathfinder.c
ai_shared.c
aircraft_cmd.c
aircraft_gui.c
airport.c
console.h
console_cmds.c
debug.c
debug.h
dedicated.c
engine.c
industry_gui.c
map.c
misc_gui.c
namegen.c
network.c
network_client.c
network_data.c
network_gamelist.c
network_server.c
network_udp.c
newgrf.c
npf.c
pool.c
roadveh_cmd.c
roadveh_gui.c
saveload.c
screenshot.c
sdl.c
ship_gui.c
spritecache.c
station_cmd.c
station_gui.c
town_gui.c
train_gui.c
ttd.c
variables.h
vehicle_gui.c
viewport.c
window.c
--- 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
--- 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"
--- 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"
--- 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"
--- 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"
--- 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"
--- 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"
--- 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"
 
--- 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);
--- 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"
--- /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 <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;
+		}
+	}
+}
--- /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
--- 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"
 
--- 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"
--- 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"
--- 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"
 
--- 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"
--- 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)
--- 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"
 
--- 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
--- 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?
--- 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
--- 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
--- 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
--- 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 <stdarg.h>
 
 #include "ttd.h"
+#include "debug.h"
 #include "gfx.h"
 #include "fileio.h"
 #include "engine.h"
--- 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"
--- 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"
 
 /**
--- 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"
--- 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"
--- 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"
--- 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"
--- 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"
--- 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"
--- 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"
--- 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"
--- 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"
--- 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"
--- 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"
--- 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)
 {
--- 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 */
--- 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"
--- 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"
--- 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"