From d93f7113d1564d9e2b23863e3aa7049b64b7f926 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 11 Apr 2003 18:36:27 +0000 Subject: [PATCH] Rationalisation of the system of frontend handles. Most modular bits of PuTTY (terminal, backend, logctx etc) take a `void *' handle passed to them from the frontend, and used as a context for all their callbacks. Most of these point at the frontend structure itself (on platforms where this is meaningful), except that the handle passed to the backend has always pointed at the terminal because from_backend() was implemented in terminal.c. This has finally bitten Unix PuTTY, because both backend and logctx have been passing their respective and very different frontend handles to logevent(), so I've fixed it. from_backend() is now a function supplied by the _frontend_ itself, in all cases, and the frontend handle passed to backends must be the same as that passed to everything else. What was from_backend() in terminal.c is now called term_data(), and the typical implementation of from_backend() in a GUI frontend will just extract the terminal handle from the frontend structure and delegate to that. This appears to work on Unix and Windows, but has most likely broken the Mac build. [originally from svn r3100] --- putty.h | 3 ++- terminal.c | 7 +------ unix/pterm.c | 29 ++++++++++++++--------------- unix/uxputty.c | 12 ++++++------ window.c | 7 ++++++- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/putty.h b/putty.h index f985ad27..a35bbc3e 100644 --- a/putty.h +++ b/putty.h @@ -543,6 +543,7 @@ void request_paste(void *frontend); void frontend_keypress(void *frontend); void ldisc_update(void *frontend, int echo, int edit); void update_specials_menu(void *frontend); +int from_backend(void *frontend, int is_stderr, const char *data, int len); #define OPTIMISE_IS_SCROLL 1 void set_iconic(void *frontend, int iconic); @@ -622,7 +623,7 @@ int term_ldisc(Terminal *, int option); void term_copyall(Terminal *); void term_reconfig(Terminal *, Config *); void term_seen_key_event(Terminal *); -int from_backend(void *, int is_stderr, const char *data, int len); +int term_data(Terminal *, int is_stderr, const char *data, int len); void term_provide_resize_fn(Terminal *term, void (*resize_fn)(void *, int, int), void *resize_ctx); diff --git a/terminal.c b/terminal.c index 8e012f50..bcf202e5 100644 --- a/terminal.c +++ b/terminal.c @@ -4705,13 +4705,8 @@ int term_ldisc(Terminal *term, int option) return FALSE; } -/* - * from_backend(), to get data from the backend for the terminal. - */ -int from_backend(void *vterm, int is_stderr, const char *data, int len) +int term_data(Terminal *term, int is_stderr, const char *data, int len) { - Terminal *term = (Terminal *)vterm; - assert(len > 0); bufchain_add(&term->inbuf, data, len); diff --git a/unix/pterm.c b/unix/pterm.c index a2074a36..70317d5c 100644 --- a/unix/pterm.c +++ b/unix/pterm.c @@ -93,8 +93,7 @@ char *x_get_default(const char *key) void connection_fatal(void *frontend, char *p, ...) { - Terminal *term = (Terminal *)frontend; - struct gui_data *inst = (struct gui_data *)term->frontend; + struct gui_data *inst = (struct gui_data *)frontend; va_list ap; char *msg; @@ -164,10 +163,15 @@ int askappend(void *frontend, Filename filename) return 2; } +int from_backend(void *frontend, int is_stderr, const char *data, int len) +{ + struct gui_data *inst = (struct gui_data *)frontend; + return term_data(inst->term, is_stderr, data, len); +} + void logevent(void *frontend, char *string) { - Terminal *term = (Terminal *)frontend; - struct gui_data *inst = (struct gui_data *)term->frontend; + struct gui_data *inst = (struct gui_data *)frontend; log_eventlog(inst->logctx, string); @@ -212,8 +216,7 @@ static Mouse_Button translate_button(Mouse_Button button) */ void *get_window(void *frontend) { - Terminal *term = (Terminal *)frontend; - struct gui_data *inst = (struct gui_data *)term->frontend; + struct gui_data *inst = (struct gui_data *)frontend; return inst->window; } @@ -351,7 +354,7 @@ gint delete_window(GtkWidget *widget, GdkEvent *event, gpointer data) { struct gui_data *inst = (struct gui_data *)data; if (inst->cfg.warn_on_close) { - if (!reallyclose(inst->term)) + if (!reallyclose(inst)) return TRUE; } return FALSE; @@ -1981,8 +1984,7 @@ char *get_x_display(void *frontend) long get_windowid(void *frontend) { - Terminal *term = (Terminal *)frontend; - struct gui_data *inst = (struct gui_data *)(term->frontend); + struct gui_data *inst = (struct gui_data *)frontend; return (long)GDK_WINDOW_XWINDOW(inst->area->window); } @@ -2508,8 +2510,6 @@ void change_settings_menuitem(GtkMenuItem *item, gpointer data) oldcfg.window_border != cfg2.window_border || need_size) { set_geom_hints(inst); request_resize(inst, cfg2.width, cfg2.height); - //term_size(inst->term, cfg2.height, cfg2.width, cfg2.savelines); - // where TF is our configure event going?! } term_invalidate(inst->term); @@ -2519,8 +2519,7 @@ void change_settings_menuitem(GtkMenuItem *item, gpointer data) void update_specials_menu(void *frontend) { - Terminal *term = (Terminal *)frontend; - struct gui_data *inst = (struct gui_data *)term->frontend; + struct gui_data *inst = (struct gui_data *)frontend; const struct telnet_special *specials; @@ -2737,7 +2736,7 @@ int pt_main(int argc, char **argv) { char *realhost, *error; - error = inst->back->init((void *)inst->term, &inst->backhandle, + error = inst->back->init((void *)inst, &inst->backhandle, &inst->cfg, inst->cfg.host, inst->cfg.port, &realhost, inst->cfg.tcp_nodelay); @@ -2759,7 +2758,7 @@ int pt_main(int argc, char **argv) } } inst->back->provide_logctx(inst->backhandle, inst->logctx); - update_specials_menu(inst->term); + update_specials_menu(inst); term_provide_resize_fn(inst->term, inst->back->size, inst->backhandle); diff --git a/unix/uxputty.c b/unix/uxputty.c index 6507a2a9..f3da5e12 100644 --- a/unix/uxputty.c +++ b/unix/uxputty.c @@ -14,11 +14,15 @@ /* * TODO: * - * - Copy-and-paste from the Event Log. + * - Go through all the config options and ensure they can all be + * configured and reconfigured properly. * * - Remainder of the context menu: * - * - New Session and Duplicate Session (perhaps in pterm, in fact?!) + * - New Session, Duplicate Session and the Saved Sessions + * submenu. + * + at least New and Duplicate probably _should_ be in + * pterm. * + Duplicate Session will be fun, since we must work out * how to pass the config data through. * + In fact this should be easier on Unix, since fork() is @@ -42,10 +46,6 @@ * already have dropped privileges by this point, so we * can't get another pty. Sigh. Looks like exec has to be * the way forward then :-/ - * - * - Saved Sessions submenu (not in pterm of course) - * - * - Copy All to Clipboard (for what that's worth) */ /* diff --git a/window.c b/window.c index 40d9ae10..3c3cdb68 100644 --- a/window.c +++ b/window.c @@ -632,7 +632,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) char msg[1024], *title; char *realhost; - error = back->init((void *)term, &backhandle, &cfg, + error = back->init(NULL, &backhandle, &cfg, cfg.host, cfg.port, &realhost, cfg.tcp_nodelay); back->provide_logctx(backhandle, logctx); if (error) { @@ -4621,3 +4621,8 @@ void frontend_keypress(void *handle) */ return; } + +int from_backend(void *frontend, int is_stderr, const char *data, int len) +{ + return term_data(term, is_stderr, data, len); +}