diff options
author | Pixel <> | 2001-04-02 01:00:37 +0000 |
---|---|---|
committer | Pixel <> | 2001-04-02 01:00:37 +0000 |
commit | ce176d3637caebac401e634b40abe8bc48505327 (patch) | |
tree | 6176a1d949974cb887773177727c2894945b56e8 /lib/exceptions.c | |
parent | 8212d25ba09a7fdf1938a1992022a0143d29e05b (diff) |
Exceptions.
Diffstat (limited to 'lib/exceptions.c')
-rw-r--r-- | lib/exceptions.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/exceptions.c b/lib/exceptions.c index 349e8a9..231ca63 100644 --- a/lib/exceptions.c +++ b/lib/exceptions.c @@ -4,6 +4,9 @@ #include "config.h" #include "exceptions.h" +char * contexts[128]; +int clevel = 0; + char * Estrdup(char * o) { char * r; @@ -22,8 +25,34 @@ void * Emalloc(size_t s) { return r; } +void pushcontext(char * c) { + if (clevel == 128) { + exception(1, _("Too much error contexts during pushcontext().")); + } + contexts[clevel++] = Estrdup(c); +} + +void popcontext(void) { + if (clevel == 0) { + exception(1, _("Error context empty, but popcontext() called.")); + } + free(contexts[--clevel]); +} + +void flushcontext(void) { + while (clevel) { + popcontext(); + } +} + void exception(int level, char *msg) { - fprintf(stderr, "%s\n", msg); + int i; + + fprintf(stderr, "Error detected. Showing context.\n"); + for (i = 0; i < clevel; i++) { + fprintf(stderr, " (%i) - %s\n", i, contexts[i]); + } + fprintf(stderr, " Error description: %s\n", msg); exit(level); } |