chiark / gitweb /
before special kerning thing
[ypp-sc-tools.web-live.git] / pctb / structure.c
index f9f1e7f52b1c8cf08328fe8a05a0446f0bc3452f..bbc7b8b5001f7d725de1fe28437514b24712d275 100644 (file)
@@ -229,13 +229,24 @@ CanonImage *file_read_image_ppm(FILE *f) {
 }
 
 void read_screenshots(void) {
-//  int c;
-//  while ((c= fgetc(screenshots_file) != EOF)) {
-//    ungetc(c, screenshots_file);
-
-//    eassert(npages < MAX_PAGES);
+  struct stat stab;
+  int r;
+  
+  r= fstat(fileno(screenshots_file), &stab);  eassert(!r);
+  
+  for (;;) {
+    if (S_ISREG(stab.st_mode)) {
+      long pos= ftell(screenshots_file);
+      if (pos == stab.st_size) break;
+    } else {
+      int c= fgetc(screenshots_file);
+      if (c==EOF) break;
+      ungetc(c, screenshots_file);
+    }
+    eassert(npages < MAX_PAGES);
     page_images[npages++]= file_read_image_ppm(screenshots_file);
-//  }
+  }
+  eassert(!ferror(screenshots_file));
 }
 
 static void find_commodity(int offset, Rect *rr) {
@@ -243,13 +254,14 @@ static void find_commodity(int offset, Rect *rr) {
   rr->tl.y= commbasey - offset*comminty;
   rr->br.y= rr->tl.y + comminty-2;
   if (rr->tl.y < mainr.tl.y || rr->br.y > mainr.br.y) { rr->tl.x=-1; return; }
+  
+  rr->tl.x= mainr.tl.x;
+  rr->br.x= mainr.br.x;
+
   if (rr->tl.y > mainr.tl.y)
     require_rectangle(rr->tl.x,rr->tl.y-1, rr->br.x,rr->tl.y-1, "+");
   if (rr->br.y < mainr.tl.y)
     require_rectangle(rr->tl.x,rr->br.y+1, rr->br.x,rr->br.y+1, "+");
-  
-  rr->tl.x= mainr.tl.x;
-  rr->br.x= mainr.br.x;
 }
 
 static void find_table_entry(Rect commod, int colno, Rect *cellr) {