chiark / gitweb /
count is count of offers
[ypp-sc-tools.web-live.git] / pctb / convert.c
index 291647e79f4c3930fec1d9ae7c9ccb45718f4695..75c70804df7b7d4632e9ee9967540f873c21d313 100644 (file)
@@ -47,11 +47,12 @@ static enum {
   mode_all=           0111,
 } o_mode= mode_all;
 
-static char *o_screenshots_fn;
+static char *o_screenshot_fn;
 static int o_single_page, o_quiet;
 static const char *o_outputmode= "upload";
 
-FILE *screenshots_file;
+const char *o_resolver;
+FILE *screenshot_file;
 
 
 static void vbadusage(const char *fmt, va_list) FMT(1,0) NORET;
@@ -63,11 +64,11 @@ static void vbadusage(const char *fmt, va_list al) {
 }
 DEFINE_VWRAPPERF(static, badusage, NORET);
 
-static void open_screenshots_file(const char *mode) {
-  screenshots_file= fopen(o_screenshots_fn, mode);
-  if (!screenshots_file)
+static void open_screenshot_file(const char *mode) {
+  screenshot_file= fopen(o_screenshot_fn, mode);
+  if (!screenshot_file)
     fatal("could not open screenshots file `%s': %s",
-         o_screenshots_fn, strerror(errno));
+         o_screenshot_fn, strerror(errno));
 }
 
 static void run_analysis(void) {
@@ -77,6 +78,10 @@ static void run_analysis(void) {
   progress("running recognition...");
   analyse(tf);
 
+  if (o_single_page && !strcmp(o_outputmode,"upload"))
+    fatal("Recognition successful, but refusing to upload partial data\n"
+         " (--single-page specified).  Specify an output mode?");
+
   sysassert( fseek(tf,0,SEEK_SET) == 0);
 
   progress_log("processing results (--%s)...", o_outputmode);
@@ -100,7 +105,7 @@ int main(int argc, char **argv) {
   int r;
 
 #define ARGVAL  ((*++argv) ? *argv : \
-                badusage("missing value for option %s",arg),(char*)0)
+                (badusage("missing value for option %s",arg),(char*)0))
 
   while ((arg=*++argv)) {
     if (!strcmp(arg,"--find-window-only"))
@@ -110,17 +115,23 @@ int main(int argc, char **argv) {
     else if (!strcmp(arg,"--analyse-only") ||
             !strcmp(arg,"--same"))
       o_mode= mode_analyse;
+    else if (!strcmp(arg,"--everything"))
+      o_mode= mode_all;
     else if (!strcmp(arg,"--single-page"))
       o_single_page= 1;
     else if (!strcmp(arg,"--quiet"))
       o_quiet= 1;
+    else if (!strcmp(arg,"--edit-charset"))
+      o_resolver= "./yppsc-ocr-resolver";
+    else if (!strcmp(arg,"--raw-tsv"))
+      o_outputmode= 0;
     else if (!strcmp(arg,"--upload") ||
             !strcmp(arg,"--arbitrage") ||
             !strcmp(arg,"--tsv") ||
             !strcmp(arg,"--best-prices"))
       o_outputmode= arg+2;
-    else if (!strcmp(arg,"--screenshots-file"))
-      o_screenshots_fn= ARGVAL;
+    else if (!strcmp(arg,"--screenshot-file"))
+      o_screenshot_fn= ARGVAL;
 #define DF(f)                                  \
     else if (!strcmp(arg,"-D" #f))             \
       debug_flags |= dbg_##f;
@@ -135,8 +146,8 @@ int main(int argc, char **argv) {
       badusage("unknown option `%s'",arg);
   }
   
-  if (!o_screenshots_fn) {
-    r= asprintf(&o_screenshots_fn,"%s/#pages#.ppm",get_vardir());
+  if (!o_screenshot_fn) {
+    r= asprintf(&o_screenshot_fn,"%s/#pages#.ppm",get_vardir());
     sysassert(r>=0);
   }
 
@@ -145,17 +156,20 @@ int main(int argc, char **argv) {
     find_yppclient_window();
   }
   if (o_mode & mf_screenshot) {
-    open_screenshots_file("w");
+    open_screenshot_file("w");
     if (o_single_page) take_one_screenshot();
     else take_screenshots();
   }
   if (o_mode & mf_readscreenshot) {
-    open_screenshots_file("r");
+    open_screenshot_file("r");
     if (o_single_page) read_one_screenshot();
     else read_screenshots();
   }
   if (o_mode & mf_analyse) {
-    run_analysis();
+    if (o_outputmode)
+      run_analysis();
+    else
+      analyse(stdout);
   }
   return 0;
 }