chiark / gitweb /
Move code and decls between convert.[ch] and common.[ch] so that common.[ch] is for...
authorIan Jackson <ian@liberator.(none)>
Sat, 26 Sep 2009 18:19:12 +0000 (19:19 +0100)
committerIan Jackson <ian@liberator.(none)>
Sat, 26 Sep 2009 18:19:12 +0000 (19:19 +0100)
yarrg/Makefile
yarrg/common.c
yarrg/common.h
yarrg/convert.c
yarrg/convert.h
yarrg/ocr.c
yarrg/rscommon.h
yarrg/rsmain.c

index 708bfa275f2b6b60191e19daa3af093ddfb8e608..695f85cd6ddb2aaaae8a707827d4798234fbe577 100644 (file)
@@ -36,19 +36,20 @@ TARGETS= yarrg
 default: clean-other-directory $(TARGETS)
 all: default routesearch
 
-CONVERT_OBJS= convert.o ocr.o pages.o structure.o common.o rgbimage.o resolve.o
-
+CONVERT_OBJS= convert.o ocr.o pages.o structure.o rgbimage.o resolve.o
+COMMON_OBJS= common.o
 ROUTESEARCH_OBJS= rsvalue.o rsmain.o
 
-yarrg: $(CONVERT_OBJS) -lnetpbm -lXtst -lX11 -lpcre -lm
+yarrg: $(CONVERT_OBJS) $(COMMON_OBJS) -lnetpbm -lXtst -lX11 -lpcre -lm
        $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
-$(CONVERT_OBJS): ocr.h convert.h structure.h common.h
+$(CONVERT_OBJS): common.h ocr.h convert.h structure.h
 
-routesearch:   $(ROUTESEARCH_OBJS)
+routesearch:   $(ROUTESEARCH_OBJS) $(COMMON_OBJS)
        $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
 
-$(ROUTESEARCH_OBJS): rscommon.h
+$(ROUTESEARCH_OBJS): common.h rscommon.h
+$(COMMON_OBJS): common.h
 
 clean:
        rm -f *.o core core.* *~ vgcore.*
index cc33235f2b11d2fab791a7376113ac56d05002d6..fb2534109c772f53a47840f75ade1162da581220 100644 (file)
@@ -40,129 +40,124 @@ void *mrealloc(void *p, size_t sz) {
   return r;
 }
 
+DEFINE_VWRAPPERF(, progress, )
+DEFINE_VWRAPPERF(, progress_log, )
+DEFINE_VWRAPPERF(, progress_spinner, )
+DEFINE_VWRAPPERF(, warning, )
+DEFINE_VWRAPPERF(, fatal, NORET)
 
-FILE *dbfile;
-static const char *basepath; /* as passed in by caller */
-static pid_t dbzcat;
+static int last_progress_len;
 
-int dbfile_gzopen(const char *basepath_spec) {
-  assert(!dbfile);
-
-  basepath= basepath_spec;
-
-  char *zpath= masprintf("%s.gz", basepath);
-  int e= gzopen(zpath, O_RDONLY, &dbfile, &dbzcat, 0);
-  free(zpath);
-  if (e) { errno=e; sysassert(errno==ENOENT); return 0; }
+static void vprogress_core(int spinner, const char *fmt, va_list al) {
+  int r;
+  
+  if (o_quiet) return;
+  if (!debug_flags && !isatty(2)) return;
   
-  return 1;
-}  
+  if (last_progress_len)
+    putc('\r',stderr);
 
-int dbfile_open(const char *tpath) {
-  assert(!dbfile);
+  r= vfprintf(stderr,fmt,al);
 
-  basepath= tpath;
+  if (spinner) {
+    putc(spinner,stderr);
+    r++;
+  }
 
-  dbzcat= -1;
-  dbfile= fopen(tpath,"r");
-  if (!dbfile) { sysassert(errno==ENOENT); return 0; }
-  return 1;
-}  
+  if (r < last_progress_len) {
+    fprintf(stderr,"%*s", last_progress_len - r, "");
+    if (!r) putc('\r', stderr);
+    else while (last_progress_len-- > r) putc('\b',stderr);
+  }
+  last_progress_len= r;
 
-void dbfile_close(void) {
-  gzclose(&dbfile, &dbzcat, basepath);
+  if (ferror(stderr) || fflush(stderr)) _exit(16);
 }
-
-#define dbassertgl(x) ((x) ? (void)0 : dbfile_assertfail(file,line,#x))
-
-void dbfile_getsline(char *lbuf, size_t lbufsz, const char *file, int line) {
-  errno=0;
-  char *s= fgets(lbuf,lbufsz,dbfile);
-  sysassert(!ferror(dbfile));
-  dbassertgl(!feof(dbfile));
-  assert(s);
-  int l= strlen(lbuf);
-  dbassertgl(l>0);  dbassertgl(lbuf[--l]=='\n');
-  lbuf[l]= 0;
+   
+void vprogress(const char *fmt, va_list al) { vprogress_core(0,fmt,al); }
+void vprogress_spinner(const char *fmt, va_list al) {
+  static const char spinchars[]="/-\\";
+  static int spinner;
+
+  vprogress_core(spinchars[spinner],fmt,al);
+  spinner++;
+  spinner %= (sizeof(spinchars)-1);
 }
 
-int dbfile_vscanf(const char *fmt, va_list al) {
-  int r= vfscanf(dbfile,fmt,al);
-  sysassert(!ferror(dbfile));
-  return r;
+void vprogress_log(const char *fmt, va_list al) {
+  if (o_quiet) return;
+  
+  progress("");
+  vfprintf(stderr,fmt,al);
+  putc('\n',stderr);
+  fflush(stderr);
 }
 
-int dbfile_scanf(const char *fmt, ...) {
-  va_list al;
-  va_start(al,fmt);
-  int r= dbfile_vscanf(fmt,al);
-  va_end(al);
-  return r;
+void vwarning(const char *fmt, va_list al) {
+  progress("");
+  fputs("Warning: ",stderr);
+  vfprintf(stderr,fmt,al);
+  fputs("\n",stderr);
+  fflush(stderr);
 }
 
-void dbfile_assertfail(const char *file, int line, const char *m) {
-  if (dbzcat)
-    fatal("Error in dictionary file %s.gz:\n"
-         " Requirement not met at %s:%d:\n"
-         " %s",
-         basepath, file,line, m);
-  else if (dbfile)
-    fatal("Error in dictionary file %s at byte %ld:\n"
-         " Requirement not met at %s:%d:\n"
-         " %s",
-         basepath,(long)ftell(dbfile), file,line, m);
-  else
-    fatal("Semantic error in dictionaries:\n"
-         " Requirement not met at %s:%d:\n"
-         " %s",
-         file,line, m);
+void vfatal(const char *fmt, va_list al) {
+  progress("");
+  fputs("\n\nFatal error: ",stderr);
+  vfprintf(stderr,fmt,al);
+  fflush(stderr);
+  fputs("\n\n",stderr);
+  _exit(4);
 }
 
-int gzopen(const char *zpath, int oflags, FILE **f_r, pid_t *pid_r,
-          const char *gziplevel /* 0 for read; may be 0, or "-1" etc. */) {
-
-  int zfd= open(zpath, oflags, 0666);
-  if (zfd<0) return errno;
-
-  int pipefds[2];
-  sysassert(! pipe(pipefds) );
+void sysassert_fail(const char *file, int line, const char *what) {
+  int e= errno;
+  progress("");
+  fprintf(stderr,
+         "\nfatal operational error:\n"
+         " unsuccessful execution of: %s\n"
+         " %s:%d: %s\n\n",
+         what, file,line, strerror(e));
+  _exit(16);
+}
 
-  int oi,io; const char *cmd; const char *stdiomode;
-  switch ((oflags & O_ACCMODE)) {
-  case O_RDONLY: oi=0; io=1; cmd="gunzip"; stdiomode="r"; break;
-  case O_WRONLY: oi=1; io=0; cmd="gzip";   stdiomode="w"; break;
-  default: abort();
+void waitpid_check_exitstatus(pid_t pid, const char *what, int sigpipeok) { 
+  pid_t got;
+  int st;
+  for (;;) {
+    got= waitpid(pid, &st, 0);
+    if (pid==-1) { sysassert(errno==EINTR); continue; }
+    break;
   }
-
-  sysassert( (*pid_r=fork()) != -1 );
-  if (!*pid_r) {
-    sysassert( dup2(zfd,oi)==oi );
-    sysassert( dup2(pipefds[io],io)==io );
-    sysassert(! close(zfd) );
-    sysassert(! close(pipefds[0]) );
-    sysassert(! close(pipefds[1]) );
-    execlp(cmd,cmd,gziplevel,(char*)0);
-    sysassert(!"execlp gzip/gunzip");
+  sysassert( got==pid );
+
+  if (WIFEXITED(st)) {
+    if (WEXITSTATUS(st))
+      fatal("%s failed with nonzero exit status %d",
+           what, WEXITSTATUS(st));
+  } else if (WIFSIGNALED(st)) {
+    if (!sigpipeok || WTERMSIG(st) != SIGPIPE)
+      fatal("%s died due to signal %s%s", what,
+           strsignal(WTERMSIG(st)), WCOREDUMP(st)?" (core dumped)":"");
+  } else {
+    fatal("%s gave strange wait status %d", what, st);
   }
-  sysassert(! close(zfd) );
-  sysassert(! close(pipefds[io]) );
-  sysassert( *f_r= fdopen(pipefds[oi], stdiomode) );
+}
 
-  return 0;
+char *masprintf(const char *fmt, ...) {
+  char *r;
+  va_list al;
+  va_start(al,fmt);
+  sysassert( vasprintf(&r,fmt,al) >= 0);
+  sysassert(r);
+  va_end(al);
+  return r;
 }
 
-void gzclose(FILE **f, pid_t *p, const char *what) {
-  if (!*f) return;
-  
-  sysassert(!ferror(*f));
-  sysassert(!fclose(*f));
-
-  if (*p != -1) {
-    char *process= masprintf("%s (de)compressor",what);
-    waitpid_check_exitstatus(*p,process,1);
-    free(process);
-    *p= -1;
-  }
 
-  *f= 0;
+unsigned debug_flags;
+
+void debug_flush(void) {
+  sysassert(!ferror(debug));
+  sysassert(!fflush(debug));
 }
index 9d06fabf9a55c79b8a1878a649b8db03f6aaa083..fdae435493488e71402c567bff9965022e2f4684 100644 (file)
@@ -42,9 +42,6 @@
 #include <unistd.h>
 #include <dirent.h>
 #include <inttypes.h>
-#include <fnmatch.h>
-
-#include <pcre.h>
 
 #include <fcntl.h>
 #include <unistd.h>
@@ -71,19 +68,7 @@ typedef struct { /* both inclusive */
 #define RECT_W(r) ((r).br.x - (r).tl.x + 1)
 #define RECT_H(r) ((r).br.y - (r).tl.y + 1)
 
-
-
-#define DEBUG_FLAG_LIST                                \
-   DF(findypp)                                 \
-   DF(pages)                                   \
-   DF(rect)                                    \
-   DF(pixmap)                                  \
-   DF(struct)                                  \
-   DF(ocr)                                     \
-   DF(rsync)                                   \
-   DF(structcolon)                             \
-   DF(callout)
-
+#ifdef DEBUG_FLAG_LIST
 enum {
 #define DF(f) dbg__shift_##f,
   DEBUG_FLAG_LIST
@@ -94,17 +79,15 @@ enum {
   DEBUG_FLAG_LIST
 #undef DF
 };
+#define DEBUGP(f) (!!(debug_flags & dbg_##f))
 
-unsigned debug_flags;
+#endif /*DEBUG_FLAG_LIST*/
 
-#define DEBUGP(f) (!!(debug_flags & dbg_##f))
+extern unsigned debug_flags;
 
 void debug_flush(void);
 #define debug stderr
 
-const char *get_vardir(void);
-const char *get_libdir(void);
-
 #define FMT(f,a) __attribute__((format(printf,f,a)))
 #define SCANFMT(f,a) __attribute__((format(scanf,f,a)))
 #define NORET __attribute__((noreturn))
@@ -127,6 +110,20 @@ const char *get_libdir(void);
 
 /*---------- error handling ----------*/
 
+extern int o_quiet;
+
+void vwarning(const char *fmt, va_list) FMT(1,0);
+void warning(const char *fmt, ...)      FMT(1,2);
+
+void vprogress(const char *fmt, va_list) FMT(1,0);
+void progress(const char *fmt, ...)      FMT(1,2);
+
+void vprogress_log(const char *fmt, va_list) FMT(1,0);
+void progress_log(const char *fmt, ...)      FMT(1,2);
+
+void vprogress_spinner(const char *fmt, va_list) FMT(1,0);
+void progress_spinner(const char *fmt, ...)      FMT(1,2);
+
 void vfatal(const char *fmt, va_list)  FMT(1,0) NORET;
 void fatal(const char *fmt, ...)       FMT(1,2) NORET;
 
@@ -142,35 +139,8 @@ void waitpid_check_exitstatus(pid_t pid, const char *what, int sigpipeok);
 void *mmalloc(size_t sz);
 void *mrealloc(void *p, size_t sz);
 
-
-#define dbassert(x) ((x) ? (void)0 : dbfile_assertfail(__FILE__,__LINE__,#x))
-void dbfile_assertfail(const char *file, int line, const char *m) NORET;
-
-FILE *dbfile;
-void dbfile_getsline(char *lbuf, size_t lbufsz, const char *file, int line);
-int dbfile_open(const char *tpath);   /* 0: ENOENT; 1: worked */
-int dbfile_gzopen(const char *tpath); /* 0: ENOENT; 1: worked */
-void dbfile_close(void); /* idempotent */
-
-int dbfile_scanf(const char *fmt, ...) SCANFMT(1,2);
-int dbfile_vscanf(const char *fmt, va_list al) SCANFMT(1,0);
-
-int gzopen(const char *zpath, int oflags, FILE **f_r, pid_t *pid_r,
-          const char *gziplevel /* 0 for read; may be 0, or "-1" etc. */);
-  /* returns errno value from open */
-void gzclose(FILE **f, pid_t *p, const char *what);
-  /* also OK with f==0, or p==-1 */
-
 char *masprintf(const char *fmt, ...) FMT(1,2);
 
-#define EXECLP_HELPER(helper, ...) do{                         \
-    char *helper_path= masprintf("%s/%s",get_libdir(),helper); \
-    execlp(helper_path,helper, __VA_ARGS__);                   \
-    sysassert(errno==ENOENT);                                  \
-    fatal("Failed to find helper program %s.\n"                        \
-         "(Are you in the correct directory?)", helper);       \
-  }while(0)
-
 
 #define ARRAYSIZE(a) ((sizeof((a)) / sizeof((a)[0])))
 #define FILLZERO(obj) (memset(&(obj),0,sizeof((obj))))
index 4ba23b514d45a6363ab6336c9a37dcd3daed63a6..ce3ad0b49619f5517e9a5f0384d69535921b0fc0 100644 (file)
 
 #include "convert.h"
 
-void debug_flush(void) {
-  sysassert(!ferror(debug));
-  sysassert(!fflush(debug));
-}
-
 const char *get_vardir(void) { return "."; }
 const char *get_libdir(void) { return "."; }
 
@@ -412,118 +407,128 @@ int main(int argc, char **argv) {
 }
 
 
+FILE *dbfile;
+static const char *basepath; /* as passed in by caller */
+static pid_t dbzcat;
 
+int dbfile_gzopen(const char *basepath_spec) {
+  assert(!dbfile);
 
-DEFINE_VWRAPPERF(, progress, )
-DEFINE_VWRAPPERF(, progress_log, )
-DEFINE_VWRAPPERF(, progress_spinner, )
-DEFINE_VWRAPPERF(, warning, )
-DEFINE_VWRAPPERF(, fatal, NORET)
+  basepath= basepath_spec;
 
-static int last_progress_len;
-     
-static void vprogress_core(int spinner, const char *fmt, va_list al) {
-  int r;
-  
-  if (o_quiet) return;
-  if (!debug_flags && !isatty(2)) return;
+  char *zpath= masprintf("%s.gz", basepath);
+  int e= gzopen(zpath, O_RDONLY, &dbfile, &dbzcat, 0);
+  free(zpath);
+  if (e) { errno=e; sysassert(errno==ENOENT); return 0; }
   
-  if (last_progress_len)
-    putc('\r',stderr);
+  return 1;
+}  
 
-  r= vfprintf(stderr,fmt,al);
+int dbfile_open(const char *tpath) {
+  assert(!dbfile);
 
-  if (spinner) {
-    putc(spinner,stderr);
-    r++;
-  }
+  basepath= tpath;
 
-  if (r < last_progress_len) {
-    fprintf(stderr,"%*s", last_progress_len - r, "");
-    if (!r) putc('\r', stderr);
-    else while (last_progress_len-- > r) putc('\b',stderr);
-  }
-  last_progress_len= r;
+  dbzcat= -1;
+  dbfile= fopen(tpath,"r");
+  if (!dbfile) { sysassert(errno==ENOENT); return 0; }
+  return 1;
+}  
 
-  if (ferror(stderr) || fflush(stderr)) _exit(16);
-}
-   
-void vprogress(const char *fmt, va_list al) { vprogress_core(0,fmt,al); }
-void vprogress_spinner(const char *fmt, va_list al) {
-  static const char spinchars[]="/-\\";
-  static int spinner;
-
-  vprogress_core(spinchars[spinner],fmt,al);
-  spinner++;
-  spinner %= (sizeof(spinchars)-1);
+void dbfile_close(void) {
+  gzclose(&dbfile, &dbzcat, basepath);
 }
 
-void vprogress_log(const char *fmt, va_list al) {
-  if (o_quiet) return;
-  
-  progress("");
-  vfprintf(stderr,fmt,al);
-  putc('\n',stderr);
-  fflush(stderr);
+#define dbassertgl(x) ((x) ? (void)0 : dbfile_assertfail(file,line,#x))
+
+void dbfile_getsline(char *lbuf, size_t lbufsz, const char *file, int line) {
+  errno=0;
+  char *s= fgets(lbuf,lbufsz,dbfile);
+  sysassert(!ferror(dbfile));
+  dbassertgl(!feof(dbfile));
+  assert(s);
+  int l= strlen(lbuf);
+  dbassertgl(l>0);  dbassertgl(lbuf[--l]=='\n');
+  lbuf[l]= 0;
 }
 
-void vwarning(const char *fmt, va_list al) {
-  progress("");
-  fputs("Warning: ",stderr);
-  vfprintf(stderr,fmt,al);
-  fputs("\n",stderr);
-  fflush(stderr);
+int dbfile_vscanf(const char *fmt, va_list al) {
+  int r= vfscanf(dbfile,fmt,al);
+  sysassert(!ferror(dbfile));
+  return r;
 }
 
-void vfatal(const char *fmt, va_list al) {
-  progress("");
-  fputs("\n\nFatal error: ",stderr);
-  vfprintf(stderr,fmt,al);
-  fflush(stderr);
-  fputs("\n\n",stderr);
-  _exit(4);
+int dbfile_scanf(const char *fmt, ...) {
+  va_list al;
+  va_start(al,fmt);
+  int r= dbfile_vscanf(fmt,al);
+  va_end(al);
+  return r;
 }
 
-void sysassert_fail(const char *file, int line, const char *what) {
-  int e= errno;
-  progress("");
-  fprintf(stderr,
-         "\nfatal operational error:\n"
-         " unsuccessful execution of: %s\n"
-         " %s:%d: %s\n\n",
-         what, file,line, strerror(e));
-  _exit(16);
+void dbfile_assertfail(const char *file, int line, const char *m) {
+  if (dbzcat)
+    fatal("Error in dictionary file %s.gz:\n"
+         " Requirement not met at %s:%d:\n"
+         " %s",
+         basepath, file,line, m);
+  else if (dbfile)
+    fatal("Error in dictionary file %s at byte %ld:\n"
+         " Requirement not met at %s:%d:\n"
+         " %s",
+         basepath,(long)ftell(dbfile), file,line, m);
+  else
+    fatal("Semantic error in dictionaries:\n"
+         " Requirement not met at %s:%d:\n"
+         " %s",
+         file,line, m);
 }
 
-void waitpid_check_exitstatus(pid_t pid, const char *what, int sigpipeok) { 
-  pid_t got;
-  int st;
-  for (;;) {
-    got= waitpid(pid, &st, 0);
-    if (pid==-1) { sysassert(errno==EINTR); continue; }
-    break;
+int gzopen(const char *zpath, int oflags, FILE **f_r, pid_t *pid_r,
+          const char *gziplevel /* 0 for read; may be 0, or "-1" etc. */) {
+
+  int zfd= open(zpath, oflags, 0666);
+  if (zfd<0) return errno;
+
+  int pipefds[2];
+  sysassert(! pipe(pipefds) );
+
+  int oi,io; const char *cmd; const char *stdiomode;
+  switch ((oflags & O_ACCMODE)) {
+  case O_RDONLY: oi=0; io=1; cmd="gunzip"; stdiomode="r"; break;
+  case O_WRONLY: oi=1; io=0; cmd="gzip";   stdiomode="w"; break;
+  default: abort();
   }
-  sysassert( got==pid );
-
-  if (WIFEXITED(st)) {
-    if (WEXITSTATUS(st))
-      fatal("%s failed with nonzero exit status %d",
-           what, WEXITSTATUS(st));
-  } else if (WIFSIGNALED(st)) {
-    if (!sigpipeok || WTERMSIG(st) != SIGPIPE)
-      fatal("%s died due to signal %s%s", what,
-           strsignal(WTERMSIG(st)), WCOREDUMP(st)?" (core dumped)":"");
-  } else {
-    fatal("%s gave strange wait status %d", what, st);
+
+  sysassert( (*pid_r=fork()) != -1 );
+  if (!*pid_r) {
+    sysassert( dup2(zfd,oi)==oi );
+    sysassert( dup2(pipefds[io],io)==io );
+    sysassert(! close(zfd) );
+    sysassert(! close(pipefds[0]) );
+    sysassert(! close(pipefds[1]) );
+    execlp(cmd,cmd,gziplevel,(char*)0);
+    sysassert(!"execlp gzip/gunzip");
   }
+  sysassert(! close(zfd) );
+  sysassert(! close(pipefds[io]) );
+  sysassert( *f_r= fdopen(pipefds[oi], stdiomode) );
+
+  return 0;
 }
 
-char *masprintf(const char *fmt, ...) {
-  char *r;
-  va_list al;
-  va_start(al,fmt);
-  sysassert( vasprintf(&r,fmt,al) >= 0);
-  sysassert(r);
-  va_end(al);
-  return r;
+void gzclose(FILE **f, pid_t *p, const char *what) {
+  if (!*f) return;
+  
+  sysassert(!ferror(*f));
+  sysassert(!fclose(*f));
+
+  if (*p != -1) {
+    char *process= masprintf("%s (de)compressor",what);
+    waitpid_check_exitstatus(*p,process,1);
+    free(process);
+    *p= -1;
+  }
+
+  *f= 0;
 }
index fadfe931ea40a9880d933feee85c35bcdadba674..75f61793e8fb9b25434fefd17ce39ef46128998f 100644 (file)
 #ifndef CONVERT_H
 #define CONVERT_H
 
+#define DEBUG_FLAG_LIST                                \
+   DF(findypp)                                 \
+   DF(pages)                                   \
+   DF(rect)                                    \
+   DF(pixmap)                                  \
+   DF(struct)                                  \
+   DF(ocr)                                     \
+   DF(rsync)                                   \
+   DF(structcolon)                             \
+   DF(callout)
+
+
 #include "common.h"
 #include "ocr.h"
 
+#include <fnmatch.h>
+#include <pcre.h>
 #include <pam.h>
 #include <time.h>
 #include <limits.h>
@@ -93,18 +107,6 @@ extern FILE *screenshot_file;
 void fetch_with_rsync(const char *stem);
 void fetch_with_rsync_gz(const char *stem);
 
-void vwarning(const char *fmt, va_list) FMT(1,0);
-void warning(const char *fmt, ...)      FMT(1,2);
-
-void vprogress(const char *fmt, va_list) FMT(1,0);
-void progress(const char *fmt, ...)      FMT(1,2);
-
-void vprogress_log(const char *fmt, va_list) FMT(1,0);
-void progress_log(const char *fmt, ...)      FMT(1,2);
-
-void vprogress_spinner(const char *fmt, va_list) FMT(1,0);
-void progress_spinner(const char *fmt, ...)      FMT(1,2);
-
 enum flags {
   ff_singlepage=          000002,
   ff_testservers=         000004,
@@ -151,6 +153,39 @@ extern enum mode o_mode;
 extern const char *o_ocean, *o_pirate;
 extern int o_quiet;
 
+
+#define dbassert(x) ((x) ? (void)0 : dbfile_assertfail(__FILE__,__LINE__,#x))
+void dbfile_assertfail(const char *file, int line, const char *m) NORET;
+
+FILE *dbfile;
+void dbfile_getsline(char *lbuf, size_t lbufsz, const char *file, int line);
+int dbfile_open(const char *tpath);   /* 0: ENOENT; 1: worked */
+int dbfile_gzopen(const char *tpath); /* 0: ENOENT; 1: worked */
+void dbfile_close(void); /* idempotent */
+
+int dbfile_scanf(const char *fmt, ...) SCANFMT(1,2);
+int dbfile_vscanf(const char *fmt, va_list al) SCANFMT(1,0);
+
+int gzopen(const char *zpath, int oflags, FILE **f_r, pid_t *pid_r,
+          const char *gziplevel /* 0 for read; may be 0, or "-1" etc. */);
+  /* returns errno value from open */
+void gzclose(FILE **f, pid_t *p, const char *what);
+  /* also OK with f==0, or p==-1 */
+
+
+const char *get_vardir(void);
+const char *get_libdir(void);
+
+
+#define EXECLP_HELPER(helper, ...) do{                         \
+    char *helper_path= masprintf("%s/%s",get_libdir(),helper); \
+    execlp(helper_path,helper, __VA_ARGS__);                   \
+    sysassert(errno==ENOENT);                                  \
+    fatal("Failed to find helper program %s.\n"                        \
+         "(Are you in the correct directory?)", helper);       \
+  }while(0)
+
+
 /*----- from pages.c -----*/
 
 void screenshot_startup(void);
@@ -168,5 +203,4 @@ extern int npages;
 extern const char *ocean, *pirate;
 extern char *archipelago, *island;
 
-
 #endif /*CONVERT_H*/
index 08bc60c6b4c1efa3664bdcfd05faaca70faba1c2..e373fbc6dd924b7e4586bafc9279a4fadd046932 100644 (file)
@@ -25,7 +25,6 @@
  *  sponsored by Three Rings.
  */
 
-#include "ocr.h"
 #include "convert.h"
 
 typedef struct {
index 658bbdd71404bbc2bc2f61dbef9a30591050a860..871ee02e7e5cc494b82f71f8f95fac5e13483ee7 100644 (file)
@@ -1,11 +1,9 @@
 #ifndef RSCOMMON_H
 #define RSCOMMON_H
 
-#include <stdio.h>
-
 #include <sqlite3.h>
-#include <assert.h>
-#include <stdlib.h>
+
+#include "common.h"
 
 extern struct sqlite *db;
 
index 00e918e8aedbfe320bdd7628d35f35c694b66086..a60389c3672d67f4d6cd59c3474d40beb1b7ad63 100644 (file)
@@ -2,6 +2,8 @@
 
 #include "rscommon.h"
 
+int o_quiet= 0;
+
 int main(int argc, const char **argv) {
   int ia[argc], ni=0;
   const char *arg;