chiark / gitweb /
rationalise debugging output
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Fri, 5 Jun 2009 23:34:04 +0000 (00:34 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Fri, 5 Jun 2009 23:34:04 +0000 (00:34 +0100)
pctb/convert.c
pctb/ocr.c
pctb/ocr.h
pctb/show-thing.tcl

index f90ca4a450456d3b5d437e4a093da3569fa6f975..1d516f9cbfdb5ca5cb9ae2c0babb27d032ed47a5 100644 (file)
@@ -65,6 +65,7 @@ static void require_rectangle_r(Rect rr, const char *ok) {
 }
 
 static void debug_rect(const char *what, int whati, Rect rr) {
+#ifdef DEBUG_RECTANGLES
   int y,r,w;
   fprintf(debug, "%s %d: %d,%d..%d,%d:\n", what, whati,
          rr.tl.x,rr.tl.y, rr.br.x,rr.br.y);
@@ -76,6 +77,7 @@ static void debug_rect(const char *what, int whati, Rect rr) {
     fputc('|',debug);
     fputc('\n',debug);
   }
+#endif
   debug_flush();
 }
 
@@ -136,6 +138,7 @@ static void find_structure(void) {
   down.y++;
   WALK_UNTIL_MUST(down, y,+1, mainr.br.y, '+');
 
+#ifdef DEBUG_RECTANGLES
   int xscaleunit, y,x;
   for (y=0, xscaleunit=1; y<4; y++, xscaleunit*=10) {
     fprintf(debug,"     ");
@@ -145,11 +148,10 @@ static void find_structure(void) {
     }
     fputc('\n',debug);
   }
+#endif
 
   commbasey= up.y;
   comminty= down.y - up.y + 2;
-  fprintf(debug, "up.y=%d down.y=%d commbasey=%d comminty=%d\n",
-         up.y,down.y, commbasey,comminty);
 
   Point across= { mainr.tl.x, commbasey };
   int colno=0;
@@ -159,12 +161,8 @@ static void find_structure(void) {
     eassert(colno < MAX_COLUMNS);
     int colrx= across.x;
     if (colrx > mainr.br.x) colrx= mainr.br.x;
-    if (colno < INTERESTING_COLUMNS) {
+    if (colno < INTERESTING_COLUMNS)
       colrightx[colno]= colrx;
-      fprintf(debug,"colrightx[%d]= %d\n",colno,colrx);
-    } else {
-      fprintf(debug,"extra colr %d  %d\n",colno,colrx);
-    }
       
     colno++;
     
@@ -232,9 +230,11 @@ static void load_image_and_canonify(void) {
          break;
        }
     }
+#ifdef DEBUG_RECTANGLES
     fprintf(debug, "%4d ",y);
     r= fwrite(image + y*width, 1,width, debug);  eassert(r==width);
     fputc('\n',debug);
+#endif
   }
   debug_flush();
 }
index bb9576769e10a1d633ed6ebb7786d75e3bfcf585..7eb871a68844acc1d802747e67346aed760b3729 100644 (file)
@@ -286,6 +286,15 @@ const struct OcrCellTypeInfo ocr_celltype_text= {
   .midword=1 /* Lower only */
 };
 
+static void vdebugf(const char *fmt, va_list al) {
+#ifdef DEBUG_OCR
+  vfprintf(debug,fmt,al);
+#endif
+}
+static void debugf(const char *fmt, ...) {
+  va_list al;  va_start(al,fmt);  vdebugf(fmt,al);  va_end(al);
+}
+
 OcrResultGlyph *ocr(OcrReader *rd, OcrCellType ct, int w, Pixcol cols[]) {
   int nspaces;
   unsigned ctxmap;
@@ -296,9 +305,9 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType ct, int w, Pixcol cols[]) {
   nspaces=- w;
   ctxmap= ct->initial;
   rd->nresults=0;
-  fprintf(debug,"OCR h=%d w=%d",rd->h,w);
-  for (x=0; x<w; x++) fprintf(debug," %"PSPIXCOL(PRIx),cols[x]);
-  fprintf(debug,"\n");
+  debugf("OCR h=%d w=%d",rd->h,w);
+  for (x=0; x<w; x++) debugf(" %"PSPIXCOL(PRIx),cols[x]);
+  debugf("\n");
   debug_flush();
 
   x=0;
@@ -312,7 +321,7 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType ct, int w, Pixcol cols[]) {
       nspaces++;
       x++;
       if (nspaces==SPACE_SPACES) {
-       fprintf(debug,"OCR  x=%x nspaces=%d space\n",x,nspaces);
+       debugf("OCR  x=%x nspaces=%d space\n",x,nspaces);
        ctxmap= ct->nextword;
       }
       continue;
@@ -329,7 +338,7 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType ct, int w, Pixcol cols[]) {
     DatabaseNode *uniquematch= 0;
     int uniquematch_rx=-1;
     
-    fprintf(debug,"OCR  lx=%d ctxmap=%x  ",lx,ctxmap);
+    debugf("OCR  lx=%d ctxmap=%x  ",lx,ctxmap);
 
     for (ctxi=0; ctxi<NCONTEXTS; ctxi++) {
       DatabaseNode *current= &rd->contexts[ctxi];;
@@ -338,29 +347,29 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType ct, int w, Pixcol cols[]) {
 
       x= lx;
       if (!(ctxmap & (1u << ctxi))) continue;
-      fprintf(debug," || %s",context_names[ctxi]);
+      debugf(" || %s",context_names[ctxi]);
 
       for (;;) {
        debug_flush();
-       fprintf(debug," | x=%d",x);
+       debugf(" | x=%d",x);
        if (x>w) break;
        Pixcol cv= cols[x];
-       fprintf(debug," cv=%"PSPIXCOL(PRIx),cv);
+       debugf(" cv=%"PSPIXCOL(PRIx),cv);
        for (i=0; i<current->nlinks; i++)
          if (current->links[i].col == cv)
            goto found;
        /* not found */
-       fprintf(debug," ?");
+       debugf(" ?");
        break;
 
       found:
        current= current->links[i].then;
        if (current->s[0]) {
-         fprintf(debug," \"%s\"",current->s);
+         debugf(" \"%s\"",current->s);
          bestmatch= current;
          bestmatch_rx= x;
        } else {
-         fprintf(debug," ...");
+         debugf(" ...");
        }
 
        x++;
@@ -368,7 +377,7 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType ct, int w, Pixcol cols[]) {
       
       if (bestmatch) {
        if (uniquematch && strcmp(bestmatch->s, uniquematch->s)) {
-         fprintf(debug, " ambiguous");
+         debugf( " ambiguous");
          uniquematch= 0;
          break;
        }
@@ -378,22 +387,22 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType ct, int w, Pixcol cols[]) {
     }
 
     if (uniquematch) {
-      fprintf(debug," || YES\n");
+      debugf(" || YES\n");
       add_result(rd, uniquematch->s, lx, uniquematch_rx, ctxmap);
       x= uniquematch_rx+1;
       ctxmap= ct->midword;
     } else {
       int rx;
-      fprintf(debug," || UNKNOWN");
+      debugf(" || UNKNOWN");
       for (rx=lx; rx<w && cols[rx]; rx++);
-      fprintf(debug," x=%d ctxmap=%x %d..%d\n",x, ctxmap, lx,rx);
+      debugf(" x=%d ctxmap=%x %d..%d\n",x, ctxmap, lx,rx);
       debug_flush();
       callout_unknown(rd, w,cols, lx,rx-1, ctxmap);
       goto restart;
     }
   }
   add_result(rd, 0,-1,-1,0);
-  fprintf(debug,"OCR  finished %d glyphs\n",rd->nresults);
+  debugf("OCR  finished %d glyphs\n",rd->nresults);
   debug_flush();
   return rd->results;
 }
index a03f1f508dfc5e350f589a9a458c8b138a1783e7..b77a56f8905f5269cddedc4d33de783490ece33a 100644 (file)
@@ -10,6 +10,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <stdarg.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 
@@ -41,4 +42,8 @@ void debug_flush(void);
 
 const char *get_vardir(void);
 
+
+/* #define DEBUG_RECTANGLES */
+/* #define DEBUG_OCR */
+
 #endif /*OCR_H*/
index 1af2101f9077d7f24927f1b0ea25ba39312d778d..c04d4ddf21b897e56d323e0c1ac17d40a14f8ea3 100755 (executable)
@@ -26,6 +26,10 @@ set gotsh 20
 set csrh 20
 set ctxh 20
 
+proc debug {m} {
+    puts stderr "SHOW-THING $m"
+}
+
 proc init_widgets {} {
     # idempotent
     global csrh gotsh ctxh
@@ -134,7 +138,7 @@ proc read_xpm {f} {
 
            set realcols $cols
            set cols [expr {$cols - $chop_l - $chop_r}]
-           puts stderr "NOW cols=$cols chop_l,r=$chop_l,$chop_r rows=$rows\
+           debug "NOW cols=$cols chop_l,r=$chop_l,$chop_r rows=$rows\
                 $unk_l $unk_r $ngd"
            
            set mulcols [expr {$cols*$mul+$inter}]
@@ -477,7 +481,7 @@ proc RETURN_RESULT {how what} {
     helptext {{{ Processing }}}
     unbind_all_keys
     update idletasks
-    puts stderr "$how $what"
+    debug "$how $what"
     eval update_database/$how $what
     done/$mainkind
 }
@@ -518,7 +522,7 @@ proc required {} {
     init_widgets
     manyset [lrange $l 0 3] unk_l unk_r unk_contexts
     set glyphsdone [lrange $l 3 end]
-    puts stderr "SHOW-THING GOT $l"
+    debug "GOT $l"
 
     fileevent stdin readable {}