Bah, r9008 caused an assertion failure on Windows due to a clash with the
[sgt/putty] / sercfg.c
index 10b582f..fc26737 100644 (file)
--- a/sercfg.c
+++ b/sercfg.c
@@ -29,19 +29,34 @@ static void serial_parity_handler(union control *ctrl, void *dlg,
        {"Mark", SER_PAR_MARK},
        {"Space", SER_PAR_SPACE},
     };
-    int i;
+    int mask = ctrl->listbox.context.i;
+    int i, j;
     Config *cfg = (Config *)data;
 
     if (event == EVENT_REFRESH) {
+       int oldparity = cfg->serparity;/* preserve past reentrant calls */
        dlg_update_start(ctrl, dlg);
        dlg_listbox_clear(ctrl, dlg);
-       for (i = 0; i < lenof(parities); i++)
-           dlg_listbox_addwithid(ctrl, dlg, parities[i].name,
-                                 parities[i].val);
-       for (i = 0; i < lenof(parities); i++)
-           if (cfg->serparity == parities[i].val)
-               dlg_listbox_select(ctrl, dlg, i);
+       for (i = 0; i < lenof(parities); i++)  {
+           if (mask & (1 << i))
+               dlg_listbox_addwithid(ctrl, dlg, parities[i].name,
+                                     parities[i].val);
+       }
+       for (i = j = 0; i < lenof(parities); i++) {
+           if (mask & (1 << i)) {
+               if (oldparity == parities[i].val) {
+                   dlg_listbox_select(ctrl, dlg, j);
+                   break;
+               }
+               j++;
+           }
+       }
+       if (i == lenof(parities)) {    /* an unsupported setting was chosen */
+           dlg_listbox_select(ctrl, dlg, 0);
+           oldparity = SER_PAR_NONE;
+       }
        dlg_update_done(ctrl, dlg);
+       cfg->serparity = oldparity;    /* restore */
     } else if (event == EVENT_SELCHANGE) {
        int i = dlg_listbox_index(ctrl, dlg);
        if (i < 0)
@@ -64,44 +79,61 @@ static void serial_flow_handler(union control *ctrl, void *dlg,
        {"RTS/CTS", SER_FLOW_RTSCTS},
        {"DSR/DTR", SER_FLOW_DSRDTR},
     };
-    int i;
+    int mask = ctrl->listbox.context.i;
+    int i, j;
     Config *cfg = (Config *)data;
 
     if (event == EVENT_REFRESH) {
+       int oldflow = cfg->serflow;    /* preserve past reentrant calls */
        dlg_update_start(ctrl, dlg);
        dlg_listbox_clear(ctrl, dlg);
-       for (i = 0; i < lenof(flows); i++)
-           dlg_listbox_addwithid(ctrl, dlg, flows[i].name,
-                                 flows[i].val);
-       for (i = 0; i < lenof(flows); i++)
-           if (cfg->serflow == flows[i].val)
-               dlg_listbox_select(ctrl, dlg, i);
+       for (i = 0; i < lenof(flows); i++)  {
+           if (mask & (1 << i))
+               dlg_listbox_addwithid(ctrl, dlg, flows[i].name, flows[i].val);
+       }
+       for (i = j = 0; i < lenof(flows); i++) {
+           if (mask & (1 << i)) {
+               if (oldflow == flows[i].val) {
+                   dlg_listbox_select(ctrl, dlg, j);
+                   break;
+               }
+               j++;
+           }
+       }
+       if (i == lenof(flows)) {       /* an unsupported setting was chosen */
+           dlg_listbox_select(ctrl, dlg, 0);
+           oldflow = SER_FLOW_NONE;
+       }
        dlg_update_done(ctrl, dlg);
+       cfg->serflow = oldflow;        /* restore */
     } else if (event == EVENT_SELCHANGE) {
        int i = dlg_listbox_index(ctrl, dlg);
        if (i < 0)
-           i = SER_PAR_NONE;
+           i = SER_FLOW_NONE;
        else
            i = dlg_listbox_getid(ctrl, dlg, i);
        cfg->serflow = i;
     }
 }
 
-void ser_setup_config_box(struct controlbox *b, int midsession)
+void ser_setup_config_box(struct controlbox *b, int midsession,
+                         int parity_mask, int flow_mask)
 {
     struct controlset *s;
     union control *c;
 
-    /*
-     * Add the serial back end to the protocols list at the top of
-     * the config box.
-     */
-    s = ctrl_getset(b, "Session", "hostport",
-                   "Specify your connection by host name or IP address");
-    {
+    if (!midsession) {
        int i;
        extern void config_protocolbuttons_handler(union control *, void *,
                                                   void *, int);
+
+       /*
+        * Add the serial back end to the protocols list at the
+        * top of the config box.
+        */
+       s = ctrl_getset(b, "Session", "hostport",
+                       "Specify the destination you want to connect to");
+
         for (i = 0; i < s->ncontrols; i++) {
             c = s->ctrls[i];
            if (c->generic.type == CTRL_RADIO &&
@@ -118,7 +150,7 @@ void ser_setup_config_box(struct controlbox *b, int midsession)
                if (c->radio.shortcuts) {
                    c->radio.shortcuts =
                        sresize(c->radio.shortcuts, c->radio.nbuttons, char);
-                   c->radio.shortcuts[c->radio.nbuttons-1] = NO_SHORTCUT;
+                   c->radio.shortcuts[c->radio.nbuttons-1] = 'r';
                }
            }
        }
@@ -160,8 +192,8 @@ void ser_setup_config_box(struct controlbox *b, int midsession)
                 dlg_stdeditbox_handler,I(offsetof(Config,serstopbits)),I(-2));
     ctrl_droplist(s, "Parity", 'p', 40,
                  HELPCTX(serial_parity),
-                 serial_parity_handler, I(0));
+                 serial_parity_handler, I(parity_mask));
     ctrl_droplist(s, "Flow control", 'f', 40,
                  HELPCTX(serial_flow),
-                 serial_flow_handler, I(0));
+                 serial_flow_handler, I(flow_mask));
 }