From 2ca58afcdf02d87e31115110ecd6c83ecc5dabc7 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 6 Jun 2009 20:17:13 +0100 Subject: [PATCH] much fixes for new arrangements --- pctb/charset-15.txt | 75 +++++++++++++++++++++++++++++++++++++++++++++ pctb/convert.c | 5 +++ pctb/ocr.c | 11 ++++--- pctb/ocr.h | 24 ++++++++++++--- pctb/pages.c | 4 +-- pctb/show-thing.tcl | 23 ++++++++------ pctb/structure.c | 31 +++++++++---------- pctb/structure.h | 17 ++++------ 8 files changed, 142 insertions(+), 48 deletions(-) diff --git a/pctb/charset-15.txt b/pctb/charset-15.txt index d2478da..99aeff1 100644 --- a/pctb/charset-15.txt +++ b/pctb/charset-15.txt @@ -120,6 +120,14 @@ A 600 800 +Lower +B +ff8 +888 +888 +888 +770 + Lower D ff8 @@ -137,6 +145,24 @@ ff8 88 88 +Lower +H +ff8 +80 +80 +80 +80 +80 +ff8 + +Lower +It +ff8 +0 +20 +7f0 +820 + Lower J 2000 @@ -153,6 +179,24 @@ c0 408 800 +Lower +L +ff8 +800 +800 +800 +800 + +Lower +M +ff8 +30 +1c0 +600 +1c0 +30 +ff8 + Lower N ff8 @@ -264,6 +308,12 @@ Lower i fe8 +Lower +j +2000 +2000 +1fe8 + Lower k ff8 @@ -380,6 +430,14 @@ c00 380 60 +Lower +x +820 +6c0 +100 +6c0 +820 + Lower y 60 @@ -495,6 +553,14 @@ Upper I ff8 +Upper +It +ff8 +0 +20 +7f0 +820 + Upper J 2000 @@ -576,6 +642,15 @@ ff8 8 8 +Upper +U +7f8 +800 +800 +800 +800 +7f8 + Upper V 18 diff --git a/pctb/convert.c b/pctb/convert.c index f38abf5..5f47113 100644 --- a/pctb/convert.c +++ b/pctb/convert.c @@ -31,6 +31,11 @@ int main(int argc, char **argv) { o_single_page= 1; else if (!strcmp(arg,"--screenshots-file")) eassert( o_screenshots_fn= *++argv ); +#define DF(f) \ + else if (!strcmp(arg,"-D" #f)) \ + debug_flags |= dbg_##f; + DEBUG_FLAG_LIST +#undef DF else if (!strcmp(arg,"--window-id")) { char *ep; eassert((arg=*++argv)); diff --git a/pctb/ocr.c b/pctb/ocr.c index 7eb871a..436aa8d 100644 --- a/pctb/ocr.c +++ b/pctb/ocr.c @@ -24,7 +24,7 @@ static const char *context_names[]= { #define NCONTEXTS (sizeof(context_names)/sizeof(context_names[0])) -#define SPACE_SPACES 3 +#define SPACE_SPACES 4 struct OcrReader { int h; @@ -185,7 +185,9 @@ static void callout_unknown(OcrReader *rd, int w, Pixcol cols[], * so we aren't in any danger of overwriting some other fd 4: */ r= dup2(donepipe[1],4); eassert(r==4); execlp("./show-thing.tcl", "./show-thing.tcl", - "--automatic","1",(char*)0); + DEBUGP(callout) ? "--debug" : "--noop-arg", + "--automatic-1", + (char*)0); eassert(!"execlp failed"); } r= close(jobpipe[0]); eassert(!r); @@ -287,9 +289,8 @@ const struct OcrCellTypeInfo ocr_celltype_text= { }; static void vdebugf(const char *fmt, va_list al) { -#ifdef DEBUG_OCR - vfprintf(debug,fmt,al); -#endif + if (DEBUGP(ocr)) + vfprintf(debug,fmt,al); } static void debugf(const char *fmt, ...) { va_list al; va_start(al,fmt); vdebugf(fmt,al); va_end(al); diff --git a/pctb/ocr.h b/pctb/ocr.h index 60234a8..a688742 100644 --- a/pctb/ocr.h +++ b/pctb/ocr.h @@ -7,10 +7,6 @@ #define OCR_H -// #define DEBUG_RECTANGLES -// #define DEBUG_OCR - - #define _GNU_SOURCE #include @@ -58,6 +54,26 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType, int w, Pixcol cols[]); /*----- debugging arrangements, rather contingent -----*/ +#define DEBUG_FLAG_LIST \ + DF(ocr) \ + DF(rect) \ + DF(callout) + +enum { +#define DF(f) dbg__shift_##f, + DEBUG_FLAG_LIST +#undef DF +}; +enum { +#define DF(f) dbg_##f = 1 << dbg__shift_##f, + DEBUG_FLAG_LIST +#undef DF +}; + +unsigned debug_flags; + +#define DEBUGP(f) (!!(debug_flags & dbg_##f)) + void debug_flush(void); #define eassert assert diff --git a/pctb/pages.c b/pctb/pages.c index 361ea0e..360e718 100644 --- a/pctb/pages.c +++ b/pctb/pages.c @@ -249,7 +249,7 @@ void take_screenshots(void) { /* find the window and check it's on the right kind of screen */ raise_and_get_details(); - snapshot(¤t); + wait_for_stability(¤t,0,0); test= convert_page(current); find_structure(test); free(test); @@ -286,7 +286,7 @@ void take_one_screenshot(void) { raise_and_get_details(); sync_after_input(); - snapshot(¤t); + wait_for_stability(¤t,0,0); page_images[0]= convert_page(current); npages= 1; } diff --git a/pctb/show-thing.tcl b/pctb/show-thing.tcl index c04d4dd..5356c32 100755 --- a/pctb/show-thing.tcl +++ b/pctb/show-thing.tcl @@ -26,10 +26,6 @@ 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 @@ -525,6 +521,7 @@ proc required {} { debug "GOT $l" fileevent stdin readable {} + fconfigure stdin -blocking yes read_xpm stdin resize_widgets @@ -539,14 +536,20 @@ proc main/automatic {} { } proc done/automatic {} { exec sh -c {printf \\0 >&4} - fileevent stdin readable required + main/automatic } -switch -exact -- $argv { - {} { set mainkind test } - {--automatic 1} { set mainkind automatic } - {--automatic*} { error "incompatible versions - install problem" } - default { error "huh $argv ?" } +proc debug {m} { } + +set mainkind test +foreach arg $argv { + switch -exact -- $arg { + {--debug} { proc debug {m} { puts stderr "SHOW-THING $m" } } + {--noop-arg} { } + {--automatic-1} { set mainkind automatic } + {--automatic*} { error "incompatible versions - install problem" } + default { error "huh $argv ?" } + } } main/$mainkind diff --git a/pctb/structure.c b/pctb/structure.c index fc077c1..f9f1e7f 100644 --- a/pctb/structure.c +++ b/pctb/structure.c @@ -77,7 +77,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 + if (!DEBUGP(rect)) return; 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); @@ -89,7 +89,6 @@ static void debug_rect(const char *what, int whati, Rect rr) { fputc('|',debug); fputc('\n',debug); } -#endif debug_flush(); } @@ -152,17 +151,17 @@ void find_structure(CanonImage *im) { 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," "); - for (x=0; x<=cim->w; x++) { - if (x % xscaleunit) fputc(' ',debug); - else fprintf(debug,"%d",(x / xscaleunit)%10); + if (DEBUGP(rect)) { + int xscaleunit, y,x; + for (y=0, xscaleunit=1; y<4; y++, xscaleunit*=10) { + fprintf(debug," "); + for (x=0; x<=cim->w; x++) { + if (x % xscaleunit) fputc(' ',debug); + else fprintf(debug,"%d",(x / xscaleunit)%10); + } + fputc('\n',debug); } - fputc('\n',debug); } -#endif commbasey= up.y; comminty= down.y - up.y + 2; @@ -230,13 +229,13 @@ CanonImage *file_read_image_ppm(FILE *f) { } void read_screenshots(void) { - int c; - while ((c= fgetc(screenshots_file) != EOF)) { - ungetc(c, screenshots_file); +// int c; +// while ((c= fgetc(screenshots_file) != EOF)) { +// ungetc(c, screenshots_file); - eassert(npages < MAX_PAGES); +// eassert(npages < MAX_PAGES); page_images[npages++]= file_read_image_ppm(screenshots_file); - } +// } } static void find_commodity(int offset, Rect *rr) { diff --git a/pctb/structure.h b/pctb/structure.h index 10de443..b246c87 100644 --- a/pctb/structure.h +++ b/pctb/structure.h @@ -14,16 +14,6 @@ extern const CanonColourInfo canoncolourinfos[]; CanonImage *alloc_canon_image(int w, int h); -#ifdef DEBUG_RECTANGLES -# define CANIMG_DEBUG_RECTANGLE_1LINE(im,w,h) \ - fprintf(debug, "%4d ",y); \ - int r= fwrite(im->d + y*w, 1,w, debug); \ - eassert(r==w); \ - fputc('\n',debug); -#else -# define CANIMG_DEBUG_RECTANGLE_1LINE(im,y,h) /* nothing */ -#endif - #define CANONICALISE_IMAGE(im,w,h, COMPUTE_RGB) do{ \ /* compute_rgb should be a number of statements, or \ * a block, which assigns to \ @@ -48,7 +38,12 @@ CanonImage *alloc_canon_image(int w, int h); break; \ } \ } \ - CANIMG_DEBUG_RECTANGLE_1LINE((im),(w),(h)) \ + if (DEBUGP(rect)) { \ + fprintf(debug, "%4d ",y); \ + int r= fwrite(im->d + y*w, 1,w, debug); \ + eassert(r==w); \ + fputc('\n',debug); \ + } \ } \ debug_flush(); \ }while(0) -- 2.30.2