ccutil/errcode.cpp

Go to the documentation of this file.
00001 
00020 #include          "mfcpch.h"     //precompiled headers
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 //#include                                      "ipeerr.h"
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 (                 //handle error
00043 const char *caller,              //name of caller
00044 INT8 action,                     //action to take
00045 const char *format, ...          //special message
00046 ) const
00047 {
00048   va_list args;                  //variable args
00049   char msg[MAX_MSG];
00050   char *msgptr = msg;
00051 
00052   if (caller != NULL)
00053                                  //name of caller
00054     msgptr += sprintf (msgptr, "%s:", caller);
00055                                  //actual message
00056   msgptr += sprintf (msgptr, "Error:%s", message);
00057   if (format != NULL) {
00058     msgptr += sprintf (msgptr, ":");
00059     va_start(args, format);  //variable list
00060     #ifdef __MSW32__
00061                                  //print remainder
00062     msgptr += _vsnprintf (msgptr, MAX_MSG - 2 - (msgptr - msg), format, args);
00063     msg[MAX_MSG - 2] = '\0';     //ensure termination
00064     strcat (msg, "\n");
00065     #else
00066                                  //print remainder
00067     msgptr += vsprintf (msgptr, format, args);
00068                                  //no specific
00069     msgptr += sprintf (msgptr, "\n");
00070     #endif
00071     va_end(args); 
00072   }
00073   else
00074                                  //no specific
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;                    //report only
00094     case EXIT:
00095       err_exit(); 
00096     case ABORT:
00097       abort(); 
00098     default:
00099       BADERRACTION.error ("error", ABORT, NULL);
00100   }
00101 }

Generated on Wed Feb 28 19:49:09 2007 for Tesseract by  doxygen 1.5.1