src/debug.cpp
author Tero Marttila <terom@fixme.fi>
Sat, 19 Jul 2008 01:38:52 +0300
changeset 11178 aa617a8b4f34
parent 11169 60cbac6bc442
permissions -rw-r--r--
a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 8905
diff changeset
     3
/** @file debug.cpp Handling of printing debug messages. */
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6210
diff changeset
     4
1302
1e4e3e7e23aa (svn r1806) Add missing includes (see r1803)
tron
parents: 1299
diff changeset
     5
#include "stdafx.h"
1e4e3e7e23aa (svn r1806) Add missing includes (see r1803)
tron
parents: 1299
diff changeset
     6
#include <stdio.h>
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
     7
#include <stdarg.h>
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1847
diff changeset
     8
#include "openttd.h"
10684
7cc2278c2ac0 (svn r13228) -Codechange: split console.h.
rubidium
parents: 10429
diff changeset
     9
#include "console_func.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    10
#include "debug.h"
8710
52015340050c (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8688
diff changeset
    11
#include "string_func.h"
6210
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5915
diff changeset
    12
#include "network/core/core.h"
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5915
diff changeset
    13
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5915
diff changeset
    14
#if defined(ENABLE_NETWORK)
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5915
diff changeset
    15
SOCKET _debug_socket = INVALID_SOCKET;
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5915
diff changeset
    16
#endif /* ENABLE_NETWORK */
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    17
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    18
int _debug_ai_level;
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    19
int _debug_driver_level;
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    20
int _debug_grf_level;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    21
int _debug_map_level;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    22
int _debug_misc_level;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    23
int _debug_ms_level;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    24
int _debug_net_level;
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5108
diff changeset
    25
int _debug_sprite_level;
1322
8697b73baa64 (svn r1826) -Feature: a brand new OldLoader so OpenTTD is TTD(Patch) compatible
truelight
parents: 1302
diff changeset
    26
int _debug_oldloader_level;
2125
3098398bf7ff (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
838dd6f46081 (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
4984308f9125 (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
dc67d70b5a45 (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;
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5108
diff changeset
    31
int _debug_sl_level;
5915
a39082f82ea2 (svn r8124) -Add [DEBUG]: _debug_station_level
KUDr
parents: 5835
diff changeset
    32
int _debug_station_level;
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
    33
int _debug_gamelog_level;
11178
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11169
diff changeset
    34
int _debug_grfdl_level;
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    35
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    36
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    37
struct DebugLevel {
1847
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    38
	const char *name;
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    39
	int *level;
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    40
};
1847
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    41
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    42
#define DEBUG_LEVEL(x) { #x, &_debug_##x##_level }
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    43
	static const DebugLevel debug_level[] = {
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    44
	DEBUG_LEVEL(ai),
2210
58a293892a66 (svn r2728) -Fix/Feature: Change the driver probing algorithm
tron
parents: 2186
diff changeset
    45
	DEBUG_LEVEL(driver),
1847
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    46
	DEBUG_LEVEL(grf),
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    47
	DEBUG_LEVEL(map),
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    48
	DEBUG_LEVEL(misc),
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    49
	DEBUG_LEVEL(ms),
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    50
	DEBUG_LEVEL(net),
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5108
diff changeset
    51
	DEBUG_LEVEL(sprite),
1847
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    52
	DEBUG_LEVEL(oldloader),
2125
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2066
diff changeset
    53
	DEBUG_LEVEL(ntp),
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 2916
diff changeset
    54
	DEBUG_LEVEL(npf),
5108
dc67d70b5a45 (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
    55
	DEBUG_LEVEL(yapf),
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5108
diff changeset
    56
	DEBUG_LEVEL(freetype),
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5108
diff changeset
    57
	DEBUG_LEVEL(sl),
5915
a39082f82ea2 (svn r8124) -Add [DEBUG]: _debug_station_level
KUDr
parents: 5835
diff changeset
    58
	DEBUG_LEVEL(station),
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
    59
	DEBUG_LEVEL(gamelog),
11178
aa617a8b4f34 a working CheckAvailableNewGRFs that does a metadata search/retreival via HTTP for a given list of GRFs
Tero Marttila <terom@fixme.fi>
parents: 11169
diff changeset
    60
	DEBUG_LEVEL(grfdl),
1847
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    61
	};
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
    62
#undef DEBUG_LEVEL
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
    63
5657
54c99d0f6ba4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5568
diff changeset
    64
#if !defined(NO_DEBUG_MESSAGES)
54c99d0f6ba4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5568
diff changeset
    65
11169
60cbac6bc442 (svn r13727) -Fix (r13375): compilation with NO_DEBUG_MESSAGES was broken
smatz
parents: 10824
diff changeset
    66
static void debug_print(const char *dbg, const char *buf)
5657
54c99d0f6ba4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5568
diff changeset
    67
{
8905
a6974b6041d9 (svn r11979) -Codechange: drop MSVC 2003 support because MSVC 2003 is broken in such a manner that it triggers an internal compiler error without any clue what of the code is wrong. Even trying to bisect the problem does not give a single line of code that causes the trouble.
rubidium
parents: 8743
diff changeset
    68
#if defined(ENABLE_NETWORK)
a6974b6041d9 (svn r11979) -Codechange: drop MSVC 2003 support because MSVC 2003 is broken in such a manner that it triggers an internal compiler error without any clue what of the code is wrong. Even trying to bisect the problem does not give a single line of code that causes the trouble.
rubidium
parents: 8743
diff changeset
    69
	if (_debug_socket != INVALID_SOCKET) {
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
    70
		char buf2[1024 + 32];
8905
a6974b6041d9 (svn r11979) -Codechange: drop MSVC 2003 support because MSVC 2003 is broken in such a manner that it triggers an internal compiler error without any clue what of the code is wrong. Even trying to bisect the problem does not give a single line of code that causes the trouble.
rubidium
parents: 8743
diff changeset
    71
a6974b6041d9 (svn r11979) -Codechange: drop MSVC 2003 support because MSVC 2003 is broken in such a manner that it triggers an internal compiler error without any clue what of the code is wrong. Even trying to bisect the problem does not give a single line of code that causes the trouble.
rubidium
parents: 8743
diff changeset
    72
		snprintf(buf2, lengthof(buf2), "dbg: [%s] %s\n", dbg, buf);
10751
ebd94f2d6385 (svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents: 10684
diff changeset
    73
		send(_debug_socket, buf2, (int)strlen(buf2), 0);
8905
a6974b6041d9 (svn r11979) -Codechange: drop MSVC 2003 support because MSVC 2003 is broken in such a manner that it triggers an internal compiler error without any clue what of the code is wrong. Even trying to bisect the problem does not give a single line of code that causes the trouble.
rubidium
parents: 8743
diff changeset
    74
	} else
6210
717cc12ac0a9 (svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
truelight
parents: 5915
diff changeset
    75
#endif /* ENABLE_NETWORK */
8905
a6974b6041d9 (svn r11979) -Codechange: drop MSVC 2003 support because MSVC 2003 is broken in such a manner that it triggers an internal compiler error without any clue what of the code is wrong. Even trying to bisect the problem does not give a single line of code that causes the trouble.
rubidium
parents: 8743
diff changeset
    76
	{
7901
1af11255e634 (svn r10778) -Fix: one-liners to allow MSVC and WINCE to work together (or anyway, a step towards that goal)
truelight
parents: 6574
diff changeset
    77
#if defined(WINCE)
8905
a6974b6041d9 (svn r11979) -Codechange: drop MSVC 2003 support because MSVC 2003 is broken in such a manner that it triggers an internal compiler error without any clue what of the code is wrong. Even trying to bisect the problem does not give a single line of code that causes the trouble.
rubidium
parents: 8743
diff changeset
    78
		/* We need to do OTTD2FS twice, but as it uses a static buffer, we need to store one temporary */
a6974b6041d9 (svn r11979) -Codechange: drop MSVC 2003 support because MSVC 2003 is broken in such a manner that it triggers an internal compiler error without any clue what of the code is wrong. Even trying to bisect the problem does not give a single line of code that causes the trouble.
rubidium
parents: 8743
diff changeset
    79
		TCHAR tbuf[512];
a6974b6041d9 (svn r11979) -Codechange: drop MSVC 2003 support because MSVC 2003 is broken in such a manner that it triggers an internal compiler error without any clue what of the code is wrong. Even trying to bisect the problem does not give a single line of code that causes the trouble.
rubidium
parents: 8743
diff changeset
    80
		_sntprintf(tbuf, sizeof(tbuf), _T("%s"), OTTD2FS(dbg));
a6974b6041d9 (svn r11979) -Codechange: drop MSVC 2003 support because MSVC 2003 is broken in such a manner that it triggers an internal compiler error without any clue what of the code is wrong. Even trying to bisect the problem does not give a single line of code that causes the trouble.
rubidium
parents: 8743
diff changeset
    81
		NKDbgPrintfW(_T("dbg: [%s] %s\n"), tbuf, OTTD2FS(buf));
7901
1af11255e634 (svn r10778) -Fix: one-liners to allow MSVC and WINCE to work together (or anyway, a step towards that goal)
truelight
parents: 6574
diff changeset
    82
#else
8905
a6974b6041d9 (svn r11979) -Codechange: drop MSVC 2003 support because MSVC 2003 is broken in such a manner that it triggers an internal compiler error without any clue what of the code is wrong. Even trying to bisect the problem does not give a single line of code that causes the trouble.
rubidium
parents: 8743
diff changeset
    83
		fprintf(stderr, "dbg: [%s] %s\n", dbg, buf);
7901
1af11255e634 (svn r10778) -Fix: one-liners to allow MSVC and WINCE to work together (or anyway, a step towards that goal)
truelight
parents: 6574
diff changeset
    84
#endif
8905
a6974b6041d9 (svn r11979) -Codechange: drop MSVC 2003 support because MSVC 2003 is broken in such a manner that it triggers an internal compiler error without any clue what of the code is wrong. Even trying to bisect the problem does not give a single line of code that causes the trouble.
rubidium
parents: 8743
diff changeset
    85
		IConsoleDebug(dbg, buf);
5657
54c99d0f6ba4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5568
diff changeset
    86
	}
54c99d0f6ba4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5568
diff changeset
    87
}
10824
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
    88
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
    89
void CDECL debug(const char *dbg, ...)
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
    90
{
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
    91
	va_list va;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
    92
	va_start(va, dbg);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
    93
	const char *s;
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
    94
	char buf[1024];
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
    95
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
    96
	s = va_arg(va, const char*);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
    97
	vsnprintf(buf, lengthof(buf), s, va);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
    98
	va_end(va);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
    99
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
   100
	debug_print(dbg, buf);
1a34ba6f338a (svn r13375) -Add: logging of actions that could possibly cause desyncs and crashes to simplify debugging. See readme.txt for details
smatz
parents: 10751
diff changeset
   101
}
5657
54c99d0f6ba4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5568
diff changeset
   102
#endif /* NO_DEBUG_MESSAGES */
54c99d0f6ba4 (svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around
Darkvater
parents: 5568
diff changeset
   103
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   104
void SetDebugString(const char *s)
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   105
{
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   106
	int v;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   107
	char *end;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   108
	const char *t;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   109
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6210
diff changeset
   110
	/* global debugging level? */
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   111
	if (*s >= '0' && *s <= '9') {
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   112
		const DebugLevel *i;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   113
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   114
		v = strtoul(s, &end, 0);
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   115
		s = end;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   116
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2210
diff changeset
   117
		for (i = debug_level; i != endof(debug_level); ++i) *i->level = v;
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   118
	}
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   119
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6210
diff changeset
   120
	/* individual levels */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2210
diff changeset
   121
	for (;;) {
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   122
		const DebugLevel *i;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   123
		int *p;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   124
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6210
diff changeset
   125
		/* skip delimiters */
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   126
		while (*s == ' ' || *s == ',' || *s == '\t') s++;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   127
		if (*s == '\0') break;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   128
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   129
		t = s;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   130
		while (*s >= 'a' && *s <= 'z') s++;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   131
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6210
diff changeset
   132
		/* check debugging levels */
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   133
		p = NULL;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   134
		for (i = debug_level; i != endof(debug_level); ++i)
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   135
			if (s == t + strlen(i->name) && strncmp(t, i->name, s - t) == 0) {
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   136
				p = i->level;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   137
				break;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   138
			}
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   139
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   140
		if (*s == '=') s++;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   141
		v = strtoul(s, &end, 0);
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   142
		s = end;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2210
diff changeset
   143
		if (p != NULL) {
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   144
			*p = v;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2210
diff changeset
   145
		} else {
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   146
			ShowInfoF("Unknown debug level '%.*s'", s - t, t);
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   147
			return;
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   148
		}
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   149
	}
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents:
diff changeset
   150
}
1847
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   151
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   152
/** Print out the current debug-level
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   153
 * Just return a string with the values of all the debug categorites
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   154
 * @return string with debug-levels
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   155
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6451
diff changeset
   156
const char *GetDebugString()
1847
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   157
{
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   158
	const DebugLevel *i;
8688
89da78a54edb (svn r11755) -Fix: Debug level string buffer was not long enough to contain all debug levels.
peter1138
parents: 8627
diff changeset
   159
	static char dbgstr[150];
1847
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   160
	char dbgval[20];
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   161
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   162
	memset(dbgstr, 0, sizeof(dbgstr));
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   163
	i = debug_level;
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   164
	snprintf(dbgstr, sizeof(dbgstr), "%s=%d", i->name, *i->level);
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   165
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   166
	for (i++; i != endof(debug_level); i++) {
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   167
		snprintf(dbgval, sizeof(dbgval), ", %s=%d", i->name, *i->level);
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   168
		ttd_strlcat(dbgstr, dbgval, sizeof(dbgstr));
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   169
	}
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   170
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   171
	return dbgstr;
47703af63895 (svn r2352) - Feature: add the possibility to print out the current debug-level
Darkvater
parents: 1678
diff changeset
   172
}
8743
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   173
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   174
#ifdef DEBUG_DUMP_COMMANDS
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   175
#include "fileio.h"
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   176
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   177
void CDECL DebugDumpCommands(const char *s, ...)
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   178
{
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   179
	static FILE *f = FioFOpenFile("commands-out.log", "wb", AUTOSAVE_DIR);
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   180
	if (f == NULL) return;
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   181
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   182
	va_list va;
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   183
	va_start(va, s);
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   184
	vfprintf(f, s, va);
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   185
	va_end(va);
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   186
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   187
	fflush(f);
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   188
}
62a558995c35 (svn r11811) -Fix: make compilation without networking work again (and thus move the debugdumpcommand stuff out of the network 'area').
rubidium
parents: 8710
diff changeset
   189
#endif /* DEBUG_DUMP_COMMANDS */