chiark / gitweb /
progress printing and bugfixing and build system improvements
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 7 Jun 2009 15:45:22 +0000 (16:45 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sun, 7 Jun 2009 15:45:22 +0000 (16:45 +0100)
pctb/Makefile
pctb/charset-15.txt
pctb/convert.c
pctb/convert.h
pctb/pages.c
pctb/structure.c
pctb/x.gdb

index 7d1d6efad02f7cffab871472b992e38e3f26deba..2265cecf38f189376a197d031cb76250721ffe9f 100644 (file)
@@ -1,7 +1,14 @@
-CFLAGS += -Wall -Wwrite-strings -Wpointer-arith -Wmissing-prototypes \
-       -Wstrict-prototypes -Werror -g
+OPTIMISE= -O2
+WERROR= -Werror
+WARNINGS= -Wall -Wwrite-strings -Wpointer-arith -Wmissing-prototypes \
+         -Wstrict-prototypes -Wno-format-zero-length
+DEBUG=-g
 
-all: convert x-manip-window
+CFLAGS += $(WARNINGS) $(WERROR) $(OPTIMISE) $(DEBUG)
+
+TARGETS= convert x-manip-window
+
+all: $(TARGETS)
 
 CONVERT_OBJS= convert.o ocr.o pages.o structure.o
 
@@ -9,3 +16,6 @@ convert: $(CONVERT_OBJS) -lnetpbm -lXtst -lX11
 $(CONVERT_OBJS): ocr.h convert.h structure.h
 
 x-manip-window: -lXtst -lX11
+
+clean:
+       rm -f $(TARGETS) *.o core core.*
index d12325b2701ab4b0dfff4c5319662e8718abd31b..f89f60fcbdb48157698b3c3cfc4e8ac19bd925be 100644 (file)
@@ -138,6 +138,15 @@ ff8
 410
 3e0
 
+Lower
+E
+ff8
+888
+888
+888
+888
+808
+
 Lower
 F
 ff8
@@ -628,6 +637,18 @@ y
 0
 0
 
+Lower
+yt
+60
+180
+2600
+1800
+600
+180
+60
+7f0
+820
+
 Lower
 yw
 60
@@ -666,6 +687,24 @@ A
 600
 800
 
+Upper
+Av
+800
+600
+380
+260
+218
+260
+380
+600
+820
+c0
+700
+800
+700
+c0
+20
+
 Upper
 B
 ff8
@@ -826,6 +865,17 @@ ff8
 88
 70
 
+Upper
+Q
+3e0
+410
+808
+808
+808
+1410
+23e0
+2000
+
 Upper
 R
 ff8
index cd9c6521976385498e72311d84631432a5d10bbf..8b12f3a06c62f19214658dd2a1870e63bcbbe4a0 100644 (file)
@@ -90,6 +90,7 @@ int main(int argc, char **argv) {
 DEFINE_VWRAPPERF(, progress)
 DEFINE_VWRAPPERF(, progress_log)
 DEFINE_VWRAPPERF(, progress_spinner)
+DEFINE_VWRAPPERF(, warning)
 
 static int last_progress_len;
      
@@ -137,3 +138,10 @@ void vprogress_log(const char *fmt, va_list al) {
   putc('\n',stderr);
   fflush(stderr);
 }
+
+void vwarning(const char *fmt, va_list al) {
+  progress("");
+  fputs("warning: ",stderr);
+  vfprintf(stderr,fmt,al);
+  fflush(stderr);
+}
index d39626926725eab5d6869c7f0cf41437c00d0d00..cb2bf77e6d0a27a1306cb364bc7baee794a8ca96 100644 (file)
@@ -22,14 +22,19 @@ void analyse(void);
 
 extern FILE *screenshots_file;
 
-void vprogress(const char *fmt, va_list);
-void progress(const char *fmt, ...);
+#define FMT(f,a) __attribute__((format(printf,f,a)))
 
-void vprogress_log(const char *fmt, va_list);
-void progress_log(const char *fmt, ...);
+void vwarning(const char *fmt, va_list) FMT(1,0);
+void warning(const char *fmt, ...)      FMT(1,2);
 
-void vprogress_spinner(const char *fmt, va_list);
-void progress_spinner(const char *fmt, ...);
+void vprogress(const char *fmt, va_list) FMT(1,0);
+void progress(const char *fmt, ...)      FMT(1,2);
+
+void vprogress_log(const char *fmt, va_list) FMT(1,0);
+void progress_log(const char *fmt, ...)      FMT(1,2);
+
+void vprogress_spinner(const char *fmt, va_list) FMT(1,0);
+void progress_spinner(const char *fmt, ...)      FMT(1,2);
 
 /*----- from pages.c -----*/
 
index fbf33171bd3a90182cc7e650361654767f0181d6..ffd0ba6e4c8c9c8a39d4268291f65638030d0f87 100644 (file)
@@ -61,6 +61,58 @@ static void sync_after_input(void) {
   last_input= timestamp();
 }
 
+static void translate_coords_toroot(int wx, int wy, int *rx, int *ry) {
+  int r;
+  Window dummy;
+  r= XTranslateCoordinates(disp, id,attr.root, wx,wy, rx,ry, &dummy);
+  eassert(r);
+}
+
+static void check_client_window_all_on_screen(void) {
+  int r;
+  int rxpos, rypos;
+  unsigned rwidth, rheight;
+  Window dummy;
+  unsigned bd, depth;
+
+  r= XGetGeometry(disp,attr.root, &dummy, &rxpos,&rypos,
+                 &rwidth, &rheight,
+                 &bd,&depth);
+  
+  translate_coords_toroot(0,0, &rxpos,&rypos);
+  eassert(rxpos>=0 && rypos>=0);
+
+  translate_coords_toroot(wwidth-1,wheight-1, &rxpos,&rypos);
+  eassert(rxpos<rwidth && rypos<rheight);
+}
+
+static void check_not_disturbed(void) {
+  XEvent ev;
+  int r;
+  
+  for (;;) {
+    r= XCheckMaskEvent(disp, ~0, &ev);
+    if (r==False) return;
+
+    switch (ev.type) {
+    case VisibilityNotify:
+      eassert(ev.xvisibility.state == VisibilityUnobscured);
+      break;
+    case ConfigureNotify:
+      check_client_window_all_on_screen();
+      break;
+    case FocusOut:
+      eassert(!"focus left YPP client window");
+      break;
+    case FocusIn:
+      warning("focus entered YPP client window ?!");
+      break;
+    default:
+      eassert(!"unexpected X11 event");
+    }
+  }
+}      
+
 static void send_key(KeySym sym) {
   XTestFakeKeyEvent(disp, keycode(sym),1, 10);
   XTestFakeKeyEvent(disp, keycode(sym),0, 10);
@@ -92,7 +144,9 @@ static void snapshot(Snapshot **output) {
   timestamp();
   *output= XGetImage(disp,id, 0,0, wwidth,wheight, AllPlanes, ZPixmap);
   timestamp();
-  
+
+  check_not_disturbed();
+
   debugf("PAGING   snapshot done.\n");
 }
 
@@ -105,10 +159,19 @@ static int identical(const Snapshot *a, const Snapshot *b) {
   return !memcmp(a->data, b->data, a->bytes_per_line * a->height);
 }
 
+static void wait_for_stability(Snapshot **output,
+                              const Snapshot *previously,
+                              void (*with_keypress)(void),
+                              const char *fmt, ...)
+     FMT(4,5);
+
 static void wait_for_stability(Snapshot **output,
                               const Snapshot *previously,
                               void (*with_keypress)(void),
                               const char *fmt, ...) {
+  va_list al;
+  va_start(al,fmt);
+
   Snapshot *last=0;
   int r;
   /* waits longer if we're going to return an image identical to previously
@@ -119,12 +182,9 @@ static void wait_for_stability(Snapshot **output,
          last_input, previously);
 
   char *doing;
-  va_list al;
-  va_start(al,fmt);
-  r= asprintf(&doing,fmt,al);  eassert(r>=0);
-  va_end(al);
+  r= vasprintf(&doing,fmt,al);  eassert(r>=0);
 
-  progress(doing);
+  progress("%s",doing);
 
   for (;;) {
     double at_snapshot= timestamp();
@@ -144,7 +204,7 @@ static void wait_for_stability(Snapshot **output,
       break;
     }
     
-    progress_spinner(doing);
+    progress_spinner("%s",doing);
 
     debugf("PAGING  wait_for_stability  retry\n");
 
@@ -159,13 +219,7 @@ static void wait_for_stability(Snapshot **output,
   free_snapshot(&last);
   free(doing);
   debugf("PAGING  wait_for_stability done.\n");
-}
-
-static void translate_coords_toroot(int wx, int wy, int *rx, int *ry) {
-  int r;
-  Window dummy;
-  r= XTranslateCoordinates(disp, id,attr.root, wx,wy, rx,ry, &dummy);
-  eassert(r);
+  va_end(al);
 }
 
 static void raise_and_get_details(void) {
@@ -173,7 +227,6 @@ static void raise_and_get_details(void) {
   int evbase,errbase,majver,minver;
   int wxpos, wypos;
   unsigned bd,depth;
-  Window dummy;
 
   progress("raising and checking YPP client window...");
 
@@ -202,20 +255,11 @@ static void raise_and_get_details(void) {
 
   eassert(wwidth >= 320 && wheight >= 320);
 
-  int rxpos, rypos;
-  unsigned rwidth, rheight;
-  r= XGetGeometry(disp,attr.root, &dummy, &rxpos,&rypos,
-                 &rwidth, &rheight,
-                 &bd,&depth);
-  
-  translate_coords_toroot(0,0, &rxpos,&rypos);
-  eassert(rxpos>=0 && rypos>=0);
-
-  translate_coords_toroot(wwidth-1,wheight-1, &rxpos,&rypos);
-  eassert(rxpos<rwidth && rypos<rheight);
+  check_client_window_all_on_screen();
 }
 
 static void set_focus(void) {
+  int r;
   int screen= XScreenNumberOfScreen(attr.screen);
 
   progress("taking control of YPP client window...");
@@ -231,6 +275,13 @@ static void set_focus(void) {
 
   sync_after_input();
 
+  delay(0.5);
+  r= XSelectInput(disp, id,
+                 StructureNotifyMask|
+                 VisibilityChangeMask|
+                 FocusChangeMask
+                 );  eassert(r);
+
   translate_coords_toroot(10,10, &xpos,&ypos);
   XTestFakeMotionEvent(disp,screen, xpos,ypos, 0);
 
@@ -324,7 +375,8 @@ void take_screenshots(void) {
     debugf("PAGING page %d converted\n",npages);
 
     wait_for_stability(&current,last, 0,
-                      "collecting screenshot of page %d...",npages+1);
+                      "collecting screenshot of page %d...",
+                      npages+1);
 
     if (npages &&  /* first pagedown doesn't do much */
        identical(current,last)) {
index 04cb962c5a00882ad9a1dc7665b3466be6c4c63f..d768acd406151a7fccf55a510cbd2d1c9ede4af9 100644 (file)
@@ -235,7 +235,7 @@ static void file_read_image_ppm(FILE *f) {
 void read_one_screenshot(void) {
   progress("reading screenshot...");
   file_read_image_ppm(screenshots_file);
-  progress_log("read screenshot.",npages);
+  progress_log("read screenshot.");
 }
 
 void read_screenshots(void) {
index c52a919f444c36943e834775242abc1f07f51346..5d5abeb53343064267e8f105d5a49276b619b4ca 100644 (file)
@@ -1,5 +1,6 @@
 file convert
 set confirm off
-set args 0x8c00007 >t
+set args --screenshot-only
 
+break pages.c:375
 run