chiark / gitweb /
Cope if very few commodities on screen. Use ADJUST_BOX much more.
[ypp-sc-tools.web-live.git] / pctb / structure.c
index 1665211df8358d6820bc11ceb6c1e51c1887cfa3..e9df7334a73f04cf53c4754a0a14f7a21228180f 100644 (file)
@@ -40,7 +40,7 @@ DEBUG_DEFINE_DEBUGF(struct)
 #define TEXT_COLUMNS        2
 #define MAX_COLUMNS         7
 
-static Rect mainr = { START_MAIN,START_MAIN };
+static Rect mainr;
 static int commbasey, comminty;
 static int colrightx[INTERESTING_COLUMNS];
 static int text_h=-1, columns=-1;
@@ -242,7 +242,7 @@ static int commod_selector_matches(Rect search, const char *const *all,
 #define ADJUST_BOX(search,insidechrs,OP,want, lim,LIMIT_MUST, TLBR,XY,increm) \
   for (;;) {                                                                 \
     LIMIT_MUST( (search).tl.XY != (search).br.XY &&                          \
-               (search).tl.XY != (lim),                                      \
+               (search).TLBR.XY != (lim),                                    \
                MR((search));MSB(#TLBR);MSB(#XY) );                           \
     int got=0;                                                               \
     Point p=(search).tl;                                                     \
@@ -272,6 +272,11 @@ void find_structure(CanonImage *im, int *max_relevant_y_r) {
     }
   }
 
+  Point mainr_tl= START_MAIN;
+  mainr.tl= mainr_tl;
+  WALK_UNTIL_MUST(mainr.tl, y,-1, whole.tl.y, ' ');
+  mainr.br= mainr.tl;
+
   WALK_UNTIL_MUST(mainr.tl, x,-1, whole.tl.x, '*');
   WALK_UNTIL_MUST(mainr.tl, y,-1, whole.tl.y, '*');
   WALK_UNTIL_MUST(mainr.br, x,+1, whole.br.x, '*');
@@ -306,37 +311,48 @@ void find_structure(CanonImage *im, int *max_relevant_y_r) {
 
   debug_rect("mainr",1, mainr);
 
-  Point up = START_MAIN;
-  WALK_UNTIL_MUST(up, y,-1, mainr.tl.y, '+');
+  Rect updown= {START_MAIN,START_MAIN};
+  const int chkw= 100;
+  updown.br.x += chkw-1;
+  updown.br.y++;
+  debug_rect("updown",__LINE__,updown);
+
+  ADJUST_BOX(updown, "+", >=,chkw, mainr.tl.y,   MUST, tl,y,-1);
+  debug_rect("updown",__LINE__,updown);
+  updown.br.y= updown.tl.y;
+  updown.tl.y= updown.tl.y-1;
 
-  Point down = START_MAIN;
-  down.y++;
-  WALK_UNTIL_MUST(down, y,+1, mainr.br.y, '+');
+  ADJUST_BOX(updown, "+*",>=,chkw, mainr.tl.y-1, MUST, tl,y,-1);
+  debug_rect("updown",__LINE__,updown);
 
-  commbasey= up.y;
-  comminty= down.y - up.y + 2;
+  commbasey= updown.tl.y + 1;
+  comminty= updown.br.y - updown.tl.y;
 
-  Point across= { mainr.tl.x, commbasey };
+  Rect across= {{ mainr.tl.x - 1, commbasey              },
+               { mainr.tl.x,     commbasey + comminty-2 }};
   int colno=0;
   for (;;) {
-    MUST( get_p(across) != '+', MI(colno);MP(across);MR(mainr);MI(commbasey) );
-    WALK_UNTIL(across, x,+1, mainr.br.x, '+');
-    MUST( colno < MAX_COLUMNS, MP(across);MR(mainr);MI(commbasey); );
-    int colrx= across.x;
-    if (colrx > mainr.br.x) colrx= mainr.br.x;
+
+#define LIMIT_QUITEQ(cond,mp) { if (!(cond)) break; }
+    debug_rect("across",colno*1000000+__LINE__, across);
+    ADJUST_BOX(across, "+",>=,comminty-1, mainr.br.x, LIMIT_QUITEQ, br,x,+1);
+    debug_rect("across",colno*1000000+__LINE__, across);
+
+    MUST( colno < MAX_COLUMNS, MI(colno);MR(across);MR(mainr);MI(commbasey); );
+    int colrx= across.br.x-1;
+    if (colrx >= mainr.br.x) colrx= mainr.br.x;
     if (colno < INTERESTING_COLUMNS)
       colrightx[colno]= colrx;
       
     colno++;
     
-    if (across.x >= mainr.br.x-1)
+    if (across.br.x >= mainr.br.x)
       break;
 
-    across.x++;
-    REQUIRE_RECTANGLE(across.x,mainr.tl.y, across.x,mainr.br.y, "+");
-    across.x++;
+    REQUIRE_RECTANGLE(across.br.x,mainr.tl.y, across.br.x,mainr.br.y, "+");
+    across.br.x++;
   }
-  MUST( colno >= MIN_COLUMNS, MI(colno);MR(mainr);MP(across); );
+  MUST( colno >= MIN_COLUMNS, MI(colno);MR(mainr);MR(across); );
 
 #define SET_ONCE(var,val) do{                                          \
     int v= (val);                                                      \
@@ -812,6 +828,8 @@ void find_islandname(void) {
            might_be_colon=1;
            goto ok_might_be_colon;
          }
+       } else if (nruns==1 && runs[0]==1 && might_be_colon) {
+         goto colon_found;
        }
        might_be_colon=0;
       ok_might_be_colon: