00001
00020 #include "mfcpch.h"
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <stdarg.h>
00024 #include <string.h>
00025 #ifdef __UNIX__
00026 #include <signal.h>
00027 #endif
00028 #include "tprintf.h"
00029
00030 #include "errcode.h"
00031
00032 const ERRCODE BADERRACTION = "Illegal error action";
00033 #define MAX_MSG 1024
00034 extern INT16 global_abort_code;
00035
00041 void
00042 ERRCODE::error (
00043 const char *caller,
00044 INT8 action,
00045 const char *format, ...
00046 ) const
00047 {
00048 va_list args;
00049 char msg[MAX_MSG];
00050 char *msgptr = msg;
00051
00052 if (caller != NULL)
00053
00054 msgptr += sprintf (msgptr, "%s:", caller);
00055
00056 msgptr += sprintf (msgptr, "Error:%s", message);
00057 if (format != NULL) {
00058 msgptr += sprintf (msgptr, ":");
00059 va_start(args, format);
00060 #ifdef __MSW32__
00061
00062 msgptr += _vsnprintf (msgptr, MAX_MSG - 2 - (msgptr - msg), format, args);
00063 msg[MAX_MSG - 2] = '\0';
00064 strcat (msg, "\n");
00065 #else
00066
00067 msgptr += vsprintf (msgptr, format, args);
00068
00069 msgptr += sprintf (msgptr, "\n");
00070 #endif
00071 va_end(args);
00072 }
00073 else
00074
00075 msgptr += sprintf (msgptr, "\n");
00076
00077 tprintf(msg);
00078 if ((strstr (message, "File") != NULL) ||
00079 (strstr (message, "file") != NULL))
00080 global_abort_code = FILE_ABORT;
00081 else if ((strstr (message, "List") != NULL) ||
00082 (strstr (message, "list") != NULL))
00083 global_abort_code = LIST_ABORT;
00084 else if ((strstr (message, "Memory") != NULL) ||
00085 (strstr (message, "memory") != NULL))
00086 global_abort_code = MEMORY_ABORT;
00087 else
00088 global_abort_code = NO_ABORT_CODE;
00089
00090 switch (action) {
00091 case DBG:
00092 case LOG:
00093 return;
00094 case EXIT:
00095 err_exit();
00096 case ABORT:
00097 abort();
00098 default:
00099 BADERRACTION.error ("error", ABORT, NULL);
00100 }
00101 }