diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 7b6c8bffb..937cac6d6 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: laws.c,v 1.19 2001/02/11 20:54:01 enno Exp $ + * $Id: laws.c,v 1.20 2001/02/12 22:39:56 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -2142,7 +2142,7 @@ reorder_owners(region * r) assert(!u->building); if (u->ship==NULL) { if (fval(u, FL_OWNER)) { - fprintf(stderr, "WARNING: Einheit %s war Besitzer von nichts.\n", unitname(u)); + log_warning(("[reorder_owners] Einheit %s war Besitzer von nichts.\n", unitname(u))); freset(u, FL_OWNER); } if (useek!=up) { diff --git a/src/common/kernel/border.c b/src/common/kernel/border.c index a90aa7d8a..0730f87a3 100644 --- a/src/common/kernel/border.c +++ b/src/common/kernel/border.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: border.c,v 1.4 2001/02/10 10:40:11 enno Exp $ + * $Id: border.c,v 1.5 2001/02/12 22:39:56 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -117,7 +117,7 @@ read_borders(FILE * f) if (to==from) { direction_t dir = (direction_t) (rand() % MAXDIRECTIONS); region * r = rconnect(from, dir); - fprintf(stderr, "WARNING: invalid %s in %s\n", type->__name, tregionid(from, NULL)); + log_error(("[read_borders] invalid %s in %s\n", type->__name, tregionid(from, NULL))); if (r!=NULL) to = r; } b = new_border(type, from, to); diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 22a830443..221dde231 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: eressea.c,v 1.12 2001/02/10 14:18:00 enno Exp $ + * $Id: eressea.c,v 1.13 2001/02/12 22:39:56 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -915,8 +915,8 @@ strcheck (const char *s, size_t maxlen) static char buffer[16 * 1024]; if (strlen(s) > maxlen) { assert(maxlen < 16 * 1024); - fprintf(stderr, "\nWARNUNG: String wurde auf %d Zeichen verkürzt:\n%s\n", - (int)maxlen, s); + log_warning(("[strcheck] String wurde auf %d Zeichen verkürzt:\n%s\n", + (int)maxlen, s)); strncpy(buffer, s, maxlen); buffer[maxlen] = 0; return buffer; diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index 61acfcea6..b3edbb344 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: eressea.h,v 1.16 2001/02/10 19:24:05 enno Exp $ + * $Id: eressea.h,v 1.17 2001/02/12 22:39:56 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -1128,6 +1128,8 @@ extern void kernel_done(void); #define FIRST_TURN 184 +#include + #ifdef _MSC_VER #include #endif diff --git a/src/common/kernel/magic.c b/src/common/kernel/magic.c index b22b7c8b1..27a8bf299 100644 --- a/src/common/kernel/magic.c +++ b/src/common/kernel/magic.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: magic.c,v 1.6 2001/02/09 13:53:51 corwin Exp $ + * $Id: magic.c,v 1.7 2001/02/12 22:39:56 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -2414,7 +2414,7 @@ sm_familiar(const unit * u, const region * r, skill_t sk, int value) /* skillmod int mod; unit * familiar = get_familiar(u); if (familiar==NULL) { - fprintf(stderr, "WARNING: %s has a familiar-skillmod, but no familiar\n", unitname(u)); + log_error(("[sm_familiar] %s has a familiar-skillmod, but no familiar\n", unitname(u))); return value; } mod = eff_skill(familiar, sk, r)/2; diff --git a/src/common/util/log.c b/src/common/util/log.c new file mode 100644 index 000000000..5bd8404e8 --- /dev/null +++ b/src/common/util/log.c @@ -0,0 +1,86 @@ +#include +#include "log.h" + +#include +#include +#include + +#define LOG_FLUSH (1<<0) +#define LOG_CPERROR (1<<1) +#define LOG_CPWARNING (1<<1) + +/* TODO: set from external function */ +static int flags = LOG_FLUSH|LOG_CPERROR; +static FILE * logfile; + +void +log_puts(const char * str) +{ + if (!logfile) logfile = stderr; + fputs(str, logfile); +} + +void +log_printf(const char * format, ...) +{ + va_list marker; + if (!logfile) logfile = stderr; + va_start(marker, format); + vfprintf(logfile, format, marker); + va_end(marker); +} + +void +log_open(const char * filename) +{ + if (logfile) log_close(); + logfile = fopen(filename, "a"); +} + +void +log_close(void) +{ + if (!logfile || logfile == stderr || logfile == stdout) return; + fclose(logfile); +} + +void +_log_warn(const char * format, ...) +{ + va_list marker; + if (!logfile) logfile = stderr; + va_start(marker, format); + fputs("WARNING: ", logfile); + vfprintf(logfile, format, marker); + va_end(marker); + if (logfile!=stderr) { + if (flags & LOG_CPWARNING) { + fputs("\bWARNING: ", stderr); + vfprintf(stderr, format, marker); + } + if (flags & LOG_FLUSH) { + fflush(logfile); + } + } +} + +void +_log_error(const char * format, ...) +{ + va_list marker; + if (!logfile) logfile = stderr; + + va_start(marker, format); + fputs("ERROR: ", logfile); + vfprintf(logfile, format, marker); + va_end(marker); + if (logfile!=stderr) { + if (flags & LOG_CPERROR) { + fputs("\bERROR: ", stderr); + vfprintf(stderr, format, marker); + } + if (flags & LOG_FLUSH) { + fflush(logfile); + } + } +} diff --git a/src/common/util/log.h b/src/common/util/log.h new file mode 100644 index 000000000..802ec5135 --- /dev/null +++ b/src/common/util/log.h @@ -0,0 +1,11 @@ +extern void log_open(const char * filename); +extern void log_printf(const char * str, ...); +extern void log_puts(const char * str); +extern void log_close(void); + +#define log_warning(x) _log_warn x +#define log_error(x) _log_error x + +/* use macros above instead of these: */ +extern void _log_warn(const char * format, ...); +extern void _log_error(const char * format, ...); diff --git a/src/eressea/korrektur.c b/src/eressea/korrektur.c index 59a2df101..bcf1d136b 100644 --- a/src/eressea/korrektur.c +++ b/src/eressea/korrektur.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: korrektur.c,v 1.20 2001/02/10 19:24:05 enno Exp $ + * $Id: korrektur.c,v 1.21 2001/02/12 22:39:57 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -83,7 +83,7 @@ fix_skills(void) /* make sure that this is done only once! */ while (a && a->data.i!=magic) a=a->next; if (a) { - fprintf(stderr, "WARNING: fix_skills() was called a second time\n"); + log_warning(("[fix_skills] function was called a second time\n")); return; } a_add(&global.attribs, a_new(&at_key))->data.i = magic; @@ -95,7 +95,7 @@ fix_skills(void) if (fscanf(F, "%s %d %d %d %d %d\n", zText, &skill, &number, &from, &self, &teach)<=0) break; u = findunit(atoi36(zText)); if (u==NULL) { - fprintf(stderr, "unit %s not found!\n", zText); + log_warning(("[fix_skills] unit %s not found!\n", zText)); continue; } myskill = get_skill(u, (skill_t)skill); @@ -114,7 +114,7 @@ fix_skills(void) attrib * a = a_find(global.attribs, &at_key); \ while (a && a->data.i!=(magic)) a=a->next; \ if (a) { \ - fprintf(stderr, "WARNING: a unique fix was called a second time\n"); \ + log_warning(("[do_once] a unique fix was called a second time\n")); \ return; \ } \ else (fun); \ @@ -413,7 +413,7 @@ repair_illusion(void) else if (i) continue; else { u->race = RC_ILLUSION; - fprintf(stderr, "Illusion repariert: %s in Partei %s\n", unitname(u), factionid(u->faction)); + log_puts("[repair_illusion] repariert: %s in Partei %s\n", unitname(u), factionid(u->faction)); } } if(!race[u->race].nonplayer && ( @@ -620,7 +620,7 @@ fix_migrants(void) { for (u=r->units;u;u=u->next) { if (u->race==RC_HUMAN) u->irace=RC_HUMAN; if (u->irace!=u->race && u->race!=RC_ILLUSION && u->race!=RC_DAEMON) { - fprintf(stderr, "WARNUNG: %s ist ein %s, als %s getarnt\n", unitname(u), race[u->race].name[0], race[u->irace].name[0]); + log_warning(("[fix_migrants] %s ist ein %s, als %s getarnt\n", unitname(u), race[u->race].name[0], race[u->irace].name[0])); } } } diff --git a/src/eressea/main.c b/src/eressea/main.c index c64a8e3bf..0357c692d 100644 --- a/src/eressea/main.c +++ b/src/eressea/main.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: main.c,v 1.14 2001/02/11 19:55:00 corwin Exp $ + * $Id: main.c,v 1.15 2001/02/12 22:39:57 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -491,6 +491,9 @@ read_args(int argc, char **argv) maxregions = atoi(argv[++i]); maxregions = (maxregions*81+80) / 81; break; + case 'l': + log_open(argv[++i]); + break; default: usage(argv[0], argv[i]); } @@ -504,6 +507,7 @@ main(int argc, char *argv[]) int i; char zText[MAX_PATH]; + log_open("eressea.log"); printf("\n%s PBEM host\n" "Copyright (C) 1996-2001 C.Schlittchen, K.Zedel, E.Rehling, H.Peters.\n\n" "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version()); @@ -538,6 +542,6 @@ main(int argc, char *argv[]) game_done(); kernel_done(); - + log_close(); return 0; }