(svn r2352) - Feature: add the possibility to print out the current debug-level
authorDarkvater
Fri, 20 May 2005 17:59:24 +0000
changeset 1847 47703af63895
parent 1846 c4c9ded67c3c
child 1848 56d64406e2ca
(svn r2352) - Feature: add the possibility to print out the current debug-level
console_cmds.c
debug.c
debug.h
--- a/console_cmds.c	Thu May 19 17:40:26 2005 +0000
+++ b/console_cmds.c	Fri May 20 17:59:24 2005 +0000
@@ -833,13 +833,17 @@
 DEF_CONSOLE_CMD(ConDebugLevel)
 {
 	if (argc == 0) {
-		IConsoleHelp("Set the default debugging level for the game. Usage: 'debug_level <level>'");
+		IConsoleHelp("Get/set the default debugging level for the game. Usage: 'debug_level [<level>]'");
 		IConsoleHelp("Level can be any combination of names, levels. Eg 'net=5 ms=4'. Remember to enclose it in \"'s");
 		return true;
 	}
 
-	if (argc < 2) return false;
-	SetDebugString(argv[1]);
+	if (argc > 2) return false;
+
+	if (argc == 1) {
+		IConsolePrintF(_icolour_def, "Current debug-level: '%s'", GetDebugString());
+	} else SetDebugString(argv[1]);
+
 	return true;
 }
 
--- a/debug.c	Thu May 19 17:40:26 2005 +0000
+++ b/debug.c	Fri May 20 17:59:24 2005 +0000
@@ -4,6 +4,7 @@
 #include "ttd.h"
 #include "console.h"
 #include "debug.h"
+#include "string.h"
 
 int _debug_ai_level;
 int _debug_grf_level;
@@ -28,6 +29,24 @@
 	IConsoleDebug(buf);
 }
 
+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),
+	DEBUG_LEVEL(oldloader),
+	DEBUG_LEVEL(npf)
+	};
+#undef DEBUG_LEVEL
 
 void SetDebugString(const char *s)
 {
@@ -35,25 +54,6 @@
 	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),
-		DEBUG_LEVEL(oldloader),
-		DEBUG_LEVEL(npf)
-	};
-	#undef DEBUG_LEVEL
-
 	// global debugging level?
 	if (*s >= '0' && *s <= '9') {
 		const DebugLevel *i;
@@ -96,3 +96,25 @@
 		}
 	}
 }
+
+/** Print out the current debug-level
+ * Just return a string with the values of all the debug categorites
+ * @return string with debug-levels
+ */
+const char *GetDebugString(void)
+{
+	const DebugLevel *i;
+	static char dbgstr[100];
+	char dbgval[20];
+
+	memset(dbgstr, 0, sizeof(dbgstr));
+	i = debug_level;
+	snprintf(dbgstr, sizeof(dbgstr), "%s=%d", i->name, *i->level);
+
+	for (i++; i != endof(debug_level); i++) {
+		snprintf(dbgval, sizeof(dbgval), ", %s=%d", i->name, *i->level);
+		ttd_strlcat(dbgstr, dbgval, sizeof(dbgstr));
+	}
+
+	return dbgstr;
+}
--- a/debug.h	Thu May 19 17:40:26 2005 +0000
+++ b/debug.h	Fri May 20 17:59:24 2005 +0000
@@ -20,5 +20,6 @@
 void CDECL debug(const char *s, ...);
 
 void SetDebugString(const char *s);
+const char *GetDebugString(void);
 
 #endif