mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-08 08:58: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:
parent
bd16a0e1de
commit
1f399bec58
@ -6,6 +6,8 @@
|
||||
#include <stdio.h>
|
||||
#include "putty.h"
|
||||
|
||||
const int be_default_protocol = -1;
|
||||
|
||||
const struct BackendVtable *const backends[] = {
|
||||
NULL
|
||||
};
|
||||
|
43
config.c
43
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
3
putty.h
3
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 {
|
||||
|
33
sercfg.c
33
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
|
||||
|
Loading…
Reference in New Issue
Block a user