From ec5da3100dcef76794f5ef028f0f822f509bb832 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 26 Feb 2005 13:37:07 +0000 Subject: [PATCH] Sort out close-on-exit, connection_fatal(), fatalbox(), and [SessionWindow dealloc] (which was required in order to avoid segfaulting when a redraw timer fired for a closed session window!). git-svn-id: svn://svn.tartarus.org/sgt/putty@5400 cda61777-01e9-0310-a592-d414129be87e --- macosx/README.OSX | 35 +++++++++++++++++++++++----------- macosx/osxclass.h | 3 +++ macosx/osxdlg.m | 24 +++++++++++++++++++++-- macosx/osxmain.m | 43 +++++++++++++++++++++++++++++------------ macosx/osxwin.m | 57 +++++++++++++++++++++++++++++++++++++++---------------- 5 files changed, 121 insertions(+), 41 deletions(-) diff --git a/macosx/README.OSX b/macosx/README.OSX index 8d989a63..0e05dba7 100644 --- a/macosx/README.OSX +++ b/macosx/README.OSX @@ -18,10 +18,10 @@ say you weren't warned! Other ways in which the port is currently unfinished include: - - terminal display is horribly slow +Missing terminal window features +-------------------------------- - - fatal errors are currently output via printf, which is obviously - wrong for a GUI application + - terminal display is horribly slow - fonts aren't configurable @@ -38,32 +38,45 @@ Other ways in which the port is currently unfinished include: starting position, plus remembering previous window positions per the Apple HIG) is not implemented - - close-on-exit isn't implemented +Missing alert box features +-------------------------- - warn-on-close isn't implemented - - SessionWindow's dealloc method does nothing yet, so leaks memory +Missing input features +---------------------- - use of Alt+numberpad to enter arbitrary numeric character codes is not yet supported - cut and paste isn't supported - - there's no Meta key yet. (I think it will have to be Command - rather than Option since the latter is necessary to send some - characters, including the rather important # on Apple UK - keyboards; but trapping Command- and sending it to the - window rather than the application menu requires me to make a - positive effort of some sort and I haven't got round to it yet.) + - there's no Meta key yet. (I'd like to at least have the + possibility of using Command rather than Option as the Meta key, + since the latter is necessary to send some characters, including + the rather important # on Apple UK keyboards; but trapping + Command- and sending it to the window rather than the + application menu requires me to make a positive effort of some + sort and I haven't got round to it yet. For those Mac users who + consider their Command key sacrosanct, don't worry, this option + _will_ be configurable and _will_ be off by default.) - there's no specials menu +Missing terminal emulation features +----------------------------------- + - currently no support for server-side window management requests (i.e. escape sequences to minimise or maximise the window, request or change its position and size, change its title etc) - window title is currently fixed +Other missing features +---------------------- + + - SessionWindow's dealloc method does nothing yet, so leaks memory + - no Event Log - no mid-session Change Settings diff --git a/macosx/osxclass.h b/macosx/osxclass.h index 2e4d1dec..c52ef14a 100644 --- a/macosx/osxclass.h +++ b/macosx/osxclass.h @@ -47,6 +47,7 @@ struct alert_queue { void *ldisc; Backend *back; void *backhandle; + int exited; /* * The following two members relate to the currently active * alert sheet, if any. They are NULL if there isn't one. @@ -65,6 +66,8 @@ struct alert_queue { - (int)fromBackend:(const char *)data len:(int)len isStderr:(int)is_stderr; - (void)startAlert:(NSAlert *)alert withCallback:(void (*)(void *, int))callback andCtx:(void *)ctx; +- (void)endSession:(int)clean; +- (void)notifyRemoteExit; @end /* diff --git a/macosx/osxdlg.m b/macosx/osxdlg.m index f2d09027..f32b0909 100644 --- a/macosx/osxdlg.m +++ b/macosx/osxdlg.m @@ -485,7 +485,27 @@ void old_keyfile_warning(void) */ } -void about_box(void *window) +static void connection_fatal_callback(void *ctx, int result) { - /* FIXME */ + SessionWindow *win = (SessionWindow *)ctx; + + [win endSession:FALSE]; +} + +void connection_fatal(void *frontend, char *p, ...) +{ + SessionWindow *win = (SessionWindow *)frontend; + va_list ap; + char *msg; + NSAlert *alert; + + va_start(ap, p); + msg = dupvprintf(p, ap); + va_end(ap); + + alert = [[NSAlert alloc] init]; + [alert setInformativeText:[NSString stringWithCString:msg]]; + [alert addButtonWithTitle:@"Proceed"]; + [win startAlert:alert withCallback:connection_fatal_callback + andCtx:win]; } diff --git a/macosx/osxmain.m b/macosx/osxmain.m index bd579852..362f92bd 100644 --- a/macosx/osxmain.m +++ b/macosx/osxmain.m @@ -60,28 +60,47 @@ char *x_get_default(const char *key) return NULL; /* this is a stub */ } -void modalfatalbox(char *p, ...) +static void commonfatalbox(char *p, va_list ap) +{ + char errorbuf[2048]; + NSAlert *alert; + + /* + * We may have come here because we ran out of memory, in which + * case it's entirely likely that that further memory + * allocations will fail. So (a) we use vsnprintf to format the + * error message rather than the usual dupvprintf; and (b) we + * have a fallback way to get the message out via stderr if + * even creating an NSAlert fails. + */ + vsnprintf(errorbuf, lenof(errorbuf), p, ap); + + alert = [NSAlert alloc]; + if (!alert) { + fprintf(stderr, "fatal error (and NSAlert failed): %s\n", errorbuf); + } else { + alert = [[alert init] autorelease]; + [alert addButtonWithTitle:@"Terminate"]; + [alert setInformativeText:[NSString stringWithCString:errorbuf]]; + [alert runModal]; + } + exit(1); +} + +void fatalbox(char *p, ...) { - /* FIXME: proper OS X GUI stuff */ va_list ap; - fprintf(stderr, "FATAL ERROR: "); va_start(ap, p); - vfprintf(stderr, p, ap); + commonfatalbox(p, ap); va_end(ap); - fputc('\n', stderr); - exit(1); } -void fatalbox(char *p, ...) +void modalfatalbox(char *p, ...) { - /* FIXME: proper OS X GUI stuff */ va_list ap; - fprintf(stderr, "FATAL ERROR: "); va_start(ap, p); - vfprintf(stderr, p, ap); + commonfatalbox(p, ap); va_end(ap); - fputc('\n', stderr); - exit(1); } void cmdline_error(char *p, ...) diff --git a/macosx/osxwin.m b/macosx/osxwin.m index 0b0c3ff6..f0ebee45 100644 --- a/macosx/osxwin.m +++ b/macosx/osxwin.m @@ -300,6 +300,8 @@ */ [self center]; /* :-) */ + exited = FALSE; + return self; } @@ -311,6 +313,14 @@ * Do so. */ sfree(alert_ctx); + if (term) + term_free(term); + if (logctx) + log_free(logctx); + if (back) + back->free(backhandle); + if (ldisc) + ldisc_free(ldisc); [super dealloc]; } @@ -346,7 +356,7 @@ char coutput[32]; int use_coutput = FALSE, special = FALSE, start, end; -printf("n=%d c=U+%04x cm=U+%04x m=%08x\n", n, c, cm, m); +//printf("n=%d c=U+%04x cm=U+%04x m=%08x\n", n, c, cm, m); /* * FIXME: Alt+numberpad codes. @@ -846,6 +856,33 @@ printf("n=%d c=U+%04x cm=U+%04x m=%08x\n", n, c, cm, m); } } +- (void)notifyRemoteExit +{ + int exitcode; + + if (!exited && (exitcode = back->exitcode(backhandle)) >= 0) + [self endSession:(exitcode == 0)]; +} + +- (void)endSession:(int)clean +{ + exited = TRUE; + if (ldisc) { + ldisc_free(ldisc); + ldisc = NULL; + } + if (back) { + back->free(backhandle); + backhandle = NULL; + back = NULL; + //FIXME: update specials menu; + } + if (cfg.close_on_exit == FORCE_ON || + (cfg.close_on_exit == AUTO && clean)) + [self close]; + // FIXME: else show restart menu item +} + @end int from_backend(void *frontend, int is_stderr, const char *data, int len) @@ -859,23 +896,11 @@ void frontend_keypress(void *handle) /* FIXME */ } -void connection_fatal(void *frontend, char *p, ...) -{ - //SessionWindow *win = (SessionWindow *)frontend; - /* FIXME: proper OS X GUI stuff */ - va_list ap; - fprintf(stderr, "FATAL ERROR: "); - va_start(ap, p); - vfprintf(stderr, p, ap); - va_end(ap); - fputc('\n', stderr); - exit(1); -} - void notify_remote_exit(void *frontend) { - //SessionWindow *win = (SessionWindow *)frontend; - /* FIXME */ + SessionWindow *win = (SessionWindow *)frontend; + + [win notifyRemoteExit]; } void ldisc_update(void *frontend, int echo, int edit) -- 2.11.0