DSCF

.co.uk

PC32

A ColorForth compiler and editor for x86-64
git clone https://dscf.co.uk/clone/PC32.git
Back | Log | Files | Refs | Issues

debuglog.h (701B)


      1 /* Opt-in debug log: set PC32_DEBUG=1 and dbg() writes to stderr and PC32_debug.log
      2  * (in the working directory).  Does nothing otherwise.  Used by main.c and win32_compat.h. */
      3 #ifndef DEBUGLOG_H
      4 #define DEBUGLOG_H
      5 
      6 #include <stdio.h>
      7 #include <stdlib.h>
      8 #include <stdarg.h>
      9 
     10 static int g_dbg = -1;			/* -1 = not decided yet */
     11 
     12 static void dbg(const char* fmt, ...) {
     13 	static FILE* logfile = NULL;
     14 	if(g_dbg < 0) {
     15 		g_dbg = getenv("PC32_DEBUG") != NULL;
     16 		if(g_dbg) logfile = fopen("PC32_debug.log", "w");
     17 	}
     18 	if(!g_dbg) return;
     19 	va_list a;
     20 	va_start(a, fmt); vfprintf(stderr, fmt, a); va_end(a);
     21 	if(logfile) { va_start(a, fmt); vfprintf(logfile, fmt, a); va_end(a); fflush(logfile); }
     22 }
     23 
     24 #endif