DEBUG_WIN Class Reference

#include <debugwin.h>

List of all members.


Detailed Description

API for the debug window is simple, see below. Most of its behaviour is its UI.

A dprintf to the window causes the text to be sent to the text area. If the stop control is set, then the dprintf blocks (does not display anything or return) until the stop is released.

In multi-threaded apps, other threads and the UI continue to function during the stop. Only the calling thread is blocked. Pressing the clear button erases all text from the window. As text is sent to the window, it scrolls up so that the most recent output is visible. If the user has scrolled back, this does not happen. If the user scrolls back to the bottom, then the scrolling turns back on.

If the user destroys the window, it never comes back.

Definition at line 70 of file debugwin.h.

Public Member Functions

Private Attributes


Constructor & Destructor Documentation

DEBUG_WIN::DEBUG_WIN ( const char *  title,
INT32  xpos = DEBUG_WIN_XPOS,
INT32  ypos = DEBUG_WIN_YPOS,
INT32  xsize = DEBUG_WIN_XSIZE,
INT32  ysize = DEBUG_WIN_YSIZE,
INT32  buflines = debug_lines 
)

Create a debug window with size according to the arguments.

Create an hpterm window with a pipe connected to it.

Definition at line 213 of file debugwin.cpp.

References FALSE, fp, INT32FORMAT, and MAX_PATH.

00220                       {
00221   #ifdef __UNIX__
00222   INT32 length;                  /*length of name */
00223   char command[MAX_PATH];        /*pipe command */
00224   pid_t pid;                     /*process id */
00225   char host[MAX_PATH];           //remote host
00226   BOOL8 remote;                  //remote host
00227 
00228   //      remote=remote_display(host);                                                                    //check remote host
00229   remote = FALSE;
00230   if (remote)
00231                                  //do it remotely
00232     length = sprintf (command, "remsh %s 'DISPLAY=%s;export DISPLAY;",
00233       host, getenv ("DISPLAY"));
00234   else
00235     length = 0;
00236   length += sprintf (command + length, "trap \"\" 1 2 3 13 15\n");
00237   length +=
00238     sprintf (command + length,
00239     "/usr/bin/X11/xterm -sb -sl " INT32FORMAT " -geometry "
00240     INT32FORMAT "x" INT32FORMAT "", buflines, xsize / 8, ysize / 16);
00241   if (xpos >= 0)
00242     command[length++] = '+';
00243   length += sprintf (command + length, INT32FORMAT, xpos);
00244   if (ypos >= 0)
00245     command[length++] = '+';
00246   length +=
00247     sprintf (command + length,
00248     INT32FORMAT " -title \"%s\" -n \"%s\" -e /bin/sh -c ", ypos,
00249     title, title);
00250   pid = getpid ();               /*random number */
00251   length +=
00252     sprintf (command + length,
00253     "\"stty opost; tty >/tmp/debug%d; while [ -s /tmp/debug%d ]\ndo\nsleep 1\ndone\" &\n",
00254     pid, pid);
00255   length +=
00256     sprintf (command + length, "trap \"rm -f /tmp/debug%d; kill -9 $!\" 0\n",
00257     pid);
00258   length += sprintf (command + length, "trap \"exit\" 1 2 3 13 15\n");
00259   length +=
00260     sprintf (command + length,
00261     "while [ ! -s /tmp/debug%d ]\ndo\nsleep 1\ndone\n", pid);
00262   length += sprintf (command + length, "trap \"\" 1 2 3 13 15\n");
00263   length += sprintf (command + length, "ofile=`cat /tmp/debug%d`\n", pid);
00264   length +=
00265     sprintf (command + length, "cat -u - >$ofile; rm /tmp/debug%d\n", pid);
00266   if (remote) {
00267     command[length++] = '\'';    //terminate remsh
00268     command[length] = '\0';
00269   }
00270   fp = popen (command, "w");     /*create window */
00271   if (fp != NULL) {
00272                                  /*set no buffering */
00273     if (setvbuf (fp, NULL, _IONBF, BUFSIZ)) {
00274       pclose(fp); 
00275       fp = NULL;
00276     }
00277   }
00278   #endif
00279 }

DEBUG_WIN::~DEBUG_WIN (  ) 

Close the file and destroy the window.

Definition at line 286 of file debugwin.cpp.

References fp.

00287   {
00288   #ifdef __UNIX__
00289   pclose(fp); 
00290   #endif
00291 }


Member Function Documentation

void DEBUG_WIN::await_destruction (  ) 

Wait for the user to close the debug window. Then return.

Definition at line 322 of file debugwin.cpp.

References fp.

00322                                   {  //wait for user to close
00323   #ifdef __UNIX__
00324   signal(SIGPIPE, SIG_IGN); 
00325   while (!ferror (fp)) {
00326     sleep (1);
00327     fputc (0, fp);               //send nulls until error
00328   }
00329   #endif
00330 }

void DEBUG_WIN::dprintf ( const char *  format,
  ... 
)

Print a message to the debug window.

Like printf, this function can cope with messages which do not end in newline, but nothing is printed until the newline is received.

Definition at line 302 of file debugwin.cpp.

References fp.

Referenced by tprintf().

00304   {
00305   va_list args;                  //variable args
00306 
00307   va_start(args, format);  //variable list
00308   #ifdef __UNIX__
00309   vfprintf(fp, format, args);  //Format into msg
00310   #else
00311                                  //Format into msg
00312   vfprintf(stderr, format, args); 
00313   #endif
00314   va_end(args); 
00315 }


Member Data Documentation

FILE* DEBUG_WIN::fp [private]

Definition at line 107 of file debugwin.h.

Referenced by await_destruction(), DEBUG_WIN(), dprintf(), and ~DEBUG_WIN().


The documentation for this class was generated from the following files:
Generated on Wed Feb 28 19:49:31 2007 for Tesseract by  doxygen 1.5.1