diff options
author | Pixel <> | 2001-04-13 12:03:09 +0000 |
---|---|---|
committer | Pixel <> | 2001-04-13 12:03:09 +0000 |
commit | a984cf3f28d3a5935c84f96f6da3bc7bd39a9ff1 (patch) | |
tree | cf0157e6e7f9df0f6025b1191d5f6be17b9b057d /lib/exceptions.c | |
parent | 905814760584d843409763d9f3c24b73b0780444 (diff) |
Assembleur.
Diffstat (limited to 'lib/exceptions.c')
-rw-r--r-- | lib/exceptions.c | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/lib/exceptions.c b/lib/exceptions.c index 231ca63..0bacb32 100644 --- a/lib/exceptions.c +++ b/lib/exceptions.c @@ -4,42 +4,61 @@ #include "config.h" #include "exceptions.h" -char * contexts[128]; +char *contexts[128]; int clevel = 0; -char * Estrdup(char * o) { - char * r; - - if (!(r = strdup(o))) { - exception(1, _("Out of memory.")); - } - return r; +/********************************\ +* * +* Gestionnaire d'exceptions * +* * +\********************************/ + +char *Estrdup(char *o) +{ + char *r; + + if (o) { + if (!(r = strdup(o))) { + exception(1, _("Out of memory.")); + } + } else { + return NULL; + } + return r; } -void * Emalloc(size_t s) { - void * r; - - if (!(r = malloc(s))) { - exception(1, _("Out of memory.")); - } - return r; +void *Emalloc(size_t s) +{ + void *r; + + if (s) { + if (!(r = malloc(s))) { + exception(1, _("Out of memory.")); + } + } else { + return NULL; + } + return r; } -void pushcontext(char * c) { +void pushcontext(char *c) +{ if (clevel == 128) { exception(1, _("Too much error contexts during pushcontext().")); } contexts[clevel++] = Estrdup(c); } -void popcontext(void) { +void popcontext(void) +{ if (clevel == 0) { exception(1, _("Error context empty, but popcontext() called.")); } free(contexts[--clevel]); } -void flushcontext(void) { +void flushcontext(void) +{ while (clevel) { popcontext(); } @@ -48,11 +67,11 @@ void flushcontext(void) { 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); + fprintf(stderr, " Error description: %s\n", msg); + exit(level); } |