- int err = 0;
- char *val;
-
- /*
- * Macros to make argument handling easier. Note that because
- * they need to call `continue', they cannot be contained in
- * the usual do {...} while (0) wrapper to make them
- * syntactically single statements; hence it is not legal to
- * use one of these macros as an unbraced statement between
- * `if' and `else'.
- */
-#define EXPECTS_ARG { \
- if (--argc <= 0) { \
- err = 1; \
- fprintf(stderr, "%s: %s expects an argument\n", appname, p); \
- continue; \
- } else \
- val = *++argv; \
-}
-#define SECOND_PASS_ONLY { if (!do_everything) continue; }
-
- while (--argc > 0) {
- char *p = *++argv;
- int ret;
-
- /*
- * Shameless cheating. Debian requires all X terminal
- * emulators to support `-T title'; but
- * cmdline_process_param will eat -T (it means no-pty) and
- * complain that pterm doesn't support it. So, in pterm
- * only, we convert -T into -title.
- */
- if ((cmdline_tooltype & TOOLTYPE_NONNETWORK) &&
- !strcmp(p, "-T"))
- p = "-title";
-
- ret = cmdline_process_param(p, (argc > 1 ? argv[1] : NULL),
- do_everything ? 1 : -1, conf);
-
- if (ret == -2) {
- cmdline_error("option \"%s\" requires an argument", p);
- } else if (ret == 2) {
- --argc, ++argv; /* skip next argument */
- continue;
- } else if (ret == 1) {
- continue;
- }
-
- if (!strcmp(p, "-fn") || !strcmp(p, "-font")) {
- FontSpec *fs;
- EXPECTS_ARG;
- SECOND_PASS_ONLY;
- fs = fontspec_new(val);
- conf_set_fontspec(conf, CONF_font, fs);
- fontspec_free(fs);
-
- } else if (!strcmp(p, "-fb")) {
- FontSpec *fs;
- EXPECTS_ARG;
- SECOND_PASS_ONLY;
- fs = fontspec_new(val);
- conf_set_fontspec(conf, CONF_boldfont, fs);
- fontspec_free(fs);
-
- } else if (!strcmp(p, "-fw")) {
- FontSpec *fs;
- EXPECTS_ARG;
- SECOND_PASS_ONLY;
- fs = fontspec_new(val);
- conf_set_fontspec(conf, CONF_widefont, fs);
- fontspec_free(fs);
-
- } else if (!strcmp(p, "-fwb")) {
- FontSpec *fs;
- EXPECTS_ARG;
- SECOND_PASS_ONLY;
- fs = fontspec_new(val);
- conf_set_fontspec(conf, CONF_wideboldfont, fs);
- fontspec_free(fs);
-
- } else if (!strcmp(p, "-cs")) {
- EXPECTS_ARG;
- SECOND_PASS_ONLY;
- conf_set_str(conf, CONF_line_codepage, val);
-
- } else if (!strcmp(p, "-geometry")) {
- int flags, x, y;
- unsigned int w, h;
- EXPECTS_ARG;
- SECOND_PASS_ONLY;
-
- flags = XParseGeometry(val, &x, &y, &w, &h);
- if (flags & WidthValue)
- conf_set_int(conf, CONF_width, w);
- if (flags & HeightValue)
- conf_set_int(conf, CONF_height, h);
-
- if (flags & (XValue | YValue)) {
- inst->xpos = x;
- inst->ypos = y;
- inst->gotpos = TRUE;
- inst->gravity = ((flags & XNegative ? 1 : 0) |
- (flags & YNegative ? 2 : 0));
- }
-
- } else if (!strcmp(p, "-sl")) {
- EXPECTS_ARG;
- SECOND_PASS_ONLY;
- conf_set_int(conf, CONF_savelines, atoi(val));
-
- } else if (!strcmp(p, "-fg") || !strcmp(p, "-bg") ||
- !strcmp(p, "-bfg") || !strcmp(p, "-bbg") ||
- !strcmp(p, "-cfg") || !strcmp(p, "-cbg")) {
- GdkColor col;
-
- EXPECTS_ARG;
- SECOND_PASS_ONLY;
- if (!gdk_color_parse(val, &col)) {
- err = 1;
- fprintf(stderr, "%s: unable to parse colour \"%s\"\n",
- appname, val);
- } else {
- int index;
- index = (!strcmp(p, "-fg") ? 0 :
- !strcmp(p, "-bg") ? 2 :
- !strcmp(p, "-bfg") ? 1 :
- !strcmp(p, "-bbg") ? 3 :
- !strcmp(p, "-cfg") ? 4 :
- !strcmp(p, "-cbg") ? 5 : -1);
- assert(index != -1);
- conf_set_int_int(conf, CONF_colours, index*3+0, col.red / 256);
- conf_set_int_int(conf, CONF_colours, index*3+1,col.green/ 256);
- conf_set_int_int(conf, CONF_colours, index*3+2, col.blue/ 256);
- }
-
- } else if (use_pty_argv && !strcmp(p, "-e")) {
- /* This option swallows all further arguments. */
- if (!do_everything)
- break;
-
- if (--argc > 0) {
- int i;
- pty_argv = snewn(argc+1, char *);
- ++argv;
- for (i = 0; i < argc; i++)
- pty_argv[i] = argv[i];
- pty_argv[argc] = NULL;
- break; /* finished command-line processing */
- } else
- err = 1, fprintf(stderr, "%s: -e expects an argument\n",
- appname);
-
- } else if (!strcmp(p, "-title")) {
- EXPECTS_ARG;
- SECOND_PASS_ONLY;
- conf_set_str(conf, CONF_wintitle, val);
-
- } else if (!strcmp(p, "-log")) {
- Filename *fn;
- EXPECTS_ARG;
- SECOND_PASS_ONLY;
- fn = filename_from_str(val);
- conf_set_filename(conf, CONF_logfilename, fn);
- conf_set_int(conf, CONF_logtype, LGTYP_DEBUG);
- filename_free(fn);
-
- } else if (!strcmp(p, "-ut-") || !strcmp(p, "+ut")) {
- SECOND_PASS_ONLY;
- conf_set_int(conf, CONF_stamp_utmp, 0);
-
- } else if (!strcmp(p, "-ut")) {
- SECOND_PASS_ONLY;
- conf_set_int(conf, CONF_stamp_utmp, 1);
-
- } else if (!strcmp(p, "-ls-") || !strcmp(p, "+ls")) {
- SECOND_PASS_ONLY;
- conf_set_int(conf, CONF_login_shell, 0);
-
- } else if (!strcmp(p, "-ls")) {
- SECOND_PASS_ONLY;
- conf_set_int(conf, CONF_login_shell, 1);
-
- } else if (!strcmp(p, "-nethack")) {
- SECOND_PASS_ONLY;
- conf_set_int(conf, CONF_nethack_keypad, 1);
-
- } else if (!strcmp(p, "-sb-") || !strcmp(p, "+sb")) {
- SECOND_PASS_ONLY;
- conf_set_int(conf, CONF_scrollbar, 0);
-
- } else if (!strcmp(p, "-sb")) {
- SECOND_PASS_ONLY;
- conf_set_int(conf, CONF_scrollbar, 1);
-
- } else if (!strcmp(p, "-name")) {
- EXPECTS_ARG;
- app_name = val;
-
- } else if (!strcmp(p, "-xrm")) {
- EXPECTS_ARG;
- provide_xrm_string(val);
-
- } else if(!strcmp(p, "-help") || !strcmp(p, "--help")) {
- help(stdout);
- exit(0);
-
- } else if(!strcmp(p, "-version") || !strcmp(p, "--version")) {
- version(stdout);
- exit(0);
-
- } else if (!strcmp(p, "-pgpfp")) {
- pgp_fingerprints();
- exit(1);
-
- } else if(p[0] != '-' && (!do_everything ||
- process_nonoption_arg(p, conf,
- allow_launch))) {
- /* do nothing */
-
- } else {
- err = 1;
- fprintf(stderr, "%s: unrecognized option '%s'\n", appname, p);
- }
- }
-
- return err;
-}
-
-int uxsel_input_add(int fd, int rwx) {
- int flags = 0;
- if (rwx & 1) flags |= GDK_INPUT_READ;
- if (rwx & 2) flags |= GDK_INPUT_WRITE;
- if (rwx & 4) flags |= GDK_INPUT_EXCEPTION;
- assert(flags);
- return gdk_input_add(fd, flags, fd_input_func, NULL);
-}
-
-void uxsel_input_remove(int id) {
- gdk_input_remove(id);