cutil/danerror.cpp

Go to the documentation of this file.
00001 
00020 /* =================
00021           Include Files and Type Defines
00022  ==================== */
00023 #include "general.h"
00024 #include "danerror.h"
00025 #include "callcpp.h"
00026 #include "globaloc.h"
00027 #ifdef __UNIX__
00028 #include "assert.h"
00029 #endif
00030 
00031 #include <stdio.h>
00032 #include <setjmp.h>
00033 
00034 #define MAXTRAPDEPTH    100
00035 
00036 #define ERRORTRAPDEPTH    1000
00037 
00038 /* =================
00039  Global Data Definitions and Declarations
00040  ==================== */
00041 static jmp_buf ErrorTrapStack[MAXTRAPDEPTH];
00042 static VOID_PROC ProcTrapStack[MAXTRAPDEPTH];
00043 static INT32 CurrentTrapDepth = 0;
00044 
00045 /* =================
00046               Public Code
00047  ==================== */
00048 /* =============================== */
00060 void ReleaseErrorTrap() { 
00061   if (CurrentTrapDepth > 0) {
00062     CurrentTrapDepth--;
00063   }
00064 }                                /* ReleaseErrorTrap */
00065 
00066 
00067 /* =============================== */
00084 void DoError(int Error, const char *Message) { 
00085   if (Message != NULL) {
00086     cprintf ("\nError: %s!\n", Message);
00087   }
00088 
00089   if (CurrentTrapDepth <= 0) {
00090     cprintf ("\nFatal error: No error trap defined!\n");
00091 
00092     /* SPC 20/4/94
00093        There used to be a call to abort() here. I've changed it to call into the
00094        C++ error code to generate a meaningful status code
00095      */
00096     signal_termination_handler(Error); 
00097   }
00098 
00099   if (ProcTrapStack[CurrentTrapDepth - 1] != DO_NOTHING)
00100     (*ProcTrapStack[CurrentTrapDepth - 1]) ();
00101 
00102   longjmp (ErrorTrapStack[CurrentTrapDepth - 1], 1);
00103   assert(FALSE); 
00104 }                                /* DoError */
00105 
00106 
00107 /* =================
00108      Private Code
00109  ==================== */
00110 /* =============================== */
00129 jmp_buf &PushErrorTrap(VOID_PROC Procedure) { 
00130   if (CurrentTrapDepth >= MAXTRAPDEPTH)
00131     DoError (ERRORTRAPDEPTH, "Error trap depth exceeded");
00132   ProcTrapStack[CurrentTrapDepth] = Procedure;
00133   return ErrorTrapStack[CurrentTrapDepth++];
00134 
00135 }                                /* PushErrorTrap */

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