savedsession[0] = '\0';
}
}
- save_settings(savedsession, !isdef, cfg);
+ {
+ char *errmsg = save_settings(savedsession, !isdef, cfg);
+ if (errmsg) {
+ dlg_error_msg(dlg, errmsg);
+ sfree(errmsg);
+ }
+ }
get_sesslist(ssd->sesslist, FALSE);
get_sesslist(ssd->sesslist, TRUE);
dlg_refresh(ssd->editbox, dlg);
-/* $Id: macstore.c,v 1.18 2003/03/29 23:07:55 ben Exp $ */
+/* $Id: macstore.c,v 1.19 2003/04/01 18:10:25 simon Exp $ */
/*
* macstore.c: Macintosh-specific impementation of the interface
FSSpec dstfile;
};
-void *open_settings_w(char const *sessionname) {
+void *open_settings_w(char const *sessionname, char **errmsg) {
short sessVRefNum;
long sessDirID;
OSErr error;
Str255 psessionname;
FSSpec dstfile;
-
+
+ *errmsg = NULL;
+
error = get_session_dir(kCreateFolder, &sessVRefNum, &sessDirID);
if (error != noErr) return NULL;
/*
* Exports from settings.c.
*/
-void save_settings(char *section, int do_host, Config * cfg);
+char *save_settings(char *section, int do_host, Config * cfg);
void save_open_settings(void *sesskey, int do_host, Config *cfg);
void load_settings(char *section, int do_host, Config * cfg);
void load_open_settings(void *sesskey, int do_host, Config *cfg);
write_setting_s(sesskey, name, buf);
}
-void save_settings(char *section, int do_host, Config * cfg)
+char *save_settings(char *section, int do_host, Config * cfg)
{
void *sesskey;
+ char *errmsg;
- sesskey = open_settings_w(section);
+ sesskey = open_settings_w(section, &errmsg);
if (!sesskey)
- return;
+ return errmsg;
save_open_settings(sesskey, do_host, cfg);
close_settings_w(sesskey);
+ return NULL;
}
void save_open_settings(void *sesskey, int do_host, Config *cfg)
* A given key will be written at most once while saving a session.
* Keys may be up to 255 characters long. String values have no length
* limit.
+ *
+ * Any returned error message must be freed after use.
*/
-void *open_settings_w(const char *sessionname);
+void *open_settings_w(const char *sessionname, char **errmsg);
void write_setting_s(void *handle, const char *key, const char *value);
void write_setting_i(void *handle, const char *key, int value);
void write_setting_filename(void *handle, const char *key, Filename value);
*/
}
-void fatalbox(char *p, ...)
+void fatal_message_box(void *window, char *msg)
{
- va_list ap;
- char *msg;
- va_start(ap, p);
- msg = dupvprintf(p, ap);
- va_end(ap);
- messagebox(NULL, "PuTTY Fatal Error", msg,
+ messagebox(window, "PuTTY Fatal Error", msg,
string_width("REASONABLY LONG LINE OF TEXT FOR BASIC SANITY"),
"OK", 'o', 1, 1, NULL);
- sfree(msg);
- cleanup_exit(1);
}
-void connection_fatal(void *frontend, char *p, ...)
+
+void fatalbox(char *p, ...)
{
va_list ap;
char *msg;
va_start(ap, p);
msg = dupvprintf(p, ap);
va_end(ap);
- messagebox(GTK_WIDGET(get_window(frontend)),
- "PuTTY Fatal Error", msg,
- string_width("REASONABLY LONG LINE OF TEXT FOR BASIC SANITY"),
- "OK", 'o', 1, 1, NULL);
+ fatal_message_box(NULL, msg);
sfree(msg);
cleanup_exit(1);
}
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)
uxsel_init();
+ term_size(inst->term, inst->cfg.height, inst->cfg.width, inst->cfg.savelines);
+
inst->back = select_backend(&inst->cfg);
{
- char *realhost;
-
- 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);
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 */
*/
#include <stdio.h>
+#include <stdlib.h>
#include "putty.h"
return 1; /* no-op in pterm */
}
+void fatal_message_box(void *window, char *msg)
+{
+ /* also a no-op in pterm */
+}
+
+void cleanup_exit(int code)
+{
+ exit(code);
+}
+
int process_nonoption_arg(char *arg, Config *cfg)
{
return 0; /* pterm doesn't have any. */
/* Things gtkdlg.c needs from pterm.c */
void *get_window(void *frontend); /* void * to avoid depending on gtk.h */
+/* Things pterm.c needs from gtkdlg.c */
+void fatal_message_box(void *window, char *msg);
+
/* Things pterm.c needs from {ptermm,uxputty}.c */
char *make_default_wintitle(char *hostname);
int process_nonoption_arg(char *arg, Config *cfg);
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <assert.h>
+#include <errno.h>
#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
* file somewhere or other.
*/
-void *open_settings_w(const char *sessionname)
+void *open_settings_w(const char *sessionname, char **errmsg)
{
char filename[FILENAME_MAX];
FILE *fp;
+ *errmsg = NULL;
+
/*
- * Start by making sure the sessions subdir exists. Ignore the
- * error return from mkdir since it's perfectly likely to be
- * `already exists', and any other error will trip us up later
- * on so there's no real need to catch it now.
+ * Start by making sure the .putty directory and its sessions
+ * subdir actually exist. Ignore error returns from mkdir since
+ * they're perfectly likely to be `already exists', and any
+ * other error will trip us up later on so there's no real need
+ * to catch it now.
*/
+ make_filename(filename, INDEX_DIR, sessionname);
+ mkdir(filename, 0700);
make_filename(filename, INDEX_SESSIONDIR, sessionname);
mkdir(filename, 0700);
make_filename(filename, INDEX_SESSION, sessionname);
fp = fopen(filename, "w");
- if (!fp)
- return NULL; /* can't open */
+ if (!fp) {
+ *errmsg = dupprintf("Unable to create %s: %s",
+ filename, strerror(errno));
+ return NULL; /* can't open */
+ }
return fp;
}
return;
}
-void *open_settings_w(const char *sessionname)
+void *open_settings_w(const char *sessionname, char **errmsg)
{
HKEY subkey1, sesskey;
int ret;
char *p;
+ *errmsg = NULL;
+
if (!sessionname || !*sessionname)
sessionname = "Default Settings";
ret = RegCreateKey(HKEY_CURRENT_USER, puttystr, &subkey1);
if (ret != ERROR_SUCCESS) {
sfree(p);
+ *errmsg = dupprintf("Unable to create registry key\n"
+ "HKEY_CURRENT_USER%s", puttystr);
return NULL;
}
ret = RegCreateKey(subkey1, p, &sesskey);
sfree(p);
RegCloseKey(subkey1);
- if (ret != ERROR_SUCCESS)
+ if (ret != ERROR_SUCCESS) {
+ *errmsg = dupprintf("Unable to create registry key\n"
+ "HKEY_CURRENT_USER%s\\%s", puttystr, p);
return NULL;
+ }
return (void *) sesskey;
}