From 8b3b006869bfdc6c2ddbf58d6709a73433abe2f9 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 6 Jun 2009 00:17:27 +0100 Subject: [PATCH] allow nonexistent charset db --- pctb/ocr.c | 12 ++++++++---- pctb/show-thing.tcl | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pctb/ocr.c b/pctb/ocr.c index 48c25c0..bb95767 100644 --- a/pctb/ocr.c +++ b/pctb/ocr.c @@ -63,12 +63,19 @@ static void readdb(OcrReader *rd) { char lbuf[100]; FILE *db; + for (ctxi=0; ctxicontexts[ctxi]); + char *dbfname=0; asprintf(&dbfname,"%s/charset-%d.txt",get_vardir(),rd->h); eassert(dbfname); - db= fopen(dbfname,"r"); eassert(db); + db= fopen(dbfname,"r"); free(dbfname); + if (!db) { + eassert(errno==ENOENT); + return; + } FGETSLINE(db,lbuf); eassert(!strcmp(lbuf,"# ypp-sc-tools pctb font v1")); @@ -77,9 +84,6 @@ static void readdb(OcrReader *rd) { eassert(r==1); eassert(h==rd->h); - for (ctxi=0; ctxicontexts[ctxi]); - for (;;) { FGETSLINE(db,lbuf); if (!lbuf || lbuf[0]=='#') continue; diff --git a/pctb/show-thing.tcl b/pctb/show-thing.tcl index d71c36e..980a8a4 100755 --- a/pctb/show-thing.tcl +++ b/pctb/show-thing.tcl @@ -387,6 +387,7 @@ proc read_database {} { global database database_header rows database_fn catch { unset database } set database_fn ./charset-$rows.txt + if {![file exists $database_fn]} return set f [open $database_fn r] if {[string compare [db_getsl $f] $database_header]} { error "$l ?" } if {([db_getsl $f])+0 != $rows} { error "wrong h ?" } -- 2.30.2