From 864dc5981c6de5abff5ef0305f0f0f5cf91c6e60 Mon Sep 17 00:00:00 2001
From: "Dimitrie O. Paun" <dimi@cs.toronto.edu>
Date: Fri, 10 Nov 2000 23:31:06 +0000
Subject: [PATCH] Use variable argument macros when compiling with gcc.

---
 dlls/ntdll/debugtools.c |  36 ++++++--------
 dlls/ntdll/ntdll.spec   |   8 +--
 files/file.c            |   2 +-
 include/debugtools.h    | 105 ++++++++++++++++++++++------------------
 4 files changed, 79 insertions(+), 72 deletions(-)

diff --git a/dlls/ntdll/debugtools.c b/dlls/ntdll/debugtools.c
index 22ceb34c15c..b7b53aa3a24 100644
--- a/dlls/ntdll/debugtools.c
+++ b/dlls/ntdll/debugtools.c
@@ -64,7 +64,7 @@ static inline void release( void *ptr )
 
 /* ---------------------------------------------------------------------- */
 
-const char *debugstr_an( const char *src, int n )
+const char *wine_dbgstr_an( const char *src, int n )
 {
     char *dst, *res;
 
@@ -114,7 +114,7 @@ const char *debugstr_an( const char *src, int n )
 
 /* ---------------------------------------------------------------------- */
 
-const char *debugstr_wn( const WCHAR *src, int n )
+const char *wine_dbgstr_wn( const WCHAR *src, int n )
 {
     char *dst, *res;
 
@@ -164,7 +164,7 @@ const char *debugstr_wn( const WCHAR *src, int n )
 
 /* ---------------------------------------------------------------------- */
 
-const char *debugstr_guid( const GUID *id )
+const char *wine_dbgstr_guid( const GUID *id )
 {
     char *str;
 
@@ -212,27 +212,23 @@ int wine_dbg_printf(const char *format, ...)
     va_list valist;
 
     va_start(valist, format);
-    ret = wine_dbg_vprintf( format, valist);
+    ret = wine_dbg_vprintf( format, valist );
     va_end(valist);
     return ret;
 }
 
-int __wine_dbg_header_err( const char *dbg_channel, const char *func )
+int wine_dbg_log(enum __DEBUG_CLASS cls, const char *channel,
+                 const char *function, const char *format, ... )
 {
-    return wine_dbg_printf( "err:%s:%s ", dbg_channel + 1, func );
-}
-
-int __wine_dbg_header_fixme( const char *dbg_channel, const char *func )
-{
-    return wine_dbg_printf( "fixme:%s:%s ", dbg_channel + 1, func );
-}
-
-int __wine_dbg_header_warn( const char *dbg_channel, const char *func )
-{
-    return wine_dbg_printf( "warn:%s:%s ", dbg_channel + 1, func );
-}
+    static const char *classes[__DBCL_COUNT] = { "fixme", "err", "warn", "trace" };
+    va_list valist;
+    int ret = 0;
 
-int __wine_dbg_header_trace( const char *dbg_channel, const char *func )
-{
-    return wine_dbg_printf( "trace:%s:%s ", dbg_channel + 1, func );
+    va_start(valist, format);
+    if (cls < __DBCL_COUNT)
+        ret = wine_dbg_printf( "%s:%s:%s ", classes[cls], channel + 1, function );
+    if (format)
+        ret += wine_dbg_vprintf( format, valist );
+    va_end(valist);
+    return ret;
 }
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index c76c4a9176a..ad0c4bca518 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -1017,12 +1017,12 @@ debug_channels (aspi atom cdrom console ddraw debug delayhlp dll dosfs dosmem
 @ cdecl __wine_finally_handler(ptr ptr ptr ptr) __wine_finally_handler
 
 # Debugging interface
-@ cdecl __wine_dbg_header_err(ptr str) __wine_dbg_header_err
-@ cdecl __wine_dbg_header_fixme(ptr str) __wine_dbg_header_fixme
-@ cdecl __wine_dbg_header_warn(ptr str) __wine_dbg_header_warn
-@ cdecl __wine_dbg_header_trace(ptr str) __wine_dbg_header_trace
+@ cdecl wine_dbgstr_an(str long) wine_dbgstr_an
+@ cdecl wine_dbgstr_wn(str long) wine_dbgstr_wn
+@ cdecl wine_dbgstr_guid(ptr) wine_dbgstr_guid
 @ cdecl wine_dbg_vprintf(str ptr) wine_dbg_vprintf
 @ varargs wine_dbg_printf(str) wine_dbg_printf
+@ varargs wine_dbg_log(long str str str) wine_dbg_log
 
 # Command-line
 @ cdecl __wine_get_main_args(ptr) __wine_get_main_args
diff --git a/files/file.c b/files/file.c
index 536828d100c..bb1d18c76c5 100644
--- a/files/file.c
+++ b/files/file.c
@@ -296,7 +296,7 @@ void FILE_SetDosError(void)
         SetLastError( ERROR_BAD_FORMAT );
         break;
     default:
-        WARN( strerror(save_errno) );
+        WARN( "unknown file error: %s", strerror(save_errno) );
         SetLastError( ERROR_GEN_FAILURE );
         break;
     }
diff --git a/include/debugtools.h b/include/debugtools.h
index 01c450372e8..b065227a3bd 100644
--- a/include/debugtools.h
+++ b/include/debugtools.h
@@ -15,77 +15,88 @@ struct _GUID;
 enum __DEBUG_CLASS { __DBCL_FIXME, __DBCL_ERR, __DBCL_WARN, __DBCL_TRACE, __DBCL_COUNT };
 
 #ifndef NO_TRACE_MSGS
-# define __GET_DEBUGGING_trace(dbch) ((dbch)[0] & (1 << __DBCL_TRACE))
+# define __GET_DEBUGGING_TRACE(dbch) ((dbch)[0] & (1 << __DBCL_TRACE))
 #else
-# define __GET_DEBUGGING_trace(dbch) 0
+# define __GET_DEBUGGING_TRACE(dbch) 0
 #endif
 
 #ifndef NO_DEBUG_MSGS
-# define __GET_DEBUGGING_warn(dbch)  ((dbch)[0] & (1 << __DBCL_WARN))
-# define __GET_DEBUGGING_fixme(dbch) ((dbch)[0] & (1 << __DBCL_FIXME))
+# define __GET_DEBUGGING_WARN(dbch)  ((dbch)[0] & (1 << __DBCL_WARN))
+# define __GET_DEBUGGING_FIXME(dbch) ((dbch)[0] & (1 << __DBCL_FIXME))
 #else
-# define __GET_DEBUGGING_warn(dbch)  0
-# define __GET_DEBUGGING_fixme(dbch) 0
+# define __GET_DEBUGGING_WARN(dbch)  0
+# define __GET_DEBUGGING_FIXME(dbch) 0
 #endif
 
 /* define error macro regardless of what is configured */
-#define __GET_DEBUGGING_err(dbch)  ((dbch)[0] & (1 << __DBCL_ERR))
+#define __GET_DEBUGGING_ERR(dbch)  ((dbch)[0] & (1 << __DBCL_ERR))
 
-#define __GET_DEBUGGING(dbcl,dbch)  __GET_DEBUGGING_##dbcl(dbch)
+#define __GET_DEBUGGING(dbcl,dbch)  __GET_DEBUGGING##dbcl(dbch)
 #define __SET_DEBUGGING(dbcl,dbch,on) \
     ((on) ? ((dbch)[0] |= 1 << (dbcl)) : ((dbch)[0] &= ~(1 << (dbcl))))
 
-#ifndef __GNUC__
-#define __FUNCTION__ ""
-#endif
+#ifdef __GNUC__
 
 #define __DPRINTF(dbcl,dbch) \
-  (!__GET_DEBUGGING(dbcl,(dbch)) || (__wine_dbg_header_##dbcl((dbch),__FUNCTION__),0)) ? \
-     (void)0 : (void)wine_dbg_printf
+  do { if(__GET_DEBUGGING(dbcl,(dbch))) { \
+       const char * const __dbch = (dbch); \
+       const enum __DEBUG_CLASS __dbcl = __DBCL##dbcl; \
+       __WINE_DBG_LOG
 
-extern int __wine_dbg_header_err( const char *dbg_channel, const char *func );
-extern int __wine_dbg_header_warn( const char *dbg_channel, const char *func );
-extern int __wine_dbg_header_fixme( const char *dbg_channel, const char *func );
-extern int __wine_dbg_header_trace( const char *dbg_channel, const char *func );
+#define __WINE_DBG_LOG(args...) \
+    wine_dbg_log( __dbcl, __dbch, __FUNCTION__, args); } } while(0)
 
-/* Exported definitions and macros */
+#define __PRINTF_ATTR(fmt,args) __attribute__((format (printf,fmt,args)));
 
-/* These function return a printable version of a string, including
-   quotes.  The string will be valid for some time, but not indefinitely
-   as strings are re-used.  */
-extern const char *debugstr_an (const char * s, int n);
-extern const char *debugstr_wn (const WCHAR *s, int n);
-extern const char *debugstr_guid( const struct _GUID *id );
+#else  /* __GNUC__ */
 
-extern int wine_dbg_vprintf( const char *format, va_list args );
-
-inline static const char *debugstr_a( const char *s )  { return debugstr_an( s, 80 ); }
-inline static const char *debugstr_w( const WCHAR *s ) { return debugstr_wn( s, 80 ); }
-inline static const char *debugres_a( const char *s )  { return debugstr_an( s, 80 ); }
-inline static const char *debugres_w( const WCHAR *s ) { return debugstr_wn( s, 80 ); }
+#define __DPRINTF(dbcl,dbch) \
+    (!__GET_DEBUGGING(dbcl,(dbch)) || \
+     (wine_dbg_log(__DBCL##dbcl,(dbch),__FILE__,"%d: ",__LINE__),0)) ? \
+     (void)0 : (void)wine_dbg_printf
 
-#ifdef __GNUC__
-extern int wine_dbg_printf(const char *format, ...) __attribute__((format (printf,1,2)));
-#else
-extern int wine_dbg_printf(const char *format, ...);
-#endif
+#define __PRINTF_ATTR(fmt, args)
 
-#define TRACE        __DPRINTF(trace,__wine_dbch___default)
-#define TRACE_(ch)   __DPRINTF(trace,__wine_dbch_##ch)
-#define TRACE_ON(ch) __GET_DEBUGGING(trace,__wine_dbch_##ch)
+#endif  /* __GNUC__ */
 
-#define WARN         __DPRINTF(warn,__wine_dbch___default)
-#define WARN_(ch)    __DPRINTF(warn,__wine_dbch_##ch)
-#define WARN_ON(ch)  __GET_DEBUGGING(warn,__wine_dbch_##ch)
+/* Exported definitions and macros */
 
-#define FIXME        __DPRINTF(fixme,__wine_dbch___default)
-#define FIXME_(ch)   __DPRINTF(fixme,__wine_dbch_##ch)
-#define FIXME_ON(ch) __GET_DEBUGGING(fixme,__wine_dbch_##ch)
+/* These function return a printable version of a string, including
+   quotes.  The string will be valid for some time, but not indefinitely
+   as strings are re-used.  */
+extern const char *wine_dbgstr_an( const char * s, int n );
+extern const char *wine_dbgstr_wn( const WCHAR *s, int n );
+extern const char *wine_dbgstr_guid( const struct _GUID *id );
+
+extern int wine_dbg_vprintf( const char *format, va_list args ) __PRINTF_ATTR(1,0);
+extern int wine_dbg_printf( const char *format, ... ) __PRINTF_ATTR(1,2);
+extern int wine_dbg_log( enum __DEBUG_CLASS cls, const char *ch,
+                         const char *func, const char *format, ... ) __PRINTF_ATTR(4,5);
+
+inline static const char *debugstr_an( const char * s, int n ) { return wine_dbgstr_an( s, n ); }
+inline static const char *debugstr_wn( const WCHAR *s, int n ) { return wine_dbgstr_wn( s, n ); }
+inline static const char *debugstr_guid( const struct _GUID *id ) { return wine_dbgstr_guid(id); }
+inline static const char *debugstr_a( const char *s )  { return wine_dbgstr_an( s, 80 ); }
+inline static const char *debugstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, 80 ); }
+inline static const char *debugres_a( const char *s )  { return wine_dbgstr_an( s, 80 ); }
+inline static const char *debugres_w( const WCHAR *s ) { return wine_dbgstr_wn( s, 80 ); }
+
+#define TRACE        __DPRINTF(_TRACE,__wine_dbch___default)
+#define TRACE_(ch)   __DPRINTF(_TRACE,__wine_dbch_##ch)
+#define TRACE_ON(ch) __GET_DEBUGGING(_TRACE,__wine_dbch_##ch)
+
+#define WARN         __DPRINTF(_WARN,__wine_dbch___default)
+#define WARN_(ch)    __DPRINTF(_WARN,__wine_dbch_##ch)
+#define WARN_ON(ch)  __GET_DEBUGGING(_WARN,__wine_dbch_##ch)
+
+#define FIXME        __DPRINTF(_FIXME,__wine_dbch___default)
+#define FIXME_(ch)   __DPRINTF(_FIXME,__wine_dbch_##ch)
+#define FIXME_ON(ch) __GET_DEBUGGING(_FIXME,__wine_dbch_##ch)
 
 #undef ERR  /* Solaris got an 'ERR' define in <sys/reg.h> */
-#define ERR          __DPRINTF(err,__wine_dbch___default)
-#define ERR_(ch)     __DPRINTF(err,__wine_dbch_##ch)
-#define ERR_ON(ch)   __GET_DEBUGGING(err,__wine_dbch_##ch)
+#define ERR          __DPRINTF(_ERR,__wine_dbch___default)
+#define ERR_(ch)     __DPRINTF(_ERR,__wine_dbch_##ch)
+#define ERR_ON(ch)   __GET_DEBUGGING(_ERR,__wine_dbch_##ch)
 
 #define DECLARE_DEBUG_CHANNEL(ch) \
     extern char __wine_dbch_##ch[];
-- 
GitLab