#ifdef _cplusplus extern "C" { #endif #include "wiseerror.h" static Flag fatal_flag = 3; static Flag warning_flag = 3; static Flag info_flag = 3; static Flag report_flag = 3; #define flag_of_type(c) (c == FATAL ? fatal_flag : c == WARNING ? warning_flag :c == INFO ? info_flag : report_flag ) static int eventc=0; static FILE * errlog=NULL; static void (*error_call)(char *,int)= NULL; static char * error_msg_stack[MAXMSGSTACKERROR]; static char * (*((error_msg_call)[MAXMSGSTACKERROR]))(void); static int msg_stack_no=0; /* Function: push_errormsg_stack(msg,) * * Descrip: This adds a function onto the error message * stack for stacking errors. this is for * decent parsers etc for allowing 'error scope' * to be propagated down. * * It is very very bad form to push an errormsg * stack and not pop it at the end. * * * Arg: msg [UNKN ] Undocumented argument [char *] * Arg: [UNKN ] Undocumented argument [.] * * Return [UNKN ] Undocumented return value [boolean] * */ # line 84 "wiseerror.dy" boolean push_errormsg_stack(char * msg, ...) { char buffer[1024]; va_list ap; va_start(ap,msg); vsprintf(buffer,msg,ap); if( msg_stack_no >= MAXMSGSTACKERROR ) { warn("Too many messages held on stack, [%s] discarded\n",buffer); /*** still should up the number ***/ msg_stack_no++; return FALSE; } error_msg_call[msg_stack_no] = NULL; error_msg_stack[msg_stack_no++] = stringalloc(buffer); return TRUE; } /* Function: push_errormsg_stack_call(ecall) * * Descrip: This adds a function call for people who want * to register error handling functions * * Probably best wrapped by a separate function * * * Arg: ecall [UNKN ] Undocumented argument [NullString] * * Return [UNKN ] Undocumented return value [boolean] * */ # line 113 "wiseerror.dy" boolean push_errormsg_stack_call( char * (*ecall)(void)) { if( msg_stack_no >= MAXMSGSTACKERROR ) { warn("Too many messages held on stack, Error message call discarded\n"); /*** still should up the number ***/ msg_stack_no++; return FALSE; } error_msg_call[msg_stack_no] = ecall; error_msg_stack[msg_stack_no++] = NULL; return TRUE; } /* Function: pop_errormsg_stack(void) * * Descrip: This removes a error message from the stack * * * */ # line 130 "wiseerror.dy" void pop_errormsg_stack(void) { if( msg_stack_no < MAXMSGSTACKERROR && msg_stack_no > 0 && error_msg_stack[msg_stack_no-1] != NULL) ckfree(error_msg_stack[msg_stack_no-1]); if( msg_stack_no > 0) msg_stack_no--; } /* Function: show_message_stack(ofp) * * Descrip: This shows the error message set to * everyone * * * Arg: ofp [UNKN ] Undocumented argument [FILE *] * */ # line 143 "wiseerror.dy" void show_message_stack(FILE * ofp) { register int i; register int j; register int count; for(i=0;i 0 ) show_message_stack(stderr); fputs("\t",stderr); if( type == FATAL ) fputs(othermsg,stderr); else show_text(othermsg,70,stderr); } if( flag&ERRORTOLOG && errlog != NULL) { fputs(type_to_error(type),errlog); fputc('\n',stderr); if( msg_stack_no > 0 ) show_message_stack(errlog); fputs("\n\t",errlog); show_text(othermsg,70,errlog); } if( flag&ERRORTOCALL && error_call != NULL) { (*(error_call))(othermsg,type); } return; } # line 530 "wiseerror.c" #ifdef _cplusplus } #endif