-static void ocr_readdb(void) {
- int ctx,nchrs;
- OCRDatabaseNode *current, *additional;
+DEBUG_DEFINE_DEBUGF(ocr)
+
+#define dbassert(x) \
+ ((x) ? (void)0 : \
+ fatal("Error in character set database.\n" \
+ " Requirement not met: %s:%d: %s", __FILE__,__LINE__, #x))
+
+static void fgetsline(FILE *f, char *lbuf, size_t lbufsz) {
+ errno=0;
+ char *s= fgets(lbuf,lbufsz,f);
+ sysassert(!ferror(f));
+ dbassert(!feof(f));
+ assert(s);
+ int l= strlen(lbuf);
+ dbassert(l>0); dbassert(lbuf[--l]='\n');
+ lbuf[l]= 0;
+}
+#define FGETSLINE(f,buf) (fgetsline(f,buf,sizeof(buf)))
+
+static void cleardb_node(DatabaseNode *n) {
+ int i;
+ n->s[0]= 0;
+ for (i=0; i<n->nlinks; i++)
+ cleardb_node(n->links[i].then);
+}
+
+static void readdb(OcrReader *rd) {
+ int nchrs;
+ DatabaseNode *current, *additional;