- WALK_UNTIL(mainr.tl, x,-1, whole.tl.x, '*');
- WALK_UNTIL(mainr.tl, y,-1, whole.tl.y, '*');
- WALK_UNTIL(mainr.br, x,+1, whole.br.x, '*');
- WALK_UNTIL(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);
-}
-
-static void load_image_and_canonify(void) {
- struct pam inpam;
- unsigned char rgb[3];
- int x,y,r;
- const CanonColourInfo *cci;
-
- pnm_readpaminit(stdin, &inpam, sizeof(inpam));
- height= inpam.height;
- width= inpam.width;
- eassert(inpam.maxval == 255);
- eassert(inpam.bytes_per_sample == 1);
-
- image= malloc(width*height);
- eassert(image);
- memset(image,'?',width*height);
-
- for (y=0; y<height; y++) {
- for (x=0; x<width; x++) {
- r= fread(&rgb,1,3,stdin); eassert(r==3);
- unsigned long rgb_l=
- ((unsigned long)rgb[0]<<16) |
- ((unsigned long)rgb[1]<<8) |
- (rgb[2]);
- for (cci=canoncolourinfos; cci->c; cci++)
- if (cci->rgb == rgb_l) {
- image[y*width + x]= cci->c;
- break;
- }
+ 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) {
+ if (o_flags & ff_printisland) {
+ o_outmode_kind= omk_none;
+ o_flags |= ff_singlepage;
+ } else {
+ o_outmode_kind= omk_str;
+ }
+ }
+
+ if (o_outmode_kind==omk_upload) {
+ o_flags |= ffs_upload;
+ o_outmode_str= "upload";