(svn r7602) -Fix (r7565): MSVC2003 and lower don't support variadic macros, so work around

this and thank MS for such a crappy, shitty crap compiler.
pull/155/head
Darkvater 18 years ago
parent 9516b4db60
commit bc9ceb8b74

@ -25,20 +25,6 @@ int _debug_freetype_level;
int _debug_sl_level;
void CDECL debug(const char *dbg, ...)
{
va_list va;
const char *s;
char buf[1024];
va_start(va, dbg);
s = va_arg(va, const char*);
vsnprintf(buf, lengthof(buf), s, va);
va_end(va);
fprintf(stderr, "dbg: [%s] %s\n", dbg, buf);
IConsoleDebug(dbg, buf);
}
typedef struct DebugLevel {
const char *name;
int *level;
@ -63,6 +49,39 @@ typedef struct DebugLevel {
};
#undef DEBUG_LEVEL
#if !defined(NO_DEBUG_MESSAGES)
/** Functionized DEBUG macro for compilers that don't support
* variadic macros (__VA_ARGS__) such as...yes MSVC2003 and lower */
#if defined(NO_VARARG_MACRO)
void CDECL DEBUG(int name, int level, ...)
{
va_list va;
const char *dbg;
const DebugLevel *dl = &debug_level[name];
if (level != 0 && *dl->level < level) return;
dbg = dl->name;
va_start(va, level);
#else
void CDECL debug(const char *dbg, ...)
{
va_list va;
va_start(va, dbg);
#endif /* NO_VARARG_MACRO */
{
const char *s;
char buf[1024];
s = va_arg(va, const char*);
vsnprintf(buf, lengthof(buf), s, va);
va_end(va);
fprintf(stderr, "dbg: [%s] %s\n", dbg, buf);
IConsoleDebug(dbg, buf);
}
}
#endif /* NO_DEBUG_MESSAGES */
void SetDebugString(const char *s)
{
int v;

@ -17,10 +17,43 @@
* 6.. - extremely detailed spamming
*/
/* Of course MSVC 2003 and lower has no support for variadic macros
* so we need to work around this... *sigh* */
#if defined(_MSC_VER) && (_MSC_VER < 1400)
#define NO_VARARG_MACRO
#endif
#if defined(NO_VARARG_MACRO)
enum DebugLevelType {
ai,
driver,
grf,
map,
misc,
ms,
net,
sprite,
oldloader,
ntp,
npf,
yapf,
freetype,
sl,
};
#endif /* NO_VARARG_MACRO */
#ifdef NO_DEBUG_MESSAGES
#define DEBUG(name, level, ...)
#else
#if defined(__GNUC__) && (__GNUC__ < 3)
#if defined(NO_VARARG_MACRO)
static inline void DEBUG(int name, int level, ...) {}
#elif defined(__GNUC__) && (__GNUC__ < 3)
#define DEBUG(name, level, args...)
#else
#define DEBUG(name, level, ...)
#endif
#else /* NO_DEBUG_MESSAGES */
#if defined(NO_VARARG_MACRO)
void CDECL DEBUG(int name, int level, ...);
#elif defined(__GNUC__) && (__GNUC__ < 3)
#define DEBUG(name, level, args...) if ((level == 0) || ( _debug_ ## name ## _level >= level)) debug(#name, args)
#else
#define DEBUG(name, level, ...) if (level == 0 || _debug_ ## name ## _level >= level) debug(#name, __VA_ARGS__)
@ -40,18 +73,20 @@
extern int _debug_yapf_level;
extern int _debug_freetype_level;
extern int _debug_sl_level;
#endif
void CDECL debug(const char *dbg, ...);
#if !defined(NO_VARARG_MACRO)
void CDECL debug(const char *dbg, ...);
#endif /* NO_VARARG_MACRO */
#endif /* NO_DEBUG_MESSAGES */
void SetDebugString(const char *s);
const char *GetDebugString(void);
/* MSVCRT of course has to have a different syntax for long long *sigh* */
#if defined(_MSC_VER) || defined(__MINGW32__)
# define OTTD_PRINTF64 "I64"
#define OTTD_PRINTF64 "I64"
#else
# define OTTD_PRINTF64 "ll"
#define OTTD_PRINTF64 "ll"
#endif
// Used for profiling

@ -118,8 +118,7 @@ static const char *DedicatedVideoStart(const char * const *parm)
_screen.height = _cur_resolution[1];
_dedicated_video_mem = malloc(_cur_resolution[0]*_cur_resolution[1]);
_debug_net_level = 6;
_debug_misc_level = 0;
SetDebugString("net=6");
#ifdef WIN32
// For win32 we need to allocate a console (debug mode does the same)

Loading…
Cancel
Save