+ unsigned match:1, defined:1, endsword:1;
+ DatabaseLink *links;
+} DatabaseNode;
+
+typedef struct {
+ OcrReader *rd;
+ OcrCellType ct;
+ int w;
+ Pixcol *cols;
+ int x;
+ unsigned ctxmap;
+} FindCharArgs;
+typedef struct {
+ DatabaseNode *match;
+ int rx;
+} FindCharResults;
+
+enum { ct_Lower, ct_Upper, ct_Word, ct_Digit };
+static const char *context_names[]= {
+ "Lower", /* bit 0, value 001 */
+ "Upper", /* bit 1, value 002 */
+ "Word", /* bit 2, value 004 */
+ "Digit", /* bit 3, value 010 */
+};
+struct OcrCellTypeInfo {
+ /* bitmaps of indices into context_names: */
+ unsigned initial, nextword, midword;
+ int space_spaces;
+ const char *name;
+ int (*findchar_select)(const FindCharArgs *fca,
+ const FindCharResults results[]);
+};
+
+#define NCONTEXTS (sizeof(context_names)/sizeof(context_names[0]))
+
+struct OcrReader {
+ int h;
+ DatabaseNode contexts[NCONTEXTS];
+ OcrResultGlyph *results;
+ int aresults, nresults;
+};
+
+DEBUG_DEFINE_DEBUGF(ocr)
+
+#define FGETSLINE (dbfile_getsline(lbuf,sizeof(lbuf),__FILE__,__LINE__))
+
+static void cleardb_node(DatabaseNode *n) {
+ int i;
+ free(n->str); n->str=0;
+ n->defined=n->match=n->endsword= 0;
+ for (i=0; i<n->nlinks; i++)
+ cleardb_node(n->links[i].then);
+}