+
+static void run_analysis(void) {
+ FILE *tf;
+
+ sysassert( tf= tmpfile() );
+ 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);
+ pid_t processor;
+ sysassert( (processor= fork()) != -1 );
+
+ if (!processor) {
+ sysassert( dup2(fileno(tf),0) ==0 );
+ execlp("./yppsc-commod-processor", "yppsc-commod-processor",
+ o_outputmode, (char*)0);
+ sysassert(!"execlp commod-processor failed");
+ }
+
+ waitpid_check_exitstatus(processor, "output processor/uploader");
+ fclose(tf);
+ progress_log("all complete.");
+}
+
+int main(int argc, char **argv) {
+ const char *arg;
+ int r;
+
+#define ARGVAL ((*++argv) ? *argv : \
+ (badusage("missing value for option %s",arg),(char*)0))
+
+ while ((arg=*++argv)) {
+ if (!strcmp(arg,"--find-window-only"))
+ o_mode= mode_findwindow;
+ else if (!strcmp(arg,"--screenshot-only"))
+ o_mode= mode_screenshot;
+ 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,"--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,"--screenshot-file"))
+ o_screenshot_fn= ARGVAL;
+#define DF(f) \
+ else if (!strcmp(arg,"-D" #f)) \
+ debug_flags |= dbg_##f;
+ DEBUG_FLAG_LIST
+#undef DF
+ else if (!strcmp(arg,"--window-id")) {
+ char *ep;
+ unsigned long windowid= strtoul(ARGVAL,&ep,0);
+ if (*ep) badusage("invalid window id");
+ set_yppclient_window(windowid);
+ } else
+ badusage("unknown option `%s'",arg);
+ }
+
+ if (!o_screenshot_fn) {
+ r= asprintf(&o_screenshot_fn,"%s/#pages#.ppm",get_vardir());
+ sysassert(r>=0);
+ }
+
+ if (o_mode & mf_findwindow) {
+ screenshot_startup();
+ find_yppclient_window();
+ }
+ if (o_mode & mf_screenshot) {
+ open_screenshot_file("w");
+ if (o_single_page) take_one_screenshot();
+ else take_screenshots();
+ }
+ if (o_mode & mf_readscreenshot) {
+ open_screenshot_file("r");
+ if (o_single_page) read_one_screenshot();
+ else read_screenshots();
+ }
+ if (o_mode & mf_analyse) {
+ if (o_outputmode)
+ run_analysis();
+ else
+ analyse(stdout);
+ }