tesseract  3.03
/usr/local/google/home/jbreiden/tesseract-ocr-read-only/ccutil/globaloc.cpp
Go to the documentation of this file.
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          <signal.h>
00021 #ifdef __linux__
00022 #include          <sys/syscall.h>   // For SYS_gettid.
00023 #include          <unistd.h>        // For syscall itself.
00024 #endif
00025 #include          "allheaders.h"
00026 #include          "errcode.h"
00027 #include          "tprintf.h"
00028 
00029 // Size of thread-id array of pixes to keep in case of crash.
00030 const int kMaxNumThreadPixes = 32768;
00031 
00032 Pix* global_crash_pixes[kMaxNumThreadPixes];
00033 
00034 void SavePixForCrash(int resolution, Pix* pix) {
00035 #ifdef __linux__
00036 #ifndef ANDROID
00037   int thread_id = syscall(SYS_gettid) % kMaxNumThreadPixes;
00038 #else
00039   int thread_id = gettid() % kMaxNumThreadPixes;
00040 #endif
00041   pixDestroy(&global_crash_pixes[thread_id]);
00042   if (pix != NULL) {
00043     Pix* clone = pixClone(pix);
00044     pixSetXRes(clone, resolution);
00045     pixSetYRes(clone, resolution);
00046     global_crash_pixes[thread_id] = clone;
00047   }
00048 #endif
00049 }
00050 
00051 // CALL ONLY from a signal handler! Writes a crash image to stderr.
00052 void signal_exit(int signal_code) {
00053   tprintf("Received signal %d!\n", signal_code);
00054 #ifdef __linux__
00055 #ifndef ANDROID
00056   int thread_id = syscall(SYS_gettid) % kMaxNumThreadPixes;
00057 #else
00058   int thread_id = gettid() % kMaxNumThreadPixes;
00059 #endif
00060   if (global_crash_pixes[thread_id] != NULL) {
00061     fprintf(stderr, "Crash caused by image with resolution %d\n",
00062             pixGetYRes(global_crash_pixes[thread_id]));
00063     fprintf(stderr, "<Cut here>\n");
00064     pixWriteStreamPng(stderr, global_crash_pixes[thread_id], 0.0);
00065     fprintf(stderr, "\n<End cut>\n");
00066   }
00067   // Raise an uncaught signal, so as to get a useful stack trace.
00068   raise(SIGILL);
00069 #else
00070   abort();
00071 #endif
00072 }
00073 
00074 void err_exit() {
00075   ASSERT_HOST("Fatal error encountered!" == NULL);
00076 }
00077 
00078 
00079 void set_global_loc_code(int loc_code) {
00080   // global_loc_code = loc_code;
00081 
00082 }
00083 
00084 
00085 void set_global_subloc_code(int loc_code) {
00086   // global_subloc_code = loc_code;
00087 
00088 }
00089 
00090 
00091 void set_global_subsubloc_code(int loc_code) {
00092   // global_subsubloc_code = loc_code;
00093 
00094 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines