]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Rationalisation of the system of frontend handles. Most modular bits
authorSimon Tatham <anakin@pobox.com>
Fri, 11 Apr 2003 18:36:27 +0000 (18:36 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 11 Apr 2003 18:36:27 +0000 (18:36 +0000)
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
terminal.c
unix/pterm.c
unix/uxputty.c
window.c

diff --git a/putty.h b/putty.h
index f985ad2776bfb463d2ccb2bf852c7109b0147e04..a35bbc3e8dab738915d02dc76f5bd95290e27853 100644 (file)
--- 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);
index 8e012f5070a7e826e97b582fc4364096762a9814..bcf202e515e1273bebe22699fc3f32c0b16ba6c3 100644 (file)
@@ -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);
index a2074a360e77934b77be6b22879b9c74fb089b53..70317d5cbc324116e65ebb8fa6f6a3419df32ab7 100644 (file)
@@ -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);
 
index 6507a2a9a33d7b6c13975926841fa635f7d30a9d..f3da5e120b95c23932bc6fa55c5574570d2f6830 100644 (file)
 /*
  * 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
  *          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)
  */
 
 /*
index 40d9ae1019545f8f3b3db4f11effd56884bf6d8e..3c3cdb68c47700ae8d6ebad084e9738b85a874dd 100644 (file)
--- 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);
+}