+ 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;
+
+#define FOR_EACH_CONTEXT(EACH) \
+ EACH(Word) \
+ EACH(Upper) \
+ EACH(Lower) \
+ EACH(Digit)
+
+#define FEC_ENUM(Context) ct_##Context,
+#define FEC_BIT(Context) ctf_##Context = 1 << ct_##Context,
+enum {
+ FOR_EACH_CONTEXT(FEC_ENUM)
+ FOR_EACH_CONTEXT(FEC_BIT)
+};
+
+#define FEC_STRINGS(Context) #Context,
+static const char *context_names[]= { FOR_EACH_CONTEXT(FEC_STRINGS) };
+
+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);
+}