-static void help(FILE *fp) {
- if(fprintf(fp,
-"pterm option summary:\n"
-"\n"
-" --display DISPLAY Specify X display to use (note '--')\n"
-" -name PREFIX Prefix when looking up resources (default: pterm)\n"
-" -fn FONT Normal text font\n"
-" -fb FONT Bold text font\n"
-" -geometry GEOMETRY Position and size of window (size in characters)\n"
-" -sl LINES Number of lines of scrollback\n"
-" -fg COLOUR, -bg COLOUR Foreground/background colour\n"
-" -bfg COLOUR, -bbg COLOUR Foreground/background bold colour\n"
-" -cfg COLOUR, -bfg COLOUR Foreground/background cursor colour\n"
-" -T TITLE Window title\n"
-" -ut, +ut Do(default) or do not update utmp\n"
-" -ls, +ls Do(default) or do not make shell a login shell\n"
-" -sb, +sb Do(default) or do not display a scrollbar\n"
-" -log PATH Log all output to a file\n"
-" -nethack Map numeric keypad to hjklyubn direction keys\n"
-" -xrm RESOURCE-STRING Set an X resource\n"
-" -e COMMAND [ARGS...] Execute command (consumes all remaining args)\n"
- ) < 0 || fflush(fp) < 0) {
- perror("output error");
- exit(1);
- }
-}
-
-static void version(FILE *fp) {
- if(fprintf(fp, "%s: %s\n", appname, ver) < 0 || fflush(fp) < 0) {
- perror("output error");
- exit(1);
- }
-}
-
-int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch,
- struct gui_data *inst, Conf *conf)
-{
- 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) {
- const 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")) {
- EXPECTS_ARG;
- SECOND_PASS_ONLY;
-
-#if GTK_CHECK_VERSION(2,0,0)
- inst->geometry = val;
-#else
- /* On GTK 1, we have to do this using raw Xlib */
- {
- int flags, x, y;
- unsigned int w, h;
- 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));
- }
- }
-#endif
-
- } 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")) {
- EXPECTS_ARG;
- SECOND_PASS_ONLY;
-
- {
-#if GTK_CHECK_VERSION(3,0,0)
- GdkRGBA rgba;
- int success = gdk_rgba_parse(&rgba, val);
-#else
- GdkColor col;
- int success = gdk_color_parse(val, &col);
-#endif
-
- if (!success) {
- err = 1;
- fprintf(stderr, "%s: unable to parse colour \"%s\"\n",
- appname, val);
- } else {
-#if GTK_CHECK_VERSION(3,0,0)
- int r = rgba.red * 255;
- int g = rgba.green * 255;
- int b = rgba.blue * 255;
-#else
- int r = col.red / 256;
- int g = col.green / 256;
- int b = col.blue / 256;
-#endif
-
- 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, r);
- conf_set_int_int(conf, CONF_colours, index*3+1, g);
- conf_set_int_int(conf, CONF_colours, index*3+2, b);
- }
- }
-
- } 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;
-}
-
-struct uxsel_id {
-#if GTK_CHECK_VERSION(2,0,0)
- GIOChannel *chan;
- guint watch_id;
-#else
- int id;
-#endif
-};
-
-uxsel_id *uxsel_input_add(int fd, int rwx) {
- uxsel_id *id = snew(uxsel_id);
-
-#if GTK_CHECK_VERSION(2,0,0)
- int flags = 0;
- if (rwx & 1) flags |= G_IO_IN;
- if (rwx & 2) flags |= G_IO_OUT;
- if (rwx & 4) flags |= G_IO_PRI;
- id->chan = g_io_channel_unix_new(fd);
- g_io_channel_set_encoding(id->chan, NULL, NULL);
- id->watch_id = g_io_add_watch(id->chan, flags, fd_input_func, NULL);
-#else
- 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);
- id->id = gdk_input_add(fd, flags, fd_input_func, NULL);
-#endif
-
- return id;
-}
-
-void uxsel_input_remove(uxsel_id *id) {
-#if GTK_CHECK_VERSION(2,0,0)
- g_source_remove(id->watch_id);
- g_io_channel_unref(id->chan);
-#else
- gdk_input_remove(id->id);
-#endif
- sfree(id);
-}
-