summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-12-28 19:38:09 +0000
committerDarkvater <Darkvater@openttd.org>2006-12-28 19:38:09 +0000
commitbc9ceb8b74086c48c71a02037809dcd7631848d4 (patch)
tree66b066892f39cd045bba906de83880269ed34b0c
parent9516b4db608b2ead39106ed3f3aa9b1b223c535b (diff)
downloadopenttd-bc9ceb8b74086c48c71a02037809dcd7631848d4.tar.xz
(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.
-rw-r--r--debug.c47
-rw-r--r--debug.h49
-rw-r--r--video/dedicated_v.c3
3 files changed, 76 insertions, 23 deletions
diff --git a/debug.c b/debug.c
index fc3ca2df0..536d21c6a 100644
--- a/debug.c
+++ b/debug.c
@@ -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;
diff --git a/debug.h b/debug.h
index 87c2862e5..c99795ddd 100644
--- a/debug.h
+++ b/debug.h
@@ -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
diff --git a/video/dedicated_v.c b/video/dedicated_v.c
index c4a74e902..824ca2936 100644
--- a/video/dedicated_v.c
+++ b/video/dedicated_v.c
@@ -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)