Tesseract
3.02
|
00001 /********************************************************************** 00002 * File: tprintf.c 00003 * Description: Trace version of printf - portable between UX and NT 00004 * Author: Phil Cheatle 00005 * Created: Wed Jun 28 15:01:15 BST 1995 00006 * 00007 * (C) Copyright 1995, 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" //precompiled headers 00021 00022 // Include automatically generated configuration file if running autoconf. 00023 #ifdef HAVE_CONFIG_H 00024 #include "config_auto.h" 00025 #endif 00026 00027 #include <stdio.h> 00028 #include <stdarg.h> 00029 #include "strngs.h" 00030 #include "params.h" 00031 #include "tprintf.h" 00032 #include "ccutil.h" 00033 00034 #define MAX_MSG_LEN 65536 00035 00036 #define EXTERN 00037 // Since tprintf is protected by a mutex, these parameters can rmain global. 00038 DLLSYM STRING_VAR(debug_file, "", "File to send tprintf output to"); 00039 00040 DLLSYM void 00041 tprintf ( //Trace printf 00042 const char *format, ... //special message 00043 ) { 00044 tesseract::tprintfMutex.Lock(); 00045 va_list args; //variable args 00046 static FILE *debugfp = NULL; //debug file 00047 //debug window 00048 inT32 offset = 0; //into message 00049 static char msg[MAX_MSG_LEN + 1]; 00050 00051 va_start(args, format); //variable list 00052 #ifdef _WIN32 00053 //Format into msg 00054 offset += _vsnprintf (msg + offset, MAX_MSG_LEN - offset, format, args); 00055 if (strcmp(debug_file.string(), "/dev/null") == 0) 00056 debug_file.set_value("nul"); 00057 #else 00058 //Format into msg 00059 offset += vsprintf (msg + offset, format, args); 00060 #endif 00061 va_end(args); 00062 00063 if (debugfp == NULL && strlen (debug_file.string ()) > 0) { 00064 debugfp = fopen (debug_file.string (), "wb"); 00065 } else if (debugfp != NULL && strlen (debug_file.string ()) == 0) { 00066 fclose(debugfp); 00067 debugfp = NULL; 00068 } 00069 if (debugfp != NULL) 00070 fprintf(debugfp, "%s", msg); 00071 else 00072 fprintf(stderr, "%s", msg); 00073 tesseract::tprintfMutex.Unlock(); 00074 } 00075 00076 00077 /************************************************************************* 00078 * pause_continue() 00079 * UI for a debugging pause - to see an intermediate state 00080 * Returns TRUE to continue as normal to the next pause in the current mode; 00081 * FALSE to quit the current pausing mode. 00082 *************************************************************************/ 00083 00084 DLLSYM BOOL8 00085 //special message 00086 pause_continue (const char *format, ... 00087 ) { 00088 va_list args; //variable args 00089 char msg[1000]; 00090 STRING str = STRING ("DEBUG PAUSE:\n"); 00091 00092 va_start(args, format); //variable list 00093 vsprintf(msg, format, args); //Format into msg 00094 va_end(args); 00095 00096 #ifdef GRAPHICS_DISABLED 00097 // No interaction allowed -> simply go on 00098 return true; 00099 #else 00100 00101 #ifdef __UNIX__ 00102 printf ("%s\n", msg); 00103 printf ("Type \"c\" to cancel, anything else to continue: "); 00104 char c = getchar (); 00105 return (c != 'c'); 00106 #endif 00107 00108 #ifdef _WIN32 00109 str += 00110 STRING (msg) + STRING ("\nUse OK to continue, CANCEL to stop pausing"); 00111 // return AfxMessageBox( str.string(), MB_OKCANCEL ) == IDOK; 00112 return::MessageBox (NULL, msg, "IMGAPP", 00113 MB_APPLMODAL | MB_OKCANCEL) == IDOK; 00114 #endif 00115 00116 #endif 00117 }