summaryrefslogtreecommitdiff
path: root/debug.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2005-05-20 17:59:24 +0000
committerDarkvater <darkvater@openttd.org>2005-05-20 17:59:24 +0000
commit519c4161d5824b64c01e740ccdbe7f7e11dd979e (patch)
tree445dd7beb26526a8531f009abbdac31afffc3d5f /debug.c
parent1ab7238c15ca4acfb5c49088d80d3177cb77bb01 (diff)
downloadopenttd-519c4161d5824b64c01e740ccdbe7f7e11dd979e.tar.xz
(svn r2352) - Feature: add the possibility to print out the current debug-level
Diffstat (limited to 'debug.c')
-rw-r--r--debug.c60
1 files changed, 41 insertions, 19 deletions
diff --git a/debug.c b/debug.c
index 025a182ea..2ac39fde4 100644
--- a/debug.c
+++ b/debug.c
@@ -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 @@ void CDECL debug(const char *s, ...)
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 @@ void SetDebugString(const char *s)
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 @@ void SetDebugString(const char *s)
}
}
}
+
+/** 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;
+}