chiark / gitweb /
WIP island determination; pixmap handling in progress
[ypp-sc-tools.db-live.git] / pctb / ocr.c
index 78542398abe3edcfdbc2078db667a1d135d01d01..f4bc77d56118ae8b4caebfce168a3336cd2eecc2 100644 (file)
@@ -86,17 +86,7 @@ DEBUG_DEFINE_DEBUGF(ocr)
      fatal("Error in character set database.\n"                                \
           " Requirement not met: %s:%d: %s", __FILE__,__LINE__, #x))
 
      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)))
+#define FGETSLINE (fgetsline(db,lbuf,sizeof(lbuf)))
 
 static void cleardb_node(DatabaseNode *n) {
   int i;
 
 static void cleardb_node(DatabaseNode *n) {
   int i;
@@ -129,7 +119,7 @@ static void readdb(OcrReader *rd) {
     return;
   }
 
     return;
   }
 
-  FGETSLINE(db,lbuf);
+  FGETSLINE;
   dbassert(!strcmp(lbuf,"# ypp-sc-tools pctb font v1"));
 
   r= fscanf(db, "%d", &h);
   dbassert(!strcmp(lbuf,"# ypp-sc-tools pctb font v1"));
 
   r= fscanf(db, "%d", &h);
@@ -137,7 +127,7 @@ static void readdb(OcrReader *rd) {
   dbassert(h==rd->h);
 
   for (;;) {
   dbassert(h==rd->h);
 
   for (;;) {
-    FGETSLINE(db,lbuf);
+    FGETSLINE;
     if (!lbuf || lbuf[0]=='#') continue;
     if (!strcmp(lbuf,".")) break;
 
     if (!lbuf || lbuf[0]=='#') continue;
     if (!strcmp(lbuf,".")) break;
 
@@ -145,7 +135,7 @@ static void readdb(OcrReader *rd) {
       if (!strcmp(lbuf,context_names[ctxi]))
        goto found_ctx;
     /* not found, just skip */
       if (!strcmp(lbuf,context_names[ctxi]))
        goto found_ctx;
     /* not found, just skip */
-    for (;;) { FGETSLINE(db,lbuf); if (!lbuf[0]) break; }
+    for (;;) { FGETSLINE; if (!lbuf[0]) break; }
     continue;
 
   found_ctx:
     continue;
 
   found_ctx:
@@ -171,7 +161,7 @@ static void readdb(OcrReader *rd) {
 
     current= &rd->contexts[ctxi];
     for (;;) {
 
     current= &rd->contexts[ctxi];
     for (;;) {
-      FGETSLINE(db,lbuf);
+      FGETSLINE;
       if (!lbuf[0]) { dbassert(current != &rd->contexts[ctxi]); break; }
       char *ep;
       cv= strtoul(lbuf,&ep,16);  dbassert(!*ep);
       if (!lbuf[0]) { dbassert(current != &rd->contexts[ctxi]); break; }
       char *ep;
       cv= strtoul(lbuf,&ep,16);  dbassert(!*ep);