-#define WALK_UNTIL_MUST(point,coord,increm,last,edge) \
- do { \
- WALK_UNTIL(point,coord,increm,last,edge); \
- eassert((point).coord != (last)+(increm)); \
- } while(0)
-
-static void find_structure(void) {
- Rect whole = { {0,0}, {cim->w-1,cim->h-1} };
-
- WALK_UNTIL_MUST(mainr.tl, x,-1, whole.tl.x, '*');
- WALK_UNTIL_MUST(mainr.tl, y,-1, whole.tl.y, '*');
- WALK_UNTIL_MUST(mainr.br, x,+1, whole.br.x, '*');
- WALK_UNTIL_MUST(mainr.br, y,+1, whole.br.y, '*');
-
- require_rectangle(mainr.tl.x-1, mainr.tl.y, mainr.tl.x-1, mainr.br.y, "*");
- require_rectangle(mainr.br.x+1, mainr.tl.y, mainr.br.x+1, mainr.br.y, "*");
- require_rectangle(mainr.tl.x, mainr.tl.y-1, mainr.br.x, mainr.tl.y-1, "*");
- require_rectangle(mainr.tl.x, mainr.br.y+1, mainr.br.x, mainr.br.y+1, "*");
-
-#define CHECK_STRIP_BORDER(tlbr,xy,increm) \
- do { \
- Point csb_p; \
- Rect csb_r; \
- csb_p= mainr.tl; \
- csb_p.xy= mainr.tlbr.xy; \
- if (get_p(csb_p)=='+') { \
- csb_r= mainr; \
- csb_r.tl.xy= csb_p.xy; \
- csb_r.br.xy= csb_p.xy; \
- require_rectangle_r(csb_r, "+"); \
- mainr.tlbr.xy += increm; \
- } \
- } while(0)
-
- debug_rect("mainr",0, mainr);
-
- CHECK_STRIP_BORDER(tl,x,+1);
- CHECK_STRIP_BORDER(tl,y,+1);
- CHECK_STRIP_BORDER(br,x,-1);
- CHECK_STRIP_BORDER(br,y,-1);
-
- debug_rect("mainr",1, mainr);
-
- Point up = START_MAIN;
- WALK_UNTIL_MUST(up, y,-1, mainr.tl.y, '+');
-
- Point down = START_MAIN;
- down.y++;
- WALK_UNTIL_MUST(down, y,+1, mainr.br.y, '+');
-
-#ifdef DEBUG_RECTANGLES
- int xscaleunit, y,x;
- for (y=0, xscaleunit=1; y<4; y++, xscaleunit*=10) {
- fprintf(debug," ");
- for (x=0; x<=cim->w; x++) {
- if (x % xscaleunit) fputc(' ',debug);
- else fprintf(debug,"%d",(x / xscaleunit)%10);
+ waitpid_check_exitstatus(fetcher, "rsync");
+}
+
+static void set_server(const char *envname, const char *defprotocol,
+ const char *defvalue, const char *defvalue_test,
+ const char *userspecified,
+ int enable) {
+ const char *value;
+
+ if (!enable) { value= "0"; goto ok; }
+
+ if (userspecified)
+ value= userspecified;
+ else if ((value= getenv(envname)))
+ ;
+ else if (o_flags & ff_testservers)
+ value= defvalue_test;
+ else
+ value= defvalue;
+
+ if (value[0]=='/' || (value[0]=='.' && value[1]=='/'))
+ /* absolute or relative pathname - or anyway, something with no hostname */
+ goto ok;
+
+ const char *colon= strchr(value, ':');
+ const char *slash= strchr(value, '/');
+
+ if (colon && (!slash || colon < slash))
+ /* colon before the first slash, if any */
+ /* rsync :: protocol specification - anyway, adding scheme:// won't help */
+ goto ok;
+
+ int vallen= strlen(value);
+
+ value= masprintf("%s%s%s", defprotocol, value,
+ vallen && value[vallen-1]=='/' ? "" : "/");
+
+ ok:
+ sysassert(! setenv(envname,value,1) );
+}
+
+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("--find-island")) o_flags |= ffs_printisland;
+ 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("--test-servers")) o_flags |= ff_testservers;
+ 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("--raw-tsv")) o_outmode_kind= omk_raw;
+ else if (IS("--upload")) o_outmode_kind= omk_upload;
+ else if (IS("--arbitrage") ||
+ IS("--tsv") ||
+ IS("--best-prices")) o_outmode_kind=omk_str,
+ o_outmode_str=arg+2;
+
+ 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;
+ else if (IS("--ocean")) o_ocean= ARGVAL;
+ else if (IS("--pirate")) o_pirate= 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 (o_mode & mf_analyse) {
+ if (!o_outmode_kind)
+ o_outmode_kind= (o_flags & ff_printisland) ? omk_none : omk_str;
+
+ if (o_outmode_kind==omk_upload) {
+ o_flags |= ffs_upload;
+ o_outmode_str= "upload";