| 1 |
#include "syserr.h" |
| 2 |
|
| 3 |
#include "debug.h" |
| 4 |
#include "utils.h" |
| 5 |
#include "current.h" |
| 6 |
#include "output.h" |
| 7 |
|
| 8 |
|
| 9 |
static void (*handler)(char *) = NULL; |
| 10 |
|
| 11 |
|
| 12 |
static void runtimeError(char *errorClassification, char *errorDescription, char *blurb) { |
| 13 |
output("$n$nAs you enter the twilight zone of Adventures, you stumble \ |
| 14 |
and fall to your knees. In front of you, you can vaguely see the outlines \ |
| 15 |
of an Adventure that never was.$n$n"); |
| 16 |
output(errorClassification); |
| 17 |
output(errorDescription); |
| 18 |
newline(); |
| 19 |
|
| 20 |
if (current.sourceLine != 0) { |
| 21 |
printf("At source line %d in '%s':\n", current.sourceLine, sourceFileName(current.sourceFile)); |
| 22 |
printf("%s", readSourceLine(current.sourceFile, current.sourceLine)); |
| 23 |
} |
| 24 |
|
| 25 |
newline(); |
| 26 |
output(blurb); |
| 27 |
|
| 28 |
terminate(2); |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
void setSyserrHandler(void (*f)(char *)) |
| 34 |
{ |
| 35 |
handler = f; |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
void syserr(char *description) |
| 42 |
{ |
| 43 |
lin = 0; |
| 44 |
if (handler == NULL) { |
| 45 |
char *blurb = "<If you are the creator of this piece of Interactive Fiction, \ |
| 46 |
please help debug this Alan system error. Collect *all* the sources, and, if possible, an \ |
| 47 |
exact transcript of the commands that led to this error, in a zip-file and send \ |
| 48 |
it to [email protected]. Thank you!>"; |
| 49 |
runtimeError("SYSTEM ERROR: ", description, blurb); |
| 50 |
} else |
| 51 |
handler(description); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
void apperr(char *description) |
| 57 |
{ |
| 58 |
if (handler == NULL) { |
| 59 |
char *blurb = "<If you are playing this piece of Interactive Fiction, \ |
| 60 |
please help the author to debug this programming error. Send an exact \ |
| 61 |
transcript of the commands that led to this error to the author. Thank you! \ |
| 62 |
If you *are* the author, then you have to figure this out before releasing the game.>"; |
| 63 |
runtimeError("APPLICATION ERROR: ", description, blurb); |
| 64 |
} else |
| 65 |
handler(description); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
void playererr(char *description) |
| 70 |
{ |
| 71 |
if (handler == NULL) { |
| 72 |
char *blurb = "<You have probably done something that is not exactly right.>"; |
| 73 |
runtimeError("PLAYER ERROR: ", description, blurb); |
| 74 |
} else |
| 75 |
handler(description); |
| 76 |
} |