Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tprintf.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 * File: tprintf.c
3 * Description: Trace version of printf - portable between UX and NT
4 * Author: Phil Cheatle
5 * Created: Wed Jun 28 15:01:15 BST 1995
6 *
7 * (C) Copyright 1995, Hewlett-Packard Ltd.
8 ** Licensed under the Apache License, Version 2.0 (the "License");
9 ** you may not use this file except in compliance with the License.
10 ** You may obtain a copy of the License at
11 ** http://www.apache.org/licenses/LICENSE-2.0
12 ** Unless required by applicable law or agreed to in writing, software
13 ** distributed under the License is distributed on an "AS IS" BASIS,
14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ** See the License for the specific language governing permissions and
16 ** limitations under the License.
17 *
18 **********************************************************************/
19
20 #include "mfcpch.h" //precompiled headers
21
22 // Include automatically generated configuration file if running autoconf.
23 #ifdef HAVE_CONFIG_H
24 #include "config_auto.h"
25 #endif
26
27 #include <stdio.h>
28 #include <stdarg.h>
29 #include "strngs.h"
30 #include "params.h"
31 #include "tprintf.h"
32 #include "ccutil.h"
33
34 #define MAX_MSG_LEN 65536
35
36 #define EXTERN
37 // Since tprintf is protected by a mutex, these parameters can rmain global.
38 DLLSYM STRING_VAR(debug_file, "", "File to send tprintf output to");
39
40 DLLSYM void
41 tprintf( // Trace printf
42 const char *format, ... // special message
43 ) {
44 tesseract::tprintfMutex.Lock();
45 va_list args; //variable args
46 static FILE *debugfp = NULL; //debug file
47 //debug window
48 inT32 offset = 0; //into message
49 static char msg[MAX_MSG_LEN + 1];
50
51 va_start(args, format); //variable list
52 #ifdef _WIN32
53 //Format into msg
54 offset += _vsnprintf (msg + offset, MAX_MSG_LEN - offset, format, args);
55 if (strcmp(debug_file.string(), "/dev/null") == 0)
56 debug_file.set_value("nul");
57 #else
58 //Format into msg
59 offset += vsprintf (msg + offset, format, args);
60 #endif
61 va_end(args);
62
63 if (debugfp == NULL && strlen (debug_file.string ()) > 0) {
64 debugfp = fopen (debug_file.string (), "wb");
65 } else if (debugfp != NULL && strlen (debug_file.string ()) == 0) {
66 fclose(debugfp);
67 debugfp = NULL;
68 }
69 if (debugfp != NULL)
70 fprintf(debugfp, "%s", msg);
71 else
72 fprintf(stderr, "%s", msg);
73 tesseract::tprintfMutex.Unlock();
74 }
75
76
77 /*************************************************************************
78 * pause_continue()
79 * UI for a debugging pause - to see an intermediate state
80 * Returns TRUE to continue as normal to the next pause in the current mode;
81 * FALSE to quit the current pausing mode.
82 *************************************************************************/
83
84 DLLSYM BOOL8
85 //special message
86 pause_continue (const char *format, ...
87 ) {
88 va_list args; //variable args
89 char msg[1000];
90 STRING str = STRING ("DEBUG PAUSE:\n");
91
92 va_start(args, format); //variable list
93 vsprintf(msg, format, args); //Format into msg
94 va_end(args);
95
96 #ifdef GRAPHICS_DISABLED
97 // No interaction allowed -> simply go on
98 return true;
99 #else
100
101 #ifdef __UNIX__
102 printf ("%s\n", msg);
103 printf ("Type \"c\" to cancel, anything else to continue: ");
104 char c = getchar ();
105 return (c != 'c');
106 #endif
107
108 #ifdef _WIN32
109 str +=
110 STRING (msg) + STRING ("\nUse OK to continue, CANCEL to stop pausing");
111 // return AfxMessageBox( str.string(), MB_OKCANCEL ) == IDOK;
112 return::MessageBox (NULL, msg, "IMGAPP",
113 MB_APPLMODAL | MB_OKCANCEL) == IDOK;
114 #endif
115
116 #endif
117 }