2 * sercfg.c - the serial-port specific parts of the PuTTY
3 * configuration box. Centralised as cross-platform code because
4 * more than one platform will want to use it, but not part of the
5 * main configuration. The expectation is that each platform's
6 * local config function will call out to ser_setup_config_box() if
7 * it needs to set up the standard serial stuff. (Of course, it can
8 * then apply local tweaks after ser_setup_config_box() returns, if
19 static void serial_parity_handler(union control
*ctrl
, void *dlg
,
20 void *data
, int event
)
26 {"None", SER_PAR_NONE
},
28 {"Even", SER_PAR_EVEN
},
29 {"Mark", SER_PAR_MARK
},
30 {"Space", SER_PAR_SPACE
},
33 Config
*cfg
= (Config
*)data
;
35 if (event
== EVENT_REFRESH
) {
36 dlg_update_start(ctrl
, dlg
);
37 dlg_listbox_clear(ctrl
, dlg
);
38 for (i
= 0; i
< lenof(parities
); i
++)
39 dlg_listbox_addwithid(ctrl
, dlg
, parities
[i
].name
,
41 for (i
= 0; i
< lenof(parities
); i
++)
42 if (cfg
->serparity
== parities
[i
].val
)
43 dlg_listbox_select(ctrl
, dlg
, i
);
44 dlg_update_done(ctrl
, dlg
);
45 } else if (event
== EVENT_SELCHANGE
) {
46 int i
= dlg_listbox_index(ctrl
, dlg
);
50 i
= dlg_listbox_getid(ctrl
, dlg
, i
);
55 static void serial_flow_handler(union control
*ctrl
, void *dlg
,
56 void *data
, int event
)
62 {"None", SER_FLOW_NONE
},
63 {"XON/XOFF", SER_FLOW_XONXOFF
},
64 {"RTS/CTS", SER_FLOW_RTSCTS
},
65 {"DSR/DTR", SER_FLOW_DSRDTR
},
68 Config
*cfg
= (Config
*)data
;
70 if (event
== EVENT_REFRESH
) {
71 dlg_update_start(ctrl
, dlg
);
72 dlg_listbox_clear(ctrl
, dlg
);
73 for (i
= 0; i
< lenof(flows
); i
++)
74 dlg_listbox_addwithid(ctrl
, dlg
, flows
[i
].name
,
76 for (i
= 0; i
< lenof(flows
); i
++)
77 if (cfg
->serflow
== flows
[i
].val
)
78 dlg_listbox_select(ctrl
, dlg
, i
);
79 dlg_update_done(ctrl
, dlg
);
80 } else if (event
== EVENT_SELCHANGE
) {
81 int i
= dlg_listbox_index(ctrl
, dlg
);
85 i
= dlg_listbox_getid(ctrl
, dlg
, i
);
90 void ser_setup_config_box(struct controlbox
*b
, int midsession
)
96 * Add the serial back end to the protocols list at the top of
99 s
= ctrl_getset(b
, "Session", "hostport",
100 "Specify your connection by host name or IP address");
103 extern void config_protocolbuttons_handler(union control
*, void *,
105 for (i
= 0; i
< s
->ncontrols
; i
++) {
107 if (c
->generic
.type
== CTRL_RADIO
&&
108 c
->generic
.handler
== config_protocolbuttons_handler
) {
112 sresize(c
->radio
.buttons
, c
->radio
.nbuttons
, char *);
113 c
->radio
.buttons
[c
->radio
.nbuttons
-1] =
115 c
->radio
.buttondata
=
116 sresize(c
->radio
.buttondata
, c
->radio
.nbuttons
, intorptr
);
117 c
->radio
.buttondata
[c
->radio
.nbuttons
-1] = I(PROT_SERIAL
);
118 if (c
->radio
.shortcuts
) {
120 sresize(c
->radio
.shortcuts
, c
->radio
.nbuttons
, char);
121 c
->radio
.shortcuts
[c
->radio
.nbuttons
-1] = NO_SHORTCUT
;
128 * Entirely new Connection/Serial panel for serial port
131 ctrl_settitle(b
, "Connection/Serial",
132 "Options controlling local serial lines");
136 * We don't permit switching to a different serial port in
137 * midflight, although we do allow all other
140 s
= ctrl_getset(b
, "Connection/Serial", "serline",
141 "Select a serial line");
142 ctrl_editbox(s
, "Serial line to connect to", 'l', 40,
143 HELPCTX(serial_line
),
144 dlg_stdeditbox_handler
, I(offsetof(Config
,serline
)),
145 I(sizeof(((Config
*)0)->serline
)));
148 s
= ctrl_getset(b
, "Connection/Serial", "sercfg", "Configure the serial line");
149 ctrl_editbox(s
, "Speed (baud)", 's', 40,
150 HELPCTX(serial_speed
),
151 dlg_stdeditbox_handler
, I(offsetof(Config
,serspeed
)), I(-1));
152 ctrl_editbox(s
, "Data bits", 'b', 40,
153 HELPCTX(serial_databits
),
154 dlg_stdeditbox_handler
,I(offsetof(Config
,serdatabits
)),I(-1));
156 * Stop bits come in units of one half.
158 ctrl_editbox(s
, "Stop bits", 't', 40,
159 HELPCTX(serial_stopbits
),
160 dlg_stdeditbox_handler
,I(offsetof(Config
,serstopbits
)),I(-2));
161 ctrl_droplist(s
, "Parity", 'p', 40,
162 HELPCTX(serial_parity
),
163 serial_parity_handler
, I(0));
164 ctrl_droplist(s
, "Flow control", 'f', 40,
165 HELPCTX(serial_flow
),
166 serial_flow_handler
, I(0));