-static void debug_rect(const char *what, int whati, Rect rr) {
- int y,r,w;
- fprintf(debug, "%s %d: %d,%d..%d,%d:\n", what, whati,
- rr.tl.x,rr.tl.y, rr.br.x,rr.br.y);
- w= rr.br.x - rr.tl.x + 1;
- for (y=rr.tl.y; y<=rr.br.y; y++) {
- fprintf(debug, "%4d%*s|", y, rr.tl.x,"");
- r= fwrite(image + y*width + rr.tl.x, 1, w, debug);
- eassert(r==w);
- fputc('|',debug);
- fputc('\n',debug);
+int main(int argc, char **argv) {
+ const char *arg;
+
+ sysassert( setlocale(LC_MESSAGES,"") );
+ sysassert( setlocale(LC_CTYPE,"en_GB.UTF-8") ||
+ setlocale(LC_CTYPE,"en.UTF-8") );
+
+#define ARGVAL ((*++argv) ? *argv : \
+ (badusage("missing value for option %s",arg),(char*)0))
+
+#define IS(s) (!strcmp(arg,(s)))
+
+ while ((arg=*++argv)) {
+ if (IS("--find-window-only")) o_mode= mode_findwindow;
+ else if (IS("--screenshot-only")) o_mode= mode_screenshot;
+ else if (IS("--analyse-only") ||
+ IS("--same")) o_mode= mode_analyse;
+ else if (IS("--everything")) o_mode= mode_all;
+ else if (IS("--single-page")) o_flags |= ff_singlepage;
+ else if (IS("--quiet")) o_quiet= 1;
+ else if (IS("--edit-charset")) o_flags |= ff_editcharset;
+ else if (IS("--dict-local-only")) o_flags &= ~ffs_dict;
+ else if (IS("--dict-read-only")) o_flags &= (~ffs_dict | ff_dict_fetch);
+ else if (IS("--dict-anon")) o_flags &= ~ff_dict_pirate;
+ else if (IS("--dict-submit")) o_flags |= ff_dict_fetch|ff_dict_submit;
+ else if (IS("--upload") ||
+ IS("--arbitrage") ||
+ IS("--tsv") ||
+ IS("--best-prices")) o_outputmode= arg+2;
+ else if (IS("--raw-tsv")) o_outputmode= 0;
+ else if (IS("--screenshot-file")) o_screenshot_fn= ARGVAL;
+ else if (IS("--pctb-server")) o_serv_pctb= ARGVAL;
+ else if (IS("--dict-submit-server")) o_serv_dict_submit= ARGVAL;
+ else if (IS("--dict-update-server")) o_serv_dict_fetch= ARGVAL;
+#define DF(f) \
+ else if (IS("-D" #f)) \
+ debug_flags |= dbg_##f;
+ DEBUG_FLAG_LIST
+#undef DF
+ else if (IS("--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);
+ }
+
+ /* Consequential changes to options */
+
+ if (!strcmp("upload",o_outputmode))
+ o_flags |= ffs_upload;
+
+ /* Defaults */
+
+ set_server("YPPSC_PCTB_PCTB",
+ "http://", "pctb.ilk.org",
+ o_serv_pctb, o_flags & (ff_needisland|ff_upload));
+
+ set_server("YPPSC_PCTB_DICT_UPDATE",
+ "rsync://", "rsync.pctb.chiark.greenend.org.uk/pctb",
+ o_serv_dict_fetch, o_flags & ff_dict_fetch);
+
+ set_server("YPPSC_PCTB_DICT_SUBMIT",
+ "http://", "dictup.pctb.chiark.greenend.org.uk",
+ o_serv_dict_submit, o_flags & ff_dict_submit);
+
+ if (!o_screenshot_fn)
+ o_screenshot_fn= masprintf("%s/#pages#.ppm",get_vardir());
+
+ /* Actually do the work */
+
+ if (o_mode & mf_findwindow) {
+ screenshot_startup();
+ find_yppclient_window();
+ }
+ if (o_mode & mf_screenshot) {
+ open_screenshot_file("w");
+ if (o_flags & ff_singlepage) take_one_screenshot();
+ else take_screenshots();