static char* messFormat(va_list args, const char *format, const char *prefix) { static char *new_buf = NULL; char *buf_ptr; ajint num_bytes; ajint prefix_len; if(format == NULL) ajMessCrash("invalid call, no format string."); if(prefix == NULL) prefix_len = 0; else { prefix_len = strlen(prefix); if((prefix_len + 1) > PREFIXSIZE) ajMessCrash("prefix string is too long."); } /* If they supply the internal buffer as an argument, e.g. because they */ /* used ajFmtString as an arg, then make a copy, otherwise use internal */ /* buffer. */ if(format == messbuf) { if(new_buf != NULL) AJFREE(new_buf); buf_ptr = new_buf = ajSysFuncStrdup(format); } else buf_ptr = messbuf; /* Add the prefix if there is one. */ if(prefix != NULL) { if(!strcpy(buf_ptr, prefix)) ajMessCrash("strcpy failed"); } num_bytes = prefix_len + 1; num_bytes += ajFmtVPrintCL((buf_ptr + prefix_len),BUFSIZE, format, args); /* ** Check the result. This should never happen using the ** ajFmtVPrintCL routine instead of the vsprintf routine */ if(num_bytes < 0) ajMessCrash("vsprintf failed: %s", ajMessGetSysmessageC()); else if(num_bytes > BUFSIZE) ajMessCrash("messubs internal buffer size (%d) exceeded, " "a total of %d bytes were written", BUFSIZE, num_bytes); return(buf_ptr); }
/* @func ajCall *************************************************************** ** ** Call a function by its name. If it does not exist then give ** an error message saying so. ** ** @param [r] name [const char*] name of the function to call. ** @param [v] [...] Optional arguments ** @return [void*] NULL if function call not found. ** @@ ******************************************************************************/ void* ajCall(const char *name, ...) { va_list args; CallFunc rec; CallFunc recold; void *retval = NULL; ajuint *icount; if(!callTable) { ajMessCrash("Calls to %s not registered. For graphics devices use " "ajGraphInit in main function first",name); return retval; } rec = (CallFunc) ajTableFetch(callTable, name); recold = (CallFunc) ajTableFetch(oldcallTable, name); if(rec) { va_start(args, name); retval = (*(rec))(name, args); va_end(args); } else if(recold) { icount = (ajuint*) ajTableFetch(oldcallCount, name); if(!(*icount)++) ajWarn("Obsolete graphics call '%s' called via ajCall", name); va_start(args, name); retval = (*(recold))(name, args); va_end(args); } else { ajMessCrash("Graphics call %s not found. " "Use ajGraphInit in main function first",name); } return retval; }
/* @func ajCallTableGetC ****************************************************** ** ** Returns a named function by its name. If it does not exist then give ** an error message saying so. ** ** @param [r] table [const AjPTable] Function hash table ** @param [r] name [const char*] name of the function ** @return [void*] NULL if function call not found. ** @@ ******************************************************************************/ void* ajCallTableGetC(const AjPTable table, const char *name) { void *rec; if(!table) { ajMessCrash("ajCallTableGet no call table for '%S'", name); return NULL; } rec = ajTableFetch(table, name); if(!rec) return NULL; return rec; }
__noreturn void ajMessCrashFL(const char *format, ...) { enum {MAXERRORS = 1}; static ajint internalErrors = 0; static char prefix[1024]; ajint rc; const char *mesg_buf = NULL; va_list args; if(internalErrors > MAXERRORS) abort(); else internalErrors++; /* Construct the message prefix, adding the program name if possible. */ if(messGetErrorProgram() == NULL) rc = sprintf(prefix, CRASH_PREFIX_FORMAT, MESG_TITLE, messGetErrorFile(), messGetErrorLine()); else rc = sprintf(prefix, FULL_CRASH_PREFIX_FORMAT, MESG_TITLE, messGetErrorProgram(), messGetErrorFile(), messGetErrorLine()); if(rc < 0) ajMessCrash("sprintf failed"); if(AjErrorLevel.fatal) { AJAXFORMATSTRING(args, format, mesg_buf, prefix); messDump(mesg_buf); if(crashRoutine) (*crashRoutine)(mesg_buf); else fprintf(stderr, "%s\n", mesg_buf); ajMessInvokeDebugger(); } exit(EXIT_FAILURE); }
void ajVDie(const char *format, va_list args) { const char *prefix = DIE_PREFIX; const char *mesg_buf = NULL; ++errorCount; AJAXVFORMATSTRING(args, format, mesg_buf, prefix); messDump(mesg_buf); if(errorRoutine) (*errorRoutine)(mesg_buf); else ajMessCrash(mesg_buf); ajMessInvokeDebugger(); return; }