Back to index

radiance  4R0+20100331
error.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: error.c,v 2.10 2003/07/27 22:12:01 schorsch Exp $";
00003 #endif
00004 /*
00005  *  error.c - standard error reporting function
00006  *
00007  *  External symbols declared in standard.h
00008  */
00009 
00010 #include "copyright.h"
00011 
00012 #include  <stdio.h>
00013 #include  <stdlib.h>
00014 
00015 #include  "rterror.h"
00016 
00017 extern char   *strerror();
00018                             /* global list of error actions */
00019 struct erract erract[NERRS] = ERRACT_INIT;
00020 
00021 char  errmsg[512];          /* global error message buffer */
00022 
00023 
00024 void
00025 error(etype, emsg)          /* report error, quit if necessary */
00026 int  etype;
00027 char  *emsg;
00028 {
00029        register struct erract      *ep;
00030 
00031        if ((etype < 0) | (etype >= NERRS))
00032               return;
00033        ep = erract + etype;
00034        if (ep->pf != NULL) {
00035               if (ep->pre[0]) (*ep->pf)(ep->pre);
00036               if (emsg != NULL && emsg[0]) (*ep->pf)(emsg);
00037               if (etype == SYSTEM && errno > 0) {
00038                      (*ep->pf)(": ");
00039                      (*ep->pf)(strerror(errno));
00040               }
00041               (*ep->pf)("\n");
00042        }
00043        if (!ep->ec)         /* non-fatal */
00044               return;
00045        if (ep->ec < 0)             /* dump core */
00046               abort();
00047        quit(ep->ec);        /* quit calls exit after cleanup */
00048 }