diff --git a/mac/mac.c b/mac/mac.c index 54ed35ca..0abb3375 100644 --- a/mac/mac.c +++ b/mac/mac.c @@ -1,4 +1,4 @@ -/* $Id: mac.c,v 1.9 2002/12/29 19:14:56 ben Exp $ */ +/* $Id: mac.c,v 1.10 2002/12/30 18:21:17 ben Exp $ */ /* * Copyright (c) 1999 Ben Harris * All rights reserved. @@ -413,6 +413,9 @@ static void mac_menucommand(long result) { case iNew: mac_newsession(); goto done; + case iOpen: + mac_opensession(); + goto done; case iClose: mac_closewindow(window); goto done; diff --git a/mac/mac.h b/mac/mac.h index 626ca519..838c8285 100644 --- a/mac/mac.h +++ b/mac/mac.h @@ -6,6 +6,7 @@ #define PUTTY_MAC_H #include +#include #include #include #include @@ -25,21 +26,6 @@ extern struct mac_gestalts mac_gestalts; #define HAVE_COLOR_QD() (mac_gestalts.qdvers > gestaltOriginalQD) -/* from macterm.c */ -extern void mac_newsession(void); -extern void mac_activateterm(WindowPtr, Boolean); -extern void mac_adjusttermcursor(WindowPtr, Point, RgnHandle); -extern void mac_adjusttermmenus(WindowPtr); -extern void mac_updateterm(WindowPtr); -extern void mac_clickterm(WindowPtr, EventRecord *); -extern void mac_growterm(WindowPtr, EventRecord *); -extern void mac_keyterm(WindowPtr, EventRecord *); -extern void mac_menuterm(WindowPtr, short, short); -/* from maccfg.c */ -extern void mac_loadconfig(Config *); -/* from macnet.c */ -extern void macnet_eventcheck(void); - typedef struct { /* Config that created this session */ Config cfg; @@ -69,6 +55,26 @@ typedef struct { UnicodeToTextInfo uni_to_font; } Session; +/* from macterm.c */ +extern void mac_newsession(void); +extern void mac_opensession(void); +extern void mac_startsession(Session *); +extern void mac_activateterm(WindowPtr, Boolean); +extern void mac_adjusttermcursor(WindowPtr, Point, RgnHandle); +extern void mac_adjusttermmenus(WindowPtr); +extern void mac_updateterm(WindowPtr); +extern void mac_clickterm(WindowPtr, EventRecord *); +extern void mac_growterm(WindowPtr, EventRecord *); +extern void mac_keyterm(WindowPtr, EventRecord *); +extern void mac_menuterm(WindowPtr, short, short); +/* from macstore.c */ +OSErr get_session_dir(Boolean makeit, short *pVRefNum, long *pDirID); +extern void *open_settings_r_fsp(FSSpec *); +/* from maccfg.c */ +extern void mac_loadconfig(Config *); +/* from macnet.c */ +extern void macnet_eventcheck(void); + #endif /* diff --git a/mac/mac_res.r b/mac/mac_res.r index 984df167..a8c800ed 100644 --- a/mac/mac_res.r +++ b/mac/mac_res.r @@ -1,4 +1,4 @@ -/* $Id: mac_res.r,v 1.5 2002/12/30 14:17:51 ben Exp $ */ +/* $Id: mac_res.r,v 1.6 2002/12/30 18:21:17 ben Exp $ */ /* * Copyright (c) 1999 Ben Harris * All rights reserved. @@ -360,7 +360,7 @@ resource 'MENU' (mApple, preload) { enabled, apple, { - "About PuTTYÉ", noicon, nokey, nomark, plain, + "About PuTTY\0xc9", noicon, nokey, nomark, plain, "-", noicon, nokey, nomark, plain, } }; @@ -368,11 +368,12 @@ resource 'MENU' (mApple, preload) { resource 'MENU' (mFile, preload) { mFile, textMenuProc, - 0b11111111111111111111111111111011, + 0b11111111111111111111111111110111, enabled, - "File", + "Session", { - "New Session", noicon, "N", nomark, plain, + "New", noicon, "N", nomark, plain, + "Open\0xc9", noicon, "O", nomark, plain, "Close", noicon, "W", nomark, plain, "-", noicon, nokey, nomark, plain, "Quit", noicon, "Q", nomark, plain, diff --git a/mac/macresid.h b/mac/macresid.h index b98346b1..8013901f 100644 --- a/mac/macresid.h +++ b/mac/macresid.h @@ -1,4 +1,4 @@ -/* $Id: macresid.h,v 1.1 2002/11/19 02:13:46 ben Exp $ */ +/* $Id: macresid.h,v 1.2 2002/12/30 18:21:17 ben Exp $ */ /* * macresid.h -- Mac resource IDs @@ -20,8 +20,9 @@ #define iAbout 1 /* File menu */ #define iNew 1 -#define iClose 2 -#define iQuit 4 +#define iOpen 2 +#define iClose 3 +#define iQuit 5 /* Edit menu */ #define iUndo 1 #define iCut 3 diff --git a/mac/macstore.c b/mac/macstore.c index ecd0355b..fe1232e3 100644 --- a/mac/macstore.c +++ b/mac/macstore.c @@ -1,4 +1,4 @@ -/* $Id: macstore.c,v 1.5 2002/12/28 22:44:27 ben Exp $ */ +/* $Id: macstore.c,v 1.6 2002/12/30 18:21:17 ben Exp $ */ /* * macstore.c: Macintosh-specific impementation of the interface @@ -15,12 +15,12 @@ #include "putty.h" #include "storage.h" +#include "mac.h" #define PUTTY_CREATOR FOUR_CHAR_CODE('pTTY') #define SESS_TYPE FOUR_CHAR_CODE('Sess') -OSErr get_session_dir(Boolean makeit, short *pVRefNum, long *pDirID); OSErr FSpGetDirID(FSSpec *f, long *idp, Boolean makeit); /* @@ -191,21 +191,32 @@ void close_settings_w(void *handle) { safefree(handle); } -void *open_settings_r(char *sessionname) { +void *open_settings_r(char *sessionname) +{ short sessVRefNum; long sessDirID; FSSpec sessfile; OSErr error; Str255 psessionname; - int fd; - int *handle; error = get_session_dir(kDontCreateFolder, &sessVRefNum, &sessDirID); c2pstrcpy(psessionname, sessionname); error = FSMakeFSSpec(sessVRefNum, sessDirID, psessionname, &sessfile); if (error != noErr) goto out; - fd = FSpOpenResFile(&sessfile, fsRdPerm); + return open_settings_r_fsp(&sessfile); + + out: + return NULL; +} + +void *open_settings_r_fsp(FSSpec *sessfile) +{ + OSErr error; + int fd; + int *handle; + + fd = FSpOpenResFile(sessfile, fsRdPerm); if (fd == 0) {error = ResError(); goto out;} handle = safemalloc(sizeof *handle); @@ -216,7 +227,6 @@ void *open_settings_r(char *sessionname) { return NULL; } - char *read_setting_s(void *handle, char *key, char *buffer, int buflen) { int fd; Handle h; diff --git a/mac/macterm.c b/mac/macterm.c index 19ba7fa5..2e0f25d9 100644 --- a/mac/macterm.c +++ b/mac/macterm.c @@ -1,4 +1,4 @@ -/* $Id: macterm.c,v 1.25 2002/12/28 22:25:31 ben Exp $ */ +/* $Id: macterm.c,v 1.26 2002/12/30 18:21:17 ben Exp $ */ /* * Copyright (c) 1999 Simon Tatham * Copyright (c) 1999, 2002 Ben Harris @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,7 @@ #include "macresid.h" #include "putty.h" #include "mac.h" +#include "storage.h" #include "terminal.h" #define NCOLOURS (lenof(((Config *)0)->colours)) @@ -138,15 +140,45 @@ static void display_resource(Session *s, unsigned long type, short id) { void mac_newsession(void) { Session *s; - UInt32 starttime; - char msg[128]; /* This should obviously be initialised by other means */ s = smalloc(sizeof(*s)); memset(s, 0, sizeof(*s)); do_defaults(NULL, &s->cfg); s->back = &loop_backend; - + mac_startsession(s); +} + +void mac_opensession(void) { + Session *s; + StandardFileReply sfr; + static const OSType sftypes[] = { 'Sess', 0, 0, 0 }; + void *sesshandle; + + s = smalloc(sizeof(*s)); + memset(s, 0, sizeof(*s)); + + StandardGetFile(NULL, 1, sftypes, &sfr); + if (!sfr.sfGood) goto fail; + + sesshandle = open_settings_r_fsp(&sfr.sfFile); + if (sesshandle == NULL) goto fail; + load_open_settings(sesshandle, TRUE, &s->cfg); + close_settings_r(sesshandle); + s->back = &loop_backend; + mac_startsession(s); + return; + + fail: + sfree(s); + return; +} + +void mac_startsession(Session *s) +{ + UInt32 starttime; + char msg[128]; + /* XXX: Own storage management? */ if (HAVE_COLOR_QD()) s->window = GetNewCWindow(wTerminal, NULL, (WindowPtr)-1); diff --git a/putty.h b/putty.h index 0f2911c5..3ff9e9d1 100644 --- a/putty.h +++ b/putty.h @@ -465,6 +465,7 @@ void random_destroy_seed(void); */ void save_settings(char *section, 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); void get_sesslist(struct sesslist *, int allocate); void do_defaults(char *, Config *); void registry_cleanup(void); diff --git a/settings.c b/settings.c index ce21d2c2..0c642f50 100644 --- a/settings.c +++ b/settings.c @@ -321,11 +321,17 @@ void save_settings(char *section, int do_host, Config * cfg) void load_settings(char *section, int do_host, Config * cfg) { - int i; - char prot[10]; void *sesskey; sesskey = open_settings_r(section); + load_open_settings(sesskey, do_host, cfg); + close_settings_r(sesskey); +} + +void load_open_settings(void *sesskey, int do_host, Config *cfg) +{ + int i; + char prot[10]; cfg->ssh_subsys = 0; /* FIXME: load this properly */ cfg->remote_cmd_ptr = cfg->remote_cmd; @@ -637,8 +643,6 @@ void load_settings(char *section, int do_host, Config * cfg) gppi(sesskey, "ScrollbarOnLeft", 0, &cfg->scrollbar_on_left); gpps(sesskey, "BoldFont", "", cfg->boldfont, sizeof(cfg->boldfont)); gppi(sesskey, "ShadowBoldOffset", 1, &cfg->shadowboldoffset); - - close_settings_r(sesskey); } void do_defaults(char *session, Config * cfg)