From 655f3b2663b9909656b896cf47ad949b4e9644a8 Mon Sep 17 00:00:00 2001 From: biouman Date: Tue, 1 May 2001 11:27:52 +0000 Subject: *** empty log message *** --- lib/exceptions.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'lib/exceptions.c') diff --git a/lib/exceptions.c b/lib/exceptions.c index 0fc363e..e59013b 100644 --- a/lib/exceptions.c +++ b/lib/exceptions.c @@ -13,6 +13,7 @@ #define _(x) x #endif #include "exceptions.h" +#include "pile.h" char *contexts[128]; int clevel = 0; @@ -23,7 +24,7 @@ char *Estrdup(char *o) if (o) { if (!(r = strdup(o))) { - exception(1, _("Out of memory.")); + exception(2, _("Out of memory.")); } } else { return NULL; @@ -37,7 +38,7 @@ void *Emalloc(size_t s) if (s) { if (!(r = malloc(s))) { - exception(1, _("Out of memory.")); + exception(2, _("Out of memory.")); } } else { return NULL; @@ -48,7 +49,7 @@ void *Emalloc(size_t s) void pushcontext(char *c) { if (clevel == 128) { - exception(1, _("Too much error contexts during pushcontext().")); + exception(2, _("Too much error contexts during pushcontext().")); } contexts[clevel++] = Estrdup(c); #ifdef DEBUG @@ -59,7 +60,7 @@ void pushcontext(char *c) void popcontext(void) { if (clevel == 0) { - exception(1, _("Error context empty, but popcontext() called.")); + exception(2, _("Error context empty, but popcontext() called.")); } free(contexts[--clevel]); } @@ -71,14 +72,24 @@ void flushcontext(void) } } -void exception(int level, char *msg) +/* exception avec level=1 pour une erreur non fatale avec vidage de la pile sinon +pour toutre valeur de level erreur avec terminaison du programme */ + +void exception(int level, char *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); + switch (level) { + case 1: + fprintf(stderr, " Error description: %s\n", msg); + flush_pile(); + break; + default: + 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(1); + break; + } } -- cgit v1.2.3