logging has a debug/info option now

fixed a bug in the umluaut_test, was not initializing the tnode.
This commit is contained in:
Enno Rehling 2012-05-16 01:56:25 +02:00
parent 77110158f9
commit 64f1ceecf5
5 changed files with 52 additions and 7 deletions

View file

@ -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)

View file

@ -20,7 +20,7 @@ without prior permission by the authors of Eressea.
#include <time.h>
/* 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) {

View file

@ -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

View file

@ -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));

View file

@ -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);