600
800
+Lower
+B
+ff8
+888
+888
+888
+770
+
Lower
D
ff8
88
88
+Lower
+H
+ff8
+80
+80
+80
+80
+80
+ff8
+
+Lower
+It
+ff8
+0
+20
+7f0
+820
+
Lower
J
2000
408
800
+Lower
+L
+ff8
+800
+800
+800
+800
+
+Lower
+M
+ff8
+30
+1c0
+600
+1c0
+30
+ff8
+
Lower
N
ff8
i
fe8
+Lower
+j
+2000
+2000
+1fe8
+
Lower
k
ff8
380
60
+Lower
+x
+820
+6c0
+100
+6c0
+820
+
Lower
y
60
I
ff8
+Upper
+It
+ff8
+0
+20
+7f0
+820
+
Upper
J
2000
8
8
+Upper
+U
+7f8
+800
+800
+800
+800
+7f8
+
Upper
V
18
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));
#define NCONTEXTS (sizeof(context_names)/sizeof(context_names[0]))
-#define SPACE_SPACES 3
+#define SPACE_SPACES 4
struct OcrReader {
int h;
* 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);
};
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);
#define OCR_H
-// #define DEBUG_RECTANGLES
-// #define DEBUG_OCR
-
-
#define _GNU_SOURCE
#include <string.h>
/*----- 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
/* 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);
raise_and_get_details();
sync_after_input();
- snapshot(¤t);
+ wait_for_stability(¤t,0,0);
page_images[0]= convert_page(current);
npages= 1;
}
set csrh 20
set ctxh 20
-proc debug {m} {
- puts stderr "SHOW-THING $m"
-}
-
proc init_widgets {} {
# idempotent
global csrh gotsh ctxh
debug "GOT $l"
fileevent stdin readable {}
+ fconfigure stdin -blocking yes
read_xpm stdin
resize_widgets
}
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
}
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);
fputc('|',debug);
fputc('\n',debug);
}
-#endif
debug_flush();
}
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;
}
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) {
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 \
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)