ccutil/tprintf.cpp

Go to the documentation of this file.
00001 
00019 #include          "mfcpch.h"     //precompiled headers
00020 #include          <stdio.h>
00021 #include          <stdarg.h>
00022 #include          "strngs.h"
00023 #include          "varable.h"
00024 #include              "debugwin.h"
00025 //#include                                      "ipeerr.h"
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 (                        //Trace printf
00048 const char *format, ...          //special message
00049 ) {
00050   va_list args;                  //variable args
00051   static FILE *debugfp = NULL;   //debug file
00052                                  //debug window
00053   static DEBUG_WIN *debugwin = NULL;
00054   INT32 offset = 0;              //into message
00055   static char msg[MAX_MSG_LEN + 1];
00056 
00057   va_start(args, format);  //variable list
00058   #ifdef __MSW32__
00059                                  //Format into msg
00060   offset += _vsnprintf (msg + offset, MAX_MSG_LEN - offset, format, args);
00061   #else
00062                                  //Format into msg
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                                  //in pixels
00080         debugwin = new DEBUG_WIN ("Debug Window", DEBUG_WIN_XPOS, DEBUG_WIN_YPOS,
00081                                  //in pixels
00082           DEBUG_WIN_XSIZE, DEBUG_WIN_YSIZE,
00083           debug_lines);
00084       debugwin->dprintf (msg);
00085     }
00086     else {
00087       #ifdef __UNIX__
00088                                  // output to stderr - like it used to
00089       fprintf (stderr, "%s", msg);
00090       #endif
00091 
00092       #ifdef __MSW32__
00093       TRACE ("%s", msg);         //Visual C++2.0 macro
00094       #endif
00095       #ifdef __MAC__
00096       printf ("%s", msg);        //Visual C++2.0 macro
00097       #endif
00098     }
00099   }
00100 }
00101 
00102 
00111 DLLSYM BOOL8
00112    pause_continue (const char *format, ...  //special message
00113 ) {
00114   va_list args;                  //variable args
00115   char msg[1000];
00116   STRING str = STRING ("DEBUG PAUSE:\n");
00117 
00118   va_start(args, format);  //variable list
00119   vsprintf(msg, format, args);  //Format into msg
00120   va_end(args);
00121 
00122   #ifdef GRAPHICS_DISABLED
00123   // No interaction allowed -> simply go on
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   //   return AfxMessageBox( str.string(), MB_OKCANCEL ) == IDOK;
00138   return::MessageBox (NULL, msg, "IMGAPP",
00139     MB_APPLMODAL | MB_OKCANCEL) == IDOK;
00140   #endif
00141 
00142   #endif // GRAPHICS_DISABLED
00143 }

Generated on Wed Feb 28 19:49:09 2007 for Tesseract by  doxygen 1.5.1