From 2e2ce4effa1cbb8731bab791d65952ddcdea07c8 Mon Sep 17 00:00:00 2001 From: cohrs Date: Sun, 2 Jun 2002 18:49:18 +0000 Subject: [PATCH] the panic log Add an optional paniclog file, controlled by a new PANICLOG macro that can be used to log all panic and impossible messages. Helpful when people forget to send, or didn't see, the message. --- doc/fixes34.1 | 1 + include/config.h | 8 +++++--- include/extern.h | 1 + src/end.c | 1 + src/files.c | 22 ++++++++++++++++++++++ src/pline.c | 5 +++++ 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/doc/fixes34.1 b/doc/fixes34.1 index 05e86fdf8..954cafce7 100644 --- a/doc/fixes34.1 +++ b/doc/fixes34.1 @@ -149,3 +149,4 @@ showrace option travel option mouse_support wincap option debug mode: #panic routine to test panic() and panic save file generation +a new PANICLOG optional file to log the reason for panic and impossible messages diff --git a/include/config.h b/include/config.h index fddb25795..51268e619 100644 --- a/include/config.h +++ b/include/config.h @@ -131,9 +131,10 @@ /* * Section 2: Some global parameters and filenames. - * Commenting out WIZARD, LOGFILE, or NEWS removes that feature - * from the game; otherwise set the appropriate wizard name. - * LOGFILE and NEWS refer to files in the playground. + * Commenting out WIZARD, LOGFILE, NEWS or PANICLOG removes that + * feature from the game; otherwise set the appropriate wizard + * name. LOGFILE, NEWS and PANICLOG refer to files in the + * playground. */ #ifndef WIZARD /* allow for compile-time or Makefile changes */ @@ -147,6 +148,7 @@ #define LOGFILE "logfile" /* larger file for debugging purposes */ #define NEWS "news" /* the file containing the latest hack news */ +#define PANICLOG "paniclog" /* log of panic and impossible events */ /* * If COMPRESS is defined, it should contain the full path name of your diff --git a/include/extern.h b/include/extern.h index 3ea9381bc..1a0cfa86b 100644 --- a/include/extern.h +++ b/include/extern.h @@ -638,6 +638,7 @@ E void FDECL(check_recordfile, (const char *)); #if defined(WIZARD) E void NDECL(read_wizkit); #endif +E void FDECL(paniclog, (const char *, const char *)); /* ### fountain.c ### */ diff --git a/src/end.c b/src/end.c index 7cac2cbf4..d3b36782a 100644 --- a/src/end.c +++ b/src/end.c @@ -294,6 +294,7 @@ panic VA_DECL(const char *, str) char buf[BUFSZ]; Vsprintf(buf,str,VA_ARGS); raw_print(buf); + paniclog("panic", buf); } #if defined(WIZARD) && (defined(UNIX) || defined(VMS) || defined(LATTICE) || defined(WIN32)) if (wizard) diff --git a/src/files.c b/src/files.c index c2f7bd560..6813c250b 100644 --- a/src/files.c +++ b/src/files.c @@ -1782,4 +1782,26 @@ const char *dir; /* ---------- END SCOREBOARD CREATION ----------- */ +/* ---------- BEGIN PANIC/IMPOSSIBLE LOG ----------- */ + +/*ARGSUSED*/ +void +paniclog(why, s) +const char* why; +const char* s; +{ +#ifdef PANICLOG + FILE *lfile; + + lfile = fopen_datafile(PANICLOG, "a", TRUE); + if (lfile) { + (void) fprintf(lfile, "%08ld: %s %s\n", + yyyymmdd((time_t)0L), why, s); + (void) fclose(lfile); + } +#endif /* PANICLOG */ +} + +/* ---------- END PANIC/IMPOSSIBLE LOG ----------- */ + /*files.c*/ diff --git a/src/pline.c b/src/pline.c index 08a6d1958..72766f9ae 100644 --- a/src/pline.c +++ b/src/pline.c @@ -248,6 +248,11 @@ void impossible VA_DECL(const char *, s) VA_START(s); VA_INIT(s, const char *); + { + char pbuf[BUFSZ]; + Vsprintf(pbuf,s,VA_ARGS); + paniclog("impossible", s); + } vpline(s,VA_ARGS); pline("Program in disorder - perhaps you'd better #quit."); VA_END(); -- 2.40.0