+void fetch_with_rsync_gz(const char *stem) { rsync_core(stem,".gz",""); }
+void fetch_with_rsync(const char *stem) { rsync_core(stem,"","z"); }
+
+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("--show-charset")) o_mode= mode_showcharset;
+ 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_charset_edit;
+ else if (IS("--no-edit-charset")) o_flags &= ~(ffm_charset);
+ 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")||
+ IS("--screenshots-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);