/* vi: set ts=2: +-------------------+ Christian Schlittchen | | Enno Rehling | Eressea PBEM host | Katja Zedel | (c) 1998 - 2003 | Henning Peters | | Ingo Wilken +-------------------+ Stefan Reich This program may not be used, modified or distributed without prior permission by the authors of Eressea. */ #include #include "log.h" #include "unicode.h" #include #include #include #include #include /* TODO: set from external function */ int log_flags = LOG_FLUSH|LOG_CPERROR|LOG_CPWARNING; #ifdef STDIO_CP static int stdio_codepage = STDIO_CP; #else static int stdio_codepage = 0; #endif static FILE * logfile; #define MAXLENGTH 4096 /* because I am lazy, CP437 output is limited to this many chars */ void log_flush(void) { fflush(logfile); } void log_puts(const char * str) { fflush(stdout); if (!logfile) logfile = stderr; fputs(str, logfile); } static int cp_convert(const char * format, char * buffer, size_t length, int codepage) { /* when console output on MSDOS, convert to codepage */ const char * input = format; char * pos = buffer; while (pos+1=level) { fprintf(logfile, "INFO[%u]: ", level); va_start(marker, format); vfprintf(logfile, format, marker); va_end(marker); if (logfile!=stderr) { if (stderr_level>=level) { fprintf(stderr, "INFO[%u]: ", level); va_start(marker, format); if (stdio_codepage) { char buffer[MAXLENGTH]; char converted[MAXLENGTH]; vsnprintf(buffer, sizeof(buffer), format, marker); if (cp_convert(buffer, converted, MAXLENGTH, stdio_codepage)==0) { fputs(converted, stderr); } else { /* fall back to non-converted output */ va_end(marker); va_start(marker, format); vfprintf(stderr, format, marker); } } else { vfprintf(stderr, format, marker); } va_end(marker); } if (log_flags & LOG_FLUSH) { log_flush(); } } } }