src/debug.cpp
branchNewGRF_ports
changeset 6877 889301acc299
parent 6872 1c4a4a609f85
child 10724 68a692eacf22
equal deleted inserted replaced
6876:2c40faeef7a5 6877:889301acc299
    57 	};
    57 	};
    58 #undef DEBUG_LEVEL
    58 #undef DEBUG_LEVEL
    59 
    59 
    60 #if !defined(NO_DEBUG_MESSAGES)
    60 #if !defined(NO_DEBUG_MESSAGES)
    61 
    61 
    62 /** Functionized DEBUG macro for compilers that don't support
       
    63  * variadic macros (__VA_ARGS__) such as...yes MSVC2003 and lower */
       
    64 #if defined(NO_VARARG_MACRO)
       
    65 void CDECL DEBUG(int name, int level, ...)
       
    66 {
       
    67 	va_list va;
       
    68 	const char *dbg;
       
    69 	const DebugLevel *dl = &debug_level[name];
       
    70 
       
    71 	if (level != 0 && *dl->level < level) return;
       
    72 	dbg = dl->name;
       
    73 	va_start(va, level);
       
    74 #else
       
    75 void CDECL debug(const char *dbg, ...)
    62 void CDECL debug(const char *dbg, ...)
    76 {
    63 {
    77 	va_list va;
    64 	va_list va;
    78 	va_start(va, dbg);
    65 	va_start(va, dbg);
    79 #endif /* NO_VARARG_MACRO */
    66 	const char *s;
       
    67 	char buf[1024];
       
    68 
       
    69 	s = va_arg(va, const char*);
       
    70 	vsnprintf(buf, lengthof(buf), s, va);
       
    71 	va_end(va);
       
    72 #if defined(ENABLE_NETWORK)
       
    73 	if (_debug_socket != INVALID_SOCKET) {
       
    74 		char buf2[lengthof(buf) + 32];
       
    75 
       
    76 		snprintf(buf2, lengthof(buf2), "dbg: [%s] %s\n", dbg, buf);
       
    77 		send(_debug_socket, buf2, strlen(buf2), 0);
       
    78 	} else
       
    79 #endif /* ENABLE_NETWORK */
    80 	{
    80 	{
    81 		const char *s;
       
    82 		char buf[1024];
       
    83 
       
    84 		s = va_arg(va, const char*);
       
    85 		vsnprintf(buf, lengthof(buf), s, va);
       
    86 		va_end(va);
       
    87 #if defined(ENABLE_NETWORK)
       
    88 		if (_debug_socket != INVALID_SOCKET) {
       
    89 			char buf2[lengthof(buf) + 32];
       
    90 
       
    91 			snprintf(buf2, lengthof(buf2), "dbg: [%s] %s\n", dbg, buf);
       
    92 			send(_debug_socket, buf2, strlen(buf2), 0);
       
    93 		} else
       
    94 #endif /* ENABLE_NETWORK */
       
    95 		{
       
    96 #if defined(WINCE)
    81 #if defined(WINCE)
    97 			/* We need to do OTTD2FS twice, but as it uses a static buffer, we need to store one temporary */
    82 		/* We need to do OTTD2FS twice, but as it uses a static buffer, we need to store one temporary */
    98 			TCHAR tbuf[512];
    83 		TCHAR tbuf[512];
    99 			_sntprintf(tbuf, sizeof(tbuf), _T("%s"), OTTD2FS(dbg));
    84 		_sntprintf(tbuf, sizeof(tbuf), _T("%s"), OTTD2FS(dbg));
   100 			NKDbgPrintfW(_T("dbg: [%s] %s\n"), tbuf, OTTD2FS(buf));
    85 		NKDbgPrintfW(_T("dbg: [%s] %s\n"), tbuf, OTTD2FS(buf));
   101 #else
    86 #else
   102 			fprintf(stderr, "dbg: [%s] %s\n", dbg, buf);
    87 		fprintf(stderr, "dbg: [%s] %s\n", dbg, buf);
   103 #endif
    88 #endif
   104 			IConsoleDebug(dbg, buf);
    89 		IConsoleDebug(dbg, buf);
   105 		}
       
   106 	}
    90 	}
   107 }
    91 }
   108 #endif /* NO_DEBUG_MESSAGES */
    92 #endif /* NO_DEBUG_MESSAGES */
   109 
    93 
   110 void SetDebugString(const char *s)
    94 void SetDebugString(const char *s)