summaryrefslogtreecommitdiff
path: root/lib/exceptions.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/exceptions.c')
-rw-r--r--lib/exceptions.c115
1 files changed, 61 insertions, 54 deletions
diff --git a/lib/exceptions.c b/lib/exceptions.c
index b19df9b..b4a08a4 100644
--- a/lib/exceptions.c
+++ b/lib/exceptions.c
@@ -20,88 +20,95 @@ char *contexts[128];
int clevel = 0;
int global_error = 0;
-/* Les fonctions strdup et malloc sont réécrites ici afin de simplifier la vie en cas d'erreur. */
+/*
+ * Les fonctions strdup et malloc sont reecrites ici afin de simplifier la vie en cas d'erreur.
+ */
char *Estrdup(char *o)
{
- char *r;
+ char *r;
- if (o) {
- if (!(r = strdup(o))) {
- exception(2, _("Out of memory."));
- }
- } else {
- return NULL;
+ if (o) {
+ if (!(r = strdup(o))) {
+ exception(2, _("Out of memory."));
}
- return r;
+ } else {
+ return NULL;
+ }
+ return r;
}
void *Emalloc(size_t s)
{
- void *r;
+ void *r;
- if (s) {
- if (!(r = malloc(s))) {
- exception(2, _("Out of memory."));
- }
- } else {
- return NULL;
+ if (s) {
+ if (!(r = malloc(s))) {
+ exception(2, _("Out of memory."));
}
- return r;
+ } else {
+ return NULL;
+ }
+ return r;
}
-/* Les routines de manipulation de la pile de contexte d'erreurs */
+/*
+ * Les routines de manipulation de la pile de contexte d'erreurs
+ */
void pushcontext(char *c)
{
- if (clevel == 128) {
- exception(2, _("Too much error contexts during pushcontext()."));
- }
- contexts[clevel++] = Estrdup(c);
+ if (clevel == 128) {
+ exception(2, _("Too much error contexts during pushcontext()."));
+ }
+ contexts[clevel++] = Estrdup(c);
#ifdef DEBUG
- fprintf(stderr, "%s\n", c);
+ fprintf(stderr, "%s\n", c);
#endif
}
void popcontext(void)
{
- if (clevel == 0) {
- exception(2, _("Error context empty, but popcontext() called."));
- }
- free(contexts[--clevel]);
+ if (clevel == 0) {
+ exception(2, _("Error context empty, but popcontext() called."));
+ }
+ free(contexts[--clevel]);
}
void flushcontext(void)
{
- while (clevel) {
- popcontext();
- }
+ while (clevel) {
+ popcontext();
+ }
}
-/* 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 */
+/*
+ * 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)
+void exception(int level, char *msg)
{
- int i;
- switch (level) {
- case 1:
- fprintf(stderr, _("Non-fatal 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);
- flush_pile();
- global_error = 1;
- break;
- default:
- fprintf(stderr, _("Fatal 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);
- clearterm();
- exit(1);
- break;
- }
+ int i;
+
+ switch (level) {
+ case 1:
+ fprintf(stderr, _("Non-fatal 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);
+ flush_pile();
+ global_error = 1;
+ break;
+ default:
+ fprintf(stderr, _("Fatal 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);
+ clearterm();
+ exit(1);
+ break;
+ }
}