--- ray/src/common/error.c 1991/11/12 16:56:00 2.1 +++ ray/src/common/error.c 2003/07/17 09:21:29 2.9 @@ -1,61 +1,48 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: error.c,v 2.9 2003/07/17 09:21:29 schorsch Exp $"; #endif - /* * error.c - standard error reporting function + * + * External symbols declared in standard.h */ -#include "standard.h" +#include "copyright.h" -extern char *sys_errlist[]; /* system error list */ -extern int sys_nerr; /* number of system errors */ +#include +#include -char errmsg[128]; /* global error message buffer */ +#include "rterror.h" +extern char *strerror(); + /* global list of error actions */ +struct erract erract[NERRS] = ERRACT_INIT; +char errmsg[512]; /* global error message buffer */ + + +void error(etype, emsg) /* report error, quit if necessary */ int etype; char *emsg; { - switch (etype) { - case WARNING: - wputs("warning - "); - wputs(emsg); - wputs("\n"); + register struct erract *ep; + + if (etype < 0 | etype >= NERRS) return; - case COMMAND: - cputs(emsg); - cputs("\n"); - return; - case USER: - eputs("fatal - "); - eputs(emsg); - eputs("\n"); - quit(1); - case INTERNAL: - eputs("internal - "); - eputs(emsg); - eputs("\n"); - quit(1); - case SYSTEM: - eputs("system - "); - eputs(emsg); - if (errno > 0) { - eputs(": "); - if (errno <= sys_nerr) - eputs(sys_errlist[errno]); - else - eputs("Unknown error"); + ep = erract + etype; + if (ep->pf != NULL) { + if (ep->pre[0]) (*ep->pf)(ep->pre); + if (emsg != NULL && emsg[0]) (*ep->pf)(emsg); + if (etype == SYSTEM && errno > 0) { + (*ep->pf)(": "); + (*ep->pf)(strerror(errno)); } - eputs("\n"); - quit(2); - case CONSISTENCY: - eputs("consistency - "); - eputs(emsg); - eputs("\n"); - abort(); + (*ep->pf)("\n"); } + if (!ep->ec) /* non-fatal */ + return; + if (ep->ec < 0) /* dump core */ + abort(); + quit(ep->ec); /* quit calls exit after cleanup */ }