/* 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 #include /* TODO: set from external function */ int log_flags = LOG_FLUSH | LOG_CPERROR | LOG_CPWARNING | LOG_CPDEBUG; int log_stderr = 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 */ #define LOG_MAXBACKUPS 5 void log_flush(void) { if (logfile) fflush(logfile); } void log_puts(const char *str) { fflush(stdout); if (logfile) { 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 < buffer + length && *input) { size_t length = 0; int result = 0; if (codepage == 437) { result = unicode_utf8_to_cp437(pos, input, &length); } else if (codepage == 1252) { result = unicode_utf8_to_cp1252(pos, input, &length); } if (result != 0) { *pos = 0; /* just in case caller ignores our return value */ return result; } ++pos; input += length; } *pos = 0; return 0; } void log_rotate(const char *filename, int maxindex) { int n; if (_access(filename, 4)==0) { char buffer[2][MAX_PATH]; int src = 1; assert(strlen(filename)