src/debug.cpp
author peter1138
Tue, 22 Jan 2008 07:27:06 +0000
changeset 8374 7a1b6c89cb89
parent 8247 16e1c8db6f55
child 8409 de295d5e2bb4
permissions -rw-r--r--
(svn r11940) -Codechange: Store short filename once per open file instead of once per sprite cache entry. Not all file types need this, but most of the time no sprite cache entry needed it either.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5959
diff changeset
     3
/** @file debug.cpp */
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5959
diff changeset
     4
1302
29f313f85ec5 (svn r1806) Add missing includes (see r1803)
tron
parents: 1299
diff changeset
     5
#include "stdafx.h"
29f313f85ec5 (svn r1806) Add missing includes (see r1803)
tron
parents: 1299
diff changeset
     6
#include <stdio.h>
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
     7
#include <stdarg.h>
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1847
diff changeset
     8
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
     9
#include "console.h"
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    10
#include "debug.h"
8214
971f861d5543 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8192
diff changeset
    11
#include "string_func.h"
5959
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
    12
#include "network/core/core.h"
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
    13
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
    14
#if defined(ENABLE_NETWORK)
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
    15
SOCKET _debug_socket = INVALID_SOCKET;
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
    16
#endif /* ENABLE_NETWORK */
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    17
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    18
int _debug_ai_level;
2210
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    19
int _debug_driver_level;
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    20
int _debug_grf_level;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    21
int _debug_map_level;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    22
int _debug_misc_level;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    23
int _debug_ms_level;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    24
int _debug_net_level;
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5108
diff changeset
    25
int _debug_sprite_level;
1322
a7fef520f54c (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1302
diff changeset
    26
int _debug_oldloader_level;
2125
edc17858f9f6 (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2066
diff changeset
    27
int _debug_ntp_level;
1678
187385f01cc9 (svn r2182) - Add: [NPF] There is now a debug class for NPF. Use -d npf<level> to enable debugging printouts from npf.
matthijs
parents: 1322
diff changeset
    28
int _debug_npf_level;
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 2916
diff changeset
    29
int _debug_yapf_level;
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 3900
diff changeset
    30
int _debug_freetype_level;
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5108
diff changeset
    31
int _debug_sl_level;
5664
846a93238ca1 (svn r8124) -Add [DEBUG]: _debug_station_level
KUDr
parents: 5584
diff changeset
    32
int _debug_station_level;
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    33
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    34
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    35
struct DebugLevel {
1847
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    36
	const char *name;
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    37
	int *level;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    38
};
1847
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    39
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    40
#define DEBUG_LEVEL(x) { #x, &_debug_##x##_level }
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    41
	static const DebugLevel debug_level[] = {
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    42
	DEBUG_LEVEL(ai),
2210
b76184e0929c (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    43
	DEBUG_LEVEL(driver),
1847
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    44
	DEBUG_LEVEL(grf),
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    45
	DEBUG_LEVEL(map),
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    46
	DEBUG_LEVEL(misc),
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    47
	DEBUG_LEVEL(ms),
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    48
	DEBUG_LEVEL(net),
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5108
diff changeset
    49
	DEBUG_LEVEL(sprite),
1847
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    50
	DEBUG_LEVEL(oldloader),
2125
edc17858f9f6 (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2066
diff changeset
    51
	DEBUG_LEVEL(ntp),
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 2916
diff changeset
    52
	DEBUG_LEVEL(npf),
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 3900
diff changeset
    53
	DEBUG_LEVEL(yapf),
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5108
diff changeset
    54
	DEBUG_LEVEL(freetype),
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5108
diff changeset
    55
	DEBUG_LEVEL(sl),
5664
846a93238ca1 (svn r8124) -Add [DEBUG]: _debug_station_level
KUDr
parents: 5584
diff changeset
    56
	DEBUG_LEVEL(station),
1847
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    57
	};
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    58
#undef DEBUG_LEVEL
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    59
5406
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    60
#if !defined(NO_DEBUG_MESSAGES)
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    61
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    62
/** Functionized DEBUG macro for compilers that don't support
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    63
 * variadic macros (__VA_ARGS__) such as...yes MSVC2003 and lower */
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    64
#if defined(NO_VARARG_MACRO)
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    65
void CDECL DEBUG(int name, int level, ...)
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    66
{
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    67
	va_list va;
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    68
	const char *dbg;
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    69
	const DebugLevel *dl = &debug_level[name];
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    70
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    71
	if (level != 0 && *dl->level < level) return;
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    72
	dbg = dl->name;
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    73
	va_start(va, level);
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    74
#else
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    75
void CDECL debug(const char *dbg, ...)
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    76
{
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    77
	va_list va;
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    78
	va_start(va, dbg);
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    79
#endif /* NO_VARARG_MACRO */
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    80
	{
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    81
		const char *s;
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    82
		char buf[1024];
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    83
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    84
		s = va_arg(va, const char*);
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    85
		vsnprintf(buf, lengthof(buf), s, va);
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
    86
		va_end(va);
5959
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
    87
#if defined(ENABLE_NETWORK)
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
    88
		if (_debug_socket != INVALID_SOCKET) {
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
    89
			char buf2[lengthof(buf) + 32];
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
    90
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
    91
			snprintf(buf2, lengthof(buf2), "dbg: [%s] %s\n", dbg, buf);
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
    92
			send(_debug_socket, buf2, strlen(buf2), 0);
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
    93
		} else
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
    94
#endif /* ENABLE_NETWORK */
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
    95
		{
7405
2fd57f130eca (svn r10778) -Fix: one-liners to allow MSVC and WINCE to work together (or anyway, a step towards that goal)
truelight
parents: 6248
diff changeset
    96
#if defined(WINCE)
2fd57f130eca (svn r10778) -Fix: one-liners to allow MSVC and WINCE to work together (or anyway, a step towards that goal)
truelight
parents: 6248
diff changeset
    97
			/* We need to do OTTD2FS twice, but as it uses a static buffer, we need to store one temporary */
2fd57f130eca (svn r10778) -Fix: one-liners to allow MSVC and WINCE to work together (or anyway, a step towards that goal)
truelight
parents: 6248
diff changeset
    98
			TCHAR tbuf[512];
2fd57f130eca (svn r10778) -Fix: one-liners to allow MSVC and WINCE to work together (or anyway, a step towards that goal)
truelight
parents: 6248
diff changeset
    99
			_sntprintf(tbuf, sizeof(tbuf), _T("%s"), OTTD2FS(dbg));
2fd57f130eca (svn r10778) -Fix: one-liners to allow MSVC and WINCE to work together (or anyway, a step towards that goal)
truelight
parents: 6248
diff changeset
   100
			NKDbgPrintfW(_T("dbg: [%s] %s\n"), tbuf, OTTD2FS(buf));
2fd57f130eca (svn r10778) -Fix: one-liners to allow MSVC and WINCE to work together (or anyway, a step towards that goal)
truelight
parents: 6248
diff changeset
   101
#else
5959
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
   102
			fprintf(stderr, "dbg: [%s] %s\n", dbg, buf);
7405
2fd57f130eca (svn r10778) -Fix: one-liners to allow MSVC and WINCE to work together (or anyway, a step towards that goal)
truelight
parents: 6248
diff changeset
   103
#endif
5959
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
   104
			IConsoleDebug(dbg, buf);
98a64c6e7f1f (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5664
diff changeset
   105
		}
5406
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
   106
	}
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
   107
}
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
   108
#endif /* NO_DEBUG_MESSAGES */
2df85542fee4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5380
diff changeset
   109
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   110
void SetDebugString(const char *s)
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   111
{
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   112
	int v;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   113
	char *end;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   114
	const char *t;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   115
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5959
diff changeset
   116
	/* global debugging level? */
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   117
	if (*s >= '0' && *s <= '9') {
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   118
		const DebugLevel *i;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   119
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   120
		v = strtoul(s, &end, 0);
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   121
		s = end;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   122
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2210
diff changeset
   123
		for (i = debug_level; i != endof(debug_level); ++i) *i->level = v;
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   124
	}
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   125
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5959
diff changeset
   126
	/* individual levels */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2210
diff changeset
   127
	for (;;) {
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   128
		const DebugLevel *i;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   129
		int *p;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   130
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5959
diff changeset
   131
		/* skip delimiters */
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   132
		while (*s == ' ' || *s == ',' || *s == '\t') s++;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   133
		if (*s == '\0') break;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   134
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   135
		t = s;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   136
		while (*s >= 'a' && *s <= 'z') s++;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   137
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5959
diff changeset
   138
		/* check debugging levels */
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   139
		p = NULL;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   140
		for (i = debug_level; i != endof(debug_level); ++i)
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   141
			if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) {
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   142
				p = i->level;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   143
				break;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   144
			}
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   145
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   146
		if (*s == '=') s++;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   147
		v = strtoul(s, &end, 0);
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   148
		s = end;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2210
diff changeset
   149
		if (p != NULL) {
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   150
			*p = v;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2210
diff changeset
   151
		} else {
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   152
			ShowInfoF("Unknown debug level '%.*s'", s - t, t);
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   153
			return;
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   154
		}
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   155
	}
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   156
}
1847
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   157
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   158
/** Print out the current debug-level
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   159
 * Just return a string with the values of all the debug categorites
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   160
 * @return string with debug-levels
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   161
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6125
diff changeset
   162
const char *GetDebugString()
1847
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   163
{
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   164
	const DebugLevel *i;
8192
807098a4e2c1 (svn r11755) -Fix: Debug level string buffer was not long enough to contain all debug levels.
peter1138
parents: 8131
diff changeset
   165
	static char dbgstr[150];
1847
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   166
	char dbgval[20];
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   167
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   168
	memset(dbgstr, 0, sizeof(dbgstr));
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   169
	i = debug_level;
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   170
	snprintf(dbgstr, sizeof(dbgstr), "%s=%d", i->name, *i->level);
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   171
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   172
	for (i++; i != endof(debug_level); i++) {
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   173
		snprintf(dbgval, sizeof(dbgval), ", %s=%d", i->name, *i->level);
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   174
		ttd_strlcat(dbgstr, dbgval, sizeof(dbgstr));
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   175
	}
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   176
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   177
	return dbgstr;
d94ed71b61e7 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   178
}
8247
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   179
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   180
#ifdef DEBUG_DUMP_COMMANDS
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   181
#include "fileio.h"
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   182
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   183
void CDECL DebugDumpCommands(const char *s, ...)
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   184
{
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   185
	static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   186
	if (f == NULL) return;
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   187
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   188
	va_list va;
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   189
	va_start(va, s);
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   190
	vfprintf(f, s, va);
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   191
	va_end(va);
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   192
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   193
	fflush(f);
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   194
}
16e1c8db6f55 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8214
diff changeset
   195
#endif /* DEBUG_DUMP_COMMANDS */