return XGetDefault(GDK_DISPLAY(), app_name, key);
}
+void connection_fatal(void *frontend, char *p, ...)
+{
+ Terminal *term = (Terminal *)frontend;
+ struct gui_data *inst = (struct gui_data *)term->frontend;
+
+ va_list ap;
+ char *msg;
+ va_start(ap, p);
+ msg = dupvprintf(p, ap);
+ va_end(ap);
+ inst->exited = TRUE;
+ fatal_message_box(inst->window, msg);
+ sfree(msg);
+ if (inst->cfg.close_on_exit == FORCE_ON)
+ cleanup_exit(1);
+}
+
/*
* Default settings that are specific to pterm.
*/
struct gui_data *inst = (struct gui_data *)data;
int exitcode;
- if ((exitcode = inst->back->exitcode(inst->backhandle)) >= 0) {
+ if (!inst->exited &&
+ (exitcode = inst->back->exitcode(inst->backhandle)) >= 0) {
inst->exited = TRUE;
if (inst->cfg.close_on_exit == FORCE_ON ||
(inst->cfg.close_on_exit == AUTO && exitcode == 0))
void fd_input_func(gpointer data, gint sourcefd, GdkInputCondition condition)
{
- select_result(sourcefd,
- (condition == GDK_INPUT_READ ? 1 :
- condition == GDK_INPUT_WRITE ? 2 :
- condition == GDK_INPUT_EXCEPTION ? 4 : -1));
+ /*
+ * We must process exceptional notifications before ordinary
+ * readability ones, or we may go straight past the urgent
+ * marker.
+ */
+ if (condition & GDK_INPUT_EXCEPTION)
+ select_result(sourcefd, 4);
+ if (condition & GDK_INPUT_READ)
+ select_result(sourcefd, 1);
+ if (condition & GDK_INPUT_WRITE)
+ select_result(sourcefd, 2);
}
void destroy(GtkWidget *widget, gpointer data)
exit(1);
}
+void cmdline_error(char *p, ...)
+{
+ va_list ap;
+ fprintf(stderr, "plink: ");
+ va_start(ap, p);
+ vfprintf(stderr, p, ap);
+ va_end(ap);
+ fputc('\n', stderr);
+ exit(1);
+}
+
char *get_x_display(void *frontend)
{
return gdk_get_display();
char *val;
while (--argc > 0) {
char *p = *++argv;
+ int ret;
+
+ ret = cmdline_process_param(p, (argc > 1 ? argv[1] : NULL),
+ do_everything ? 1 : -1, cfg);
+
+ 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")) {
EXPECTS_ARG;
SECOND_PASS_ONLY;
help(stdout);
exit(0);
+ } else if(p[0] != '-' && (!do_everything ||
+ process_nonoption_arg(p, cfg))) {
+ /* do nothing */
+
} else {
err = 1;
fprintf(stderr, "pterm: unrecognized option '%s'\n", p);
if (do_cmdline(argc, argv, 1, &inst->cfg))
exit(1); /* post-defaults, do everything */
- if (!cfgbox(&inst->cfg))
+ cmdline_run_saved(&inst->cfg);
+
+ if (!*inst->cfg.host && !cfgbox(&inst->cfg))
exit(0); /* config box hit Cancel */
inst->fonts[0] = gdk_font_load(inst->cfg.font.name);
inst->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- if (inst->cfg.wintitle[0])
- set_title(inst, inst->cfg.wintitle);
- else
- set_title(inst, "pterm");
-
/*
* Set up the colour map.
*/
uxsel_init();
+ term_size(inst->term, inst->cfg.height, inst->cfg.width, inst->cfg.savelines);
+
inst->back = select_backend(&inst->cfg);
{
- char *realhost; /* FIXME: don't ignore this! */
- inst->back->init((void *)inst->term, &inst->backhandle, &inst->cfg,
- inst->cfg.host, inst->cfg.port, &realhost,
- inst->cfg.tcp_nodelay);
+ char *realhost, *error;
+
+ error = inst->back->init((void *)inst->term, &inst->backhandle,
+ &inst->cfg, inst->cfg.host, inst->cfg.port,
+ &realhost, inst->cfg.tcp_nodelay);
+
+ if (error) {
+ char *msg = dupprintf("Unable to open connection to %s:\n%s",
+ inst->cfg.host, error);
+ inst->exited = TRUE;
+ fatal_message_box(inst->window, msg);
+ sfree(msg);
+ return 0;
+ }
+
+ if (inst->cfg.wintitle[0])
+ set_title(inst, inst->cfg.wintitle);
+ else {
+ char *title = make_default_wintitle(realhost);
+ set_title(inst, title);
+ sfree(title);
+ }
}
inst->back->provide_logctx(inst->backhandle, inst->logctx);
term_provide_resize_fn(inst->term, inst->back->size, inst->backhandle);
- term_size(inst->term, inst->cfg.height, inst->cfg.width, inst->cfg.savelines);
-
inst->ldisc =
ldisc_create(&inst->cfg, inst->term, inst->back, inst->backhandle, inst);
ldisc_send(inst->ldisc, NULL, 0, 0);/* cause ldisc to notice changes */