| 1 |
/* error.c: this file contains an error function |
| 2 |
*/ |
| 3 |
#include <stdio.h> |
| 4 |
#include <ctype.h> |
| 5 |
#include "sockets.h" |
| 6 |
|
| 7 |
/* ------------------------------------------------------------------------ |
| 8 |
* Definitions: |
| 9 |
*/ |
| 10 |
#define TERMINATE 1 |
| 11 |
|
| 12 |
#ifdef vms |
| 13 |
void exit(int); |
| 14 |
#endif |
| 15 |
#ifdef MACOS_X |
| 16 |
void exit(int); |
| 17 |
#endif |
| 18 |
#ifdef MSDOS |
| 19 |
extern void exit(int); |
| 20 |
#endif |
| 21 |
|
| 22 |
/* ------------------------------------------------------------------------ |
| 23 |
* Global Variables: |
| 24 |
*/ |
| 25 |
#ifdef __PROTOTYPE__ |
| 26 |
void (*error_exit)(int)= exit; /* user may override this */ |
| 27 |
#else |
| 28 |
void (*error_exit)()= exit; /* user may override this */ |
| 29 |
#endif |
| 30 |
|
| 31 |
/* ------------------------------------------------------------------------ |
| 32 |
* Source Code: |
| 33 |
*/ |
| 34 |
|
| 35 |
/*VARARGS*/ |
| 36 |
/* error: print out an error message: |
| 37 |
* error(severity,fmt,...) |
| 38 |
* or error(severity,errfunc,fmt,...) |
| 39 |
* |
| 40 |
* where |
| 41 |
* |
| 42 |
* severity: severity of error |
| 43 |
* XTDIO_SEVERE : severe error - will terminate |
| 44 |
* XTDIO_ERROR : error - will terminate |
| 45 |
* XTDIO_WARNING : warning message |
| 46 |
* XTDIO_NOTE : notification |
| 47 |
* |
| 48 |
* fmt : printf format specification |
| 49 |
* ... : arguments for the fmt |
| 50 |
* |
| 51 |
* errfunc: |
| 52 |
* will be called |
| 53 |
*/ |
| 54 |
#ifdef __PROTOTYPE__ |
| 55 |
void error( |
| 56 |
int severity, |
| 57 |
char *fmt, |
| 58 |
...) |
| 59 |
#else /* __PROTOTYPE__ */ |
| 60 |
void error(severity,fmt,va_alist) |
| 61 |
int severity; |
| 62 |
char *fmt; |
| 63 |
va_dcl |
| 64 |
#endif /* __PROTOTYPE__ */ |
| 65 |
{ |
| 66 |
va_list args; |
| 67 |
static struct mesgstr { |
| 68 |
char *bgn_color; |
| 69 |
char *message; |
| 70 |
char *end_color; |
| 71 |
int flags; |
| 72 |
} mesg[]={ |
| 73 |
{XRED, "fatal error",XGREEN,TERMINATE}, /* SEVERE */ |
| 74 |
{XRED, "error", XGREEN,TERMINATE}, /* ERROR */ |
| 75 |
{XYELLOW, "warning", XGREEN,0}, /* WARNING */ |
| 76 |
{XCYAN, "note", XGREEN,0} /* NOTE */ |
| 77 |
}; |
| 78 |
static int nmesg= sizeof(mesg)/sizeof(struct mesgstr); |
| 79 |
|
| 80 |
/* severity sanity checks */ |
| 81 |
if(severity < 0) severity= 0; |
| 82 |
if(severity >= nmesg) severity= XTDIO_SEVERE; |
| 83 |
|
| 84 |
rdcputs(mesg[severity].bgn_color,stderr); |
| 85 |
fprintf(stderr,"***%s*** ",mesg[severity].message); |
| 86 |
rdcputs(mesg[severity].end_color,stderr); |
| 87 |
|
| 88 |
/* initialize for variable arglist handling */ |
| 89 |
#ifdef __PROTOTYPE__ |
| 90 |
va_start(args,fmt); |
| 91 |
vfprintf(stderr,fmt,args); |
| 92 |
va_end(args); |
| 93 |
#else |
| 94 |
va_start(args); |
| 95 |
vfprintf(stderr,fmt,args); |
| 96 |
va_end(args); |
| 97 |
#endif |
| 98 |
|
| 99 |
/* terminate */ |
| 100 |
if(mesg[severity].flags & TERMINATE) (*error_exit)(1); |
| 101 |
} |
| 102 |
|
| 103 |
/* ------------------------------------------------------------------------ */ |
| 104 |
|