Tesseract
3.02
|
00001 /********************************************************************** 00002 * File: errcode.c (Formerly error.c) 00003 * Description: Generic error handler function 00004 * Author: Ray Smith 00005 * Created: Tue May 1 16:28:39 BST 1990 00006 * 00007 * (C) Copyright 1989, Hewlett-Packard Ltd. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 * 00018 **********************************************************************/ 00019 00020 #include "mfcpch.h" 00021 #include <signal.h> 00022 #include "errcode.h" 00023 #include "tprintf.h" 00024 00025 /*inT16 global_loc_code = LOC_INIT;//location code 00026 inT16 global_subloc_code = SUBLOC_NORM; 00027 //pass2 subloc code 00028 inT16 global_subsubloc_code = SUBSUBLOC_OTHER; 00029 //location code 00030 inT16 global_abort_code = NO_ABORT_CODE; 00031 //Prog abort code 00032 */ 00033 void signal_exit( // 00034 int signal_code //Signal which 00035 ) { 00036 /*int exit_status; 00037 00038 if ((global_loc_code == LOC_PASS2) || (global_loc_code == LOC_FUZZY_SPACE)) 00039 global_loc_code += global_subloc_code + global_subsubloc_code; 00040 00041 if (signal_code < 0) { 00042 exit_status = global_loc_code * 8 + global_abort_code * 2 + 1; 00043 tprintf ("Signal_exit %d ABORT. LocCode: %d AbortCode: %d\n", 00044 exit_status, global_loc_code, global_abort_code); 00045 } 00046 else { 00047 exit_status = global_loc_code * 8 + signal_code * 2; 00048 tprintf ("Signal_exit %d SIGNAL ABORT. LocCode: %d SignalCode: %d\n", 00049 exit_status, global_loc_code, signal_code); 00050 } 00051 00052 exit(exit_status);*/ 00053 exit(signal_code); 00054 } 00055 00056 00057 /************************************************************************* 00058 * err_exit() 00059 * All program exits should go through this point. It allows a meaningful status 00060 * code to be generated for the real exit() call. The status code is made up 00061 * as follows: 00062 * Bit 0 : 1 = Program Abort 0 = System Abort 00063 * Bits 1,2 : IF bit 0 = 1 THEN ERRCODE::abort_code 00064 * ELSE 0 = Bus Err or Seg Vi 00065 * 1 = Floating point exception 00066 * 2 = TimeOut (Signal 15 from command timer) 00067 * 3 = Any other signal 00068 * Bits 3..7 : Location code NEVER 0 ! 00069 *************************************************************************/ 00070 00071 //extern "C" { 00072 00073 void err_exit() { 00074 signal_exit (-1); 00075 } 00076 00077 00078 void signal_termination_handler(int sig) { 00079 const ERRCODE SIGNAL_HANDLER_ERR = "Signal_termination_handler called"; 00080 SIGNAL_HANDLER_ERR.error("signal_termination_handler", ABORT, "Code %d", sig); 00081 switch (sig) { 00082 case SIGABRT: 00083 signal_exit (-1); //use abort code 00084 // case SIGBUS: 00085 case SIGSEGV: 00086 signal_exit (0); 00087 case SIGFPE: 00088 signal_exit (1); //floating point 00089 case SIGTERM: 00090 signal_exit (2); //timeout by cmdtimer 00091 default: 00092 signal_exit (3); //Anything else 00093 } 00094 } 00095 00096 00097 //}; //end extern "C" 00098 00099 00100 void set_global_loc_code(int loc_code) { 00101 // global_loc_code = loc_code; 00102 00103 } 00104 00105 00106 void set_global_subloc_code(int loc_code) { 00107 // global_subloc_code = loc_code; 00108 00109 } 00110 00111 00112 void set_global_subsubloc_code(int loc_code) { 00113 // global_subsubloc_code = loc_code; 00114 00115 }