1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

config.c: loop over backends list for protocol selector.

Similarly to the previous commit, this is one fewer place where I need
to make a handwritten change with each new protocol.
This commit is contained in:
Simon Tatham 2020-02-22 14:00:23 +00:00
parent bd16a0e1de
commit 1f399bec58
4 changed files with 31 additions and 50 deletions

View File

@ -6,6 +6,8 @@
#include <stdio.h> #include <stdio.h>
#include "putty.h" #include "putty.h"
const int be_default_protocol = -1;
const struct BackendVtable *const backends[] = { const struct BackendVtable *const backends[] = {
NULL NULL
}; };

View File

@ -1535,23 +1535,34 @@ void setup_config_box(struct controlbox *b, bool midsession,
hp->port = c; hp->port = c;
ctrl_columns(s, 1, 100); ctrl_columns(s, 1, 100);
if (!backend_vt_from_proto(PROT_SSH)) { c = ctrl_radiobuttons(s, "Connection type:", NO_SHORTCUT, 4,
ctrl_radiobuttons(s, "Connection type:", NO_SHORTCUT, 3,
HELPCTX(session_hostname), HELPCTX(session_hostname),
config_protocolbuttons_handler, P(hp), config_protocolbuttons_handler, P(hp), NULL);
"Raw", 'w', I(PROT_RAW), c->radio.buttons = sresize(c->radio.buttons, PROTOCOL_LIMIT, char *);
"Telnet", 't', I(PROT_TELNET), c->radio.shortcuts = sresize(c->radio.shortcuts, PROTOCOL_LIMIT, char);
"Rlogin", 'i', I(PROT_RLOGIN), c->radio.buttondata = sresize(c->radio.buttondata, PROTOCOL_LIMIT,
NULL); intorptr);
} else { assert(c->radio.nbuttons == 0);
ctrl_radiobuttons(s, "Connection type:", NO_SHORTCUT, 4, for (int pass = 0; pass < 4; pass++) {
HELPCTX(session_hostname), for (size_t i = 0; backends[i]; i++) {
config_protocolbuttons_handler, P(hp), int pass_needed = (
"Raw", 'w', I(PROT_RAW), backends[i]->protocol == be_default_protocol ? 0 :
"Telnet", 't', I(PROT_TELNET), backends[i]->protocol == PROT_SERIAL ? 1 :
"Rlogin", 'i', I(PROT_RLOGIN), backends[i]->protocol == PROT_RAW ? 2 : 3);
"SSH", 's', I(PROT_SSH), if (pass != pass_needed)
NULL); 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++;
}
} }
} }

View File

@ -368,7 +368,8 @@ enum {
PROT_RAW, PROT_TELNET, PROT_RLOGIN, PROT_SSH, PROT_RAW, PROT_TELNET, PROT_RLOGIN, PROT_SSH,
/* PROT_SERIAL is supported on a subset of platforms, but it doesn't /* PROT_SERIAL is supported on a subset of platforms, but it doesn't
* hurt to define it globally. */ * hurt to define it globally. */
PROT_SERIAL PROT_SERIAL,
PROTOCOL_LIMIT, /* upper bound on number of protocols */
}; };
enum { enum {

View File

@ -128,39 +128,6 @@ void ser_setup_config_box(struct controlbox *b, bool midsession,
int parity_mask, int flow_mask) int parity_mask, int flow_mask)
{ {
struct controlset *s; 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 * Entirely new Connection/Serial panel for serial port