From d3eaa28d304c5b0639bc0f7e29b3285317d5c1e7 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 6 Jun 2009 00:34:04 +0100 Subject: [PATCH] rationalise debugging output --- pctb/convert.c | 14 +++++++------- pctb/ocr.c | 41 +++++++++++++++++++++++++---------------- pctb/ocr.h | 5 +++++ pctb/show-thing.tcl | 10 +++++++--- 4 files changed, 44 insertions(+), 26 deletions(-) diff --git a/pctb/convert.c b/pctb/convert.c index f90ca4a..1d516f9 100644 --- a/pctb/convert.c +++ b/pctb/convert.c @@ -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(); } diff --git a/pctb/ocr.c b/pctb/ocr.c index bb95767..7eb871a 100644 --- a/pctb/ocr.c +++ b/pctb/ocr.c @@ -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; xh,w); + for (x=0; xnextword; } 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; ctxicontexts[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; inlinks; 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; rxnresults); + debugf("OCR finished %d glyphs\n",rd->nresults); debug_flush(); return rd->results; } diff --git a/pctb/ocr.h b/pctb/ocr.h index a03f1f5..b77a56f 100644 --- a/pctb/ocr.h +++ b/pctb/ocr.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -41,4 +42,8 @@ void debug_flush(void); const char *get_vardir(void); + +/* #define DEBUG_RECTANGLES */ +/* #define DEBUG_OCR */ + #endif /*OCR_H*/ diff --git a/pctb/show-thing.tcl b/pctb/show-thing.tcl index 1af2101..c04d4dd 100755 --- a/pctb/show-thing.tcl +++ b/pctb/show-thing.tcl @@ -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 {} -- 2.30.2