00001
00019 #include "mfcpch.h"
00020 #include <stdio.h>
00021 #include <stdarg.h>
00022 #include "strngs.h"
00023 #include "varable.h"
00024 #include "debugwin.h"
00025
00026 #include "tprintf.h"
00027
00028 #define MAX_MSG_LEN 1024
00029
00030 #define EXTERN
00031
00034 #ifdef __MSW32__
00035 DLLSYM STRING_VAR (debug_file, "tesseract.log", "File to send tprintf output to");
00036 #else
00037 DLLSYM STRING_VAR (debug_file, "", "File to send tprintf output to");
00038 #endif
00039 DLLSYM BOOL_VAR (debug_window_on, FALSE,
00040 "Send tprintf to window unless file set");
00046 DLLSYM void
00047 tprintf (
00048 const char *format, ...
00049 ) {
00050 va_list args;
00051 static FILE *debugfp = NULL;
00052
00053 static DEBUG_WIN *debugwin = NULL;
00054 INT32 offset = 0;
00055 static char msg[MAX_MSG_LEN + 1];
00056
00057 va_start(args, format);
00058 #ifdef __MSW32__
00059
00060 offset += _vsnprintf (msg + offset, MAX_MSG_LEN - offset, format, args);
00061 #else
00062
00063 offset += vsprintf (msg + offset, format, args);
00064 #endif
00065 va_end(args);
00066
00067 if (debugfp == NULL && strlen (debug_file.string ()) > 0)
00068 debugfp = fopen (debug_file.string (), "w");
00069 else if (debugfp != NULL && strlen (debug_file.string ()) == 0) {
00070 fclose(debugfp);
00071 debugfp = NULL;
00072 }
00073 if (debugfp != NULL)
00074 fprintf (debugfp, "%s", msg);
00075 else {
00076
00077 if (debug_window_on) {
00078 if (debugwin == NULL)
00079
00080 debugwin = new DEBUG_WIN ("Debug Window", DEBUG_WIN_XPOS, DEBUG_WIN_YPOS,
00081
00082 DEBUG_WIN_XSIZE, DEBUG_WIN_YSIZE,
00083 debug_lines);
00084 debugwin->dprintf (msg);
00085 }
00086 else {
00087 #ifdef __UNIX__
00088
00089 fprintf (stderr, "%s", msg);
00090 #endif
00091
00092 #ifdef __MSW32__
00093 TRACE ("%s", msg);
00094 #endif
00095 #ifdef __MAC__
00096 printf ("%s", msg);
00097 #endif
00098 }
00099 }
00100 }
00101
00102
00111 DLLSYM BOOL8
00112 pause_continue (const char *format, ...
00113 ) {
00114 va_list args;
00115 char msg[1000];
00116 STRING str = STRING ("DEBUG PAUSE:\n");
00117
00118 va_start(args, format);
00119 vsprintf(msg, format, args);
00120 va_end(args);
00121
00122 #ifdef GRAPHICS_DISABLED
00123
00124 return true;
00125 #else // GRAPHICS_DISABLED
00126
00127 #ifdef __UNIX__
00128 printf ("%s\n", msg);
00129 printf ("Type \"c\" to cancel, anything else to continue: ");
00130 char c = getchar ();
00131 return (c != 'c');
00132 #endif
00133
00134 #ifdef __MSW32__
00135 str +=
00136 STRING (msg) + STRING ("\nUse OK to continue, CANCEL to stop pausing");
00137
00138 return::MessageBox (NULL, msg, "IMGAPP",
00139 MB_APPLMODAL | MB_OKCANCEL) == IDOK;
00140 #endif
00141
00142 #endif // GRAPHICS_DISABLED
00143 }