2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2005-02-05 15:58:59 +00:00
|
|
|
#include "stdafx.h"
|
2005-02-05 21:57:01 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-02-05 15:58:59 +00:00
|
|
|
#include "console.h"
|
|
|
|
#include "debug.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2005-05-20 17:59:24 +00:00
|
|
|
#include "string.h"
|
2005-02-05 15:58:59 +00:00
|
|
|
|
|
|
|
int _debug_ai_level;
|
2005-07-27 19:57:12 +00:00
|
|
|
int _debug_driver_level;
|
2005-02-05 15:58:59 +00:00
|
|
|
int _debug_grf_level;
|
|
|
|
int _debug_map_level;
|
|
|
|
int _debug_misc_level;
|
|
|
|
int _debug_ms_level;
|
|
|
|
int _debug_net_level;
|
2006-12-26 17:36:18 +00:00
|
|
|
int _debug_sprite_level;
|
2005-02-06 18:28:35 +00:00
|
|
|
int _debug_oldloader_level;
|
2005-07-19 11:42:40 +00:00
|
|
|
int _debug_ntp_level;
|
2005-04-11 19:53:44 +00:00
|
|
|
int _debug_npf_level;
|
2006-05-27 16:12:16 +00:00
|
|
|
int _debug_yapf_level;
|
2006-11-16 22:05:33 +00:00
|
|
|
int _debug_freetype_level;
|
2006-12-26 17:36:18 +00:00
|
|
|
int _debug_sl_level;
|
2005-02-05 15:58:59 +00:00
|
|
|
|
|
|
|
|
2006-12-26 17:36:18 +00:00
|
|
|
void CDECL debug(const char *dbg, ...)
|
2005-02-05 15:58:59 +00:00
|
|
|
{
|
|
|
|
va_list va;
|
2006-12-26 17:36:18 +00:00
|
|
|
const char *s;
|
2005-02-05 15:58:59 +00:00
|
|
|
char buf[1024];
|
|
|
|
|
2006-12-26 17:36:18 +00:00
|
|
|
va_start(va, dbg);
|
|
|
|
s = va_arg(va, const char*);
|
2005-02-05 15:58:59 +00:00
|
|
|
vsnprintf(buf, lengthof(buf), s, va);
|
|
|
|
va_end(va);
|
2006-12-26 17:36:18 +00:00
|
|
|
fprintf(stderr, "dbg: [%s] %s\n", dbg, buf);
|
|
|
|
IConsoleDebug(dbg, buf);
|
2005-02-05 15:58:59 +00:00
|
|
|
}
|
|
|
|
|
2005-05-20 17:59:24 +00:00
|
|
|
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),
|
2005-07-27 19:57:12 +00:00
|
|
|
DEBUG_LEVEL(driver),
|
2005-05-20 17:59:24 +00:00
|
|
|
DEBUG_LEVEL(grf),
|
|
|
|
DEBUG_LEVEL(map),
|
|
|
|
DEBUG_LEVEL(misc),
|
|
|
|
DEBUG_LEVEL(ms),
|
|
|
|
DEBUG_LEVEL(net),
|
2006-12-26 17:36:18 +00:00
|
|
|
DEBUG_LEVEL(sprite),
|
2005-05-20 17:59:24 +00:00
|
|
|
DEBUG_LEVEL(oldloader),
|
2005-07-19 11:42:40 +00:00
|
|
|
DEBUG_LEVEL(ntp),
|
2006-05-27 16:12:16 +00:00
|
|
|
DEBUG_LEVEL(npf),
|
2006-11-16 22:05:33 +00:00
|
|
|
DEBUG_LEVEL(yapf),
|
2006-12-26 17:36:18 +00:00
|
|
|
DEBUG_LEVEL(freetype),
|
|
|
|
DEBUG_LEVEL(sl),
|
2005-05-20 17:59:24 +00:00
|
|
|
};
|
|
|
|
#undef DEBUG_LEVEL
|
2005-02-05 15:58:59 +00:00
|
|
|
|
|
|
|
void SetDebugString(const char *s)
|
|
|
|
{
|
|
|
|
int v;
|
|
|
|
char *end;
|
|
|
|
const char *t;
|
|
|
|
|
|
|
|
// global debugging level?
|
|
|
|
if (*s >= '0' && *s <= '9') {
|
|
|
|
const DebugLevel *i;
|
|
|
|
|
|
|
|
v = strtoul(s, &end, 0);
|
|
|
|
s = end;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (i = debug_level; i != endof(debug_level); ++i) *i->level = v;
|
2005-02-05 15:58:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// individual levels
|
2005-11-14 19:48:04 +00:00
|
|
|
for (;;) {
|
2005-02-05 15:58:59 +00:00
|
|
|
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;
|
2005-11-14 19:48:04 +00:00
|
|
|
if (p != NULL) {
|
2005-02-05 15:58:59 +00:00
|
|
|
*p = v;
|
2005-11-14 19:48:04 +00:00
|
|
|
} else {
|
2005-02-05 15:58:59 +00:00
|
|
|
ShowInfoF("Unknown debug level '%.*s'", s - t, t);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-05-20 17:59:24 +00:00
|
|
|
|
|
|
|
/** 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;
|
|
|
|
}
|