diff --git a/be_none.c b/be_none.c index abc05517..f520e0bb 100644 --- a/be_none.c +++ b/be_none.c @@ -6,6 +6,8 @@ #include #include "putty.h" +const int be_default_protocol = -1; + const struct BackendVtable *const backends[] = { NULL }; diff --git a/config.c b/config.c index db83adb4..8c02cf6e 100644 --- a/config.c +++ b/config.c @@ -1535,23 +1535,34 @@ void setup_config_box(struct controlbox *b, bool midsession, hp->port = c; ctrl_columns(s, 1, 100); - if (!backend_vt_from_proto(PROT_SSH)) { - ctrl_radiobuttons(s, "Connection type:", NO_SHORTCUT, 3, + c = ctrl_radiobuttons(s, "Connection type:", NO_SHORTCUT, 4, HELPCTX(session_hostname), - config_protocolbuttons_handler, P(hp), - "Raw", 'w', I(PROT_RAW), - "Telnet", 't', I(PROT_TELNET), - "Rlogin", 'i', I(PROT_RLOGIN), - NULL); - } else { - ctrl_radiobuttons(s, "Connection type:", NO_SHORTCUT, 4, - HELPCTX(session_hostname), - config_protocolbuttons_handler, P(hp), - "Raw", 'w', I(PROT_RAW), - "Telnet", 't', I(PROT_TELNET), - "Rlogin", 'i', I(PROT_RLOGIN), - "SSH", 's', I(PROT_SSH), - NULL); + config_protocolbuttons_handler, P(hp), NULL); + c->radio.buttons = sresize(c->radio.buttons, PROTOCOL_LIMIT, char *); + c->radio.shortcuts = sresize(c->radio.shortcuts, PROTOCOL_LIMIT, char); + c->radio.buttondata = sresize(c->radio.buttondata, PROTOCOL_LIMIT, + intorptr); + assert(c->radio.nbuttons == 0); + for (int pass = 0; pass < 4; pass++) { + for (size_t i = 0; backends[i]; i++) { + int pass_needed = ( + backends[i]->protocol == be_default_protocol ? 0 : + backends[i]->protocol == PROT_SERIAL ? 1 : + backends[i]->protocol == PROT_RAW ? 2 : 3); + if (pass != pass_needed) + continue; + + c->radio.buttons[c->radio.nbuttons] = + dupstr(backends[i]->displayname); + c->radio.shortcuts[c->radio.nbuttons] = + (backends[i]->protocol == PROT_SSH ? 's' : + backends[i]->protocol == PROT_SERIAL ? 'r' : + backends[i]->protocol == PROT_RAW ? 'w' : + NO_SHORTCUT); + c->radio.buttondata[c->radio.nbuttons] = + I(backends[i]->protocol); + c->radio.nbuttons++; + } } } diff --git a/putty.h b/putty.h index d1136bfb..d35c3b22 100644 --- a/putty.h +++ b/putty.h @@ -368,7 +368,8 @@ enum { PROT_RAW, PROT_TELNET, PROT_RLOGIN, PROT_SSH, /* PROT_SERIAL is supported on a subset of platforms, but it doesn't * hurt to define it globally. */ - PROT_SERIAL + PROT_SERIAL, + PROTOCOL_LIMIT, /* upper bound on number of protocols */ }; enum { diff --git a/sercfg.c b/sercfg.c index 9cd0e063..b54499a0 100644 --- a/sercfg.c +++ b/sercfg.c @@ -128,39 +128,6 @@ void ser_setup_config_box(struct controlbox *b, bool midsession, int parity_mask, int flow_mask) { struct controlset *s; - union control *c; - - if (!midsession) { - int i; - - /* - * 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 && - c->generic.handler == config_protocolbuttons_handler) { - c->radio.nbuttons++; - c->radio.ncolumns++; - c->radio.buttons = - sresize(c->radio.buttons, c->radio.nbuttons, char *); - c->radio.buttons[c->radio.nbuttons-1] = - dupstr("Serial"); - c->radio.buttondata = - sresize(c->radio.buttondata, c->radio.nbuttons, intorptr); - c->radio.buttondata[c->radio.nbuttons-1] = I(PROT_SERIAL); - if (c->radio.shortcuts) { - c->radio.shortcuts = - sresize(c->radio.shortcuts, c->radio.nbuttons, char); - c->radio.shortcuts[c->radio.nbuttons-1] = 'r'; - } - } - } - } /* * Entirely new Connection/Serial panel for serial port