chiark / gitweb /
Pack findchar's args into a struct
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 29 Jun 2009 15:56:46 +0000 (16:56 +0100)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Mon, 29 Jun 2009 15:56:46 +0000 (16:56 +0100)
pctb/ocr.c

index ecfac976b2d025176bd4ee82675c31a108c3ba18..bc8057725291a482fb7a31a9cf0428112e6442ad 100644 (file)
@@ -277,17 +277,25 @@ static void add_result(OcrReader *rd, const char *s, int l, int r,
 
 const char *ocr_celltype_name(OcrCellType ct) { return ct->name; }
 
 
 const char *ocr_celltype_name(OcrCellType ct) { return ct->name; }
 
-static DatabaseNode *findchar(OcrReader *rd, int w, Pixcol cols[],
-                             int x, int ctxi, int *matchx_r) {
-  DatabaseNode *current= &rd->contexts[ctxi];
+typedef struct {
+  OcrReader *rd;
+  int w;
+  Pixcol *cols;
+  int x;
+} FindCharArgs;
+
+static DatabaseNode *findchar(const FindCharArgs *fca,
+                             DatabaseNode *start, int *matchx_r) {
+  DatabaseNode *current= start;
   DatabaseNode *bestmatch= 0;
   int i;
   DatabaseNode *bestmatch= 0;
   int i;
+  int x= fca->x;
 
   for (;;) {
     debug_flush();
     debugf(" | x=%d",x);
 
   for (;;) {
     debug_flush();
     debugf(" | x=%d",x);
-    if (x>w) break;
-    Pixcol cv= cols[x];
+    if (x > fca->w) break;
+    Pixcol cv= fca->cols[x];
     debugf(" cv=%"PSPIXCOL(PRIx),cv);
     for (i=0; i<current->nlinks; i++)
       if (current->links[i].col == cv)
     debugf(" cv=%"PSPIXCOL(PRIx),cv);
     for (i=0; i<current->nlinks; i++)
       if (current->links[i].col == cv)
@@ -348,6 +356,12 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType ct, int w, Pixcol cols[]) {
       add_result(rd," ",x-nspaces,x+1,0);
     nspaces=0;
 
       add_result(rd," ",x-nspaces,x+1,0);
     nspaces=0;
 
+    FindCharArgs fca;
+    fca.rd= rd;
+    fca.w= w;
+    fca.cols= cols;
+    fca.x= x;
+    
     DatabaseNode *uniquematch= 0;
     int uniquematch_rx=-1;
     
     DatabaseNode *uniquematch= 0;
     int uniquematch_rx=-1;
     
@@ -358,7 +372,7 @@ OcrResultGlyph *ocr(OcrReader *rd, OcrCellType ct, int w, Pixcol cols[]) {
       debugf(" || %s",context_names[ctxi]);
 
       DatabaseNode *match=
       debugf(" || %s",context_names[ctxi]);
 
       DatabaseNode *match=
-       findchar(rd,w,cols, x,ctxi, &uniquematch_rx);
+       findchar(&fca, &rd->contexts[ctxi], &uniquematch_rx);
       if (!match) continue;
 
       if (uniquematch && strcmp(match->str, uniquematch->str)) {
       if (!match) continue;
 
       if (uniquematch && strcmp(match->str, uniquematch->str)) {