#include "syserr.h" #include "debug.h" #include "utils.h" #include "current.h" #include "output.h" static void (*handler)(char *) = NULL; /*----------------------------------------------------------------------*/ static void runtimeError(char *errorClassification, char *errorDescription, char *blurb) { output("$n$nAs you enter the twilight zone of Adventures, you stumble \ and fall to your knees. In front of you, you can vaguely see the outlines \ of an Adventure that never was.$n$n"); output(errorClassification); output(errorDescription); newline(); if (current.sourceLine != 0) { printf("At source line %d in '%s':\n", current.sourceLine, sourceFileName(current.sourceFile)); printf("%s", readSourceLine(current.sourceFile, current.sourceLine)); } newline(); output(blurb); terminate(2); } /*======================================================================*/ void setSyserrHandler(void (*f)(char *)) { handler = f; } /*======================================================================*/ // TODO Make syserr() use ... as printf() void syserr(char *description) { lin = 0; if (handler == NULL) { char *blurb = ""; runtimeError("SYSTEM ERROR: ", description, blurb); } else handler(description); } /*======================================================================*/ void apperr(char *description) { if (handler == NULL) { char *blurb = ""; runtimeError("APPLICATION ERROR: ", description, blurb); } else handler(description); } /*======================================================================*/ void playererr(char *description) { if (handler == NULL) { char *blurb = ""; runtimeError("PLAYER ERROR: ", description, blurb); } else handler(description); }