diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index 22906eba2..384ae4c22 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -205,7 +205,7 @@ int fix_demand(region * rd) for (rl = rlist; rl; rl = rl->next) { region *r = rl->data; if (!fval(r, RF_CHAOTIC)) { - log_info((LOG_INFO1, "fixing demand in %s\n", regionname(r, NULL))); + log_debug("fixing demand in %s\n", regionname(r, NULL)); } sale = mlux[rng_int() % maxlux]; if (sale) diff --git a/src/util/log.c b/src/util/log.c index ec93d625c..ab7f503f9 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -20,7 +20,7 @@ without prior permission by the authors of Eressea. #include /* TODO: set from external function */ -int log_flags = LOG_FLUSH | LOG_CPERROR | LOG_CPWARNING; +int log_flags = LOG_FLUSH | LOG_CPERROR | LOG_CPWARNING | LOG_CPDEBUG; #ifdef STDIO_CP static int stdio_codepage = STDIO_CP; #else @@ -157,6 +157,49 @@ static int check_dupe(const char *format, const char *type) return 0; } +void _log_debug(const char *format, ...) +{ + if (log_flags & LOG_CPDEBUG) { + int dupe = check_dupe(format, "DEBUG"); + + fflush(stdout); + if (!logfile) + logfile = stderr; + if (logfile != stderr) { + va_list marker; + fputs("DEBUG: ", logfile); + va_start(marker, format); + vfprintf(logfile, format, marker); + va_end(marker); + } + if (!dupe) { + va_list marker; + fputs("DEBUG: ", stderr); + 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(); + } + } +} + void _log_warn(const char *format, ...) { if (log_flags & LOG_CPWARNING) { diff --git a/src/util/log.h b/src/util/log.h index a9e8eabd3..d7228222b 100644 --- a/src/util/log.h +++ b/src/util/log.h @@ -25,18 +25,19 @@ extern "C" { #define log_warning(x) _log_warn x #define log_error(x) _log_error x #define log_info(x) _log_info x +#define log_debug _log_debug /* use macros above instead of these: */ extern void _log_warn(const char *format, ...); extern void _log_error(const char *format, ...); + extern void _log_debug(const char *format, ...); extern void _log_info(unsigned int flag, const char *format, ...); #define LOG_FLUSH 0x01 #define LOG_CPWARNING 0x02 #define LOG_CPERROR 0x04 -#define LOG_INFO1 0x08 -#define LOG_INFO2 0x10 -#define LOG_INFO3 0x20 +#define LOG_CPDEBUG 0x08 +#define LOG_CPINFO 0x10 extern int log_flags; #ifdef __cplusplus diff --git a/src/util/translation.c b/src/util/translation.c index b5ff01c70..9c329592d 100644 --- a/src/util/translation.c +++ b/src/util/translation.c @@ -168,7 +168,7 @@ void add_function(const char *symbol, evalfun parse) static evalfun find_function(const char *symbol) { - void * matches; + const void * matches; if (cb_find_prefix(&functions, symbol, strlen(symbol)+1, &matches, 1, 0)) { evalfun result; cb_get_kv(matches, &result, sizeof(result)); diff --git a/src/util/umlaut_test.c b/src/util/umlaut_test.c index 3b3995abc..900f47f67 100644 --- a/src/util/umlaut_test.c +++ b/src/util/umlaut_test.c @@ -22,10 +22,11 @@ static void test_transliterate(CuTest * tc) static void test_umlaut(CuTest * tc) { const char * umlauts = "\xc3\xa4\xc3\xb6\xc3\xbc\xc3\x9f"; /* auml ouml uuml szlig nul */ - tnode tokens = { 0 }; + tnode tokens; variant id; int result; + memset(&tokens, 0, sizeof(tokens)); /* don't crash on an empty set */ result = findtoken(&tokens, "herpderp", &id); CuAssertIntEquals(tc, E_TOK_NOMATCH, result);