+#define HOST_BOX_TITLE "Host Name (or IP address)"
+#define PORT_BOX_TITLE "Port"
+
+/*
+ * Convenience function: determine whether this binary supports a
+ * given backend.
+ */
+static int have_backend(int protocol)
+{
+ struct backend_list *p = backends;
+ for (p = backends; p->name; p++) {
+ if (p->protocol == protocol)
+ return 1;
+ }
+ return 0;
+}
+
+static void config_host_handler(union control *ctrl, void *dlg,
+ void *data, int event)
+{
+ Config *cfg = (Config *)data;
+
+ /*
+ * This function works just like the standard edit box handler,
+ * only it has to choose the control's label and text from two
+ * different places depending on the protocol.
+ */
+ if (event == EVENT_REFRESH) {
+ if (cfg->protocol == PROT_SERIAL) {
+ /*
+ * This label text is carefully chosen to contain an n,
+ * since that's the shortcut for the host name control.
+ */
+ dlg_label_change(ctrl, dlg, "Serial line");
+ dlg_editbox_set(ctrl, dlg, cfg->serline);
+ } else {
+ dlg_label_change(ctrl, dlg, HOST_BOX_TITLE);
+ dlg_editbox_set(ctrl, dlg, cfg->host);
+ }
+ } else if (event == EVENT_VALCHANGE) {
+ if (cfg->protocol == PROT_SERIAL)
+ dlg_editbox_get(ctrl, dlg, cfg->serline, lenof(cfg->serline));
+ else
+ dlg_editbox_get(ctrl, dlg, cfg->host, lenof(cfg->host));
+ }
+}
+
+static void config_port_handler(union control *ctrl, void *dlg,
+ void *data, int event)
+{
+ Config *cfg = (Config *)data;
+ char buf[80];
+
+ /*
+ * This function works just like the standard edit box handler,
+ * only it has to choose the control's label and text from two
+ * different places depending on the protocol.
+ */
+ if (event == EVENT_REFRESH) {
+ if (cfg->protocol == PROT_SERIAL) {
+ /*
+ * This label text is carefully chosen to contain a p,
+ * since that's the shortcut for the port control.
+ */
+ dlg_label_change(ctrl, dlg, "Speed");
+ sprintf(buf, "%d", cfg->serspeed);
+ } else {
+ dlg_label_change(ctrl, dlg, PORT_BOX_TITLE);
+ sprintf(buf, "%d", cfg->port);
+ }
+ dlg_editbox_set(ctrl, dlg, buf);
+ } else if (event == EVENT_VALCHANGE) {
+ dlg_editbox_get(ctrl, dlg, buf, lenof(buf));
+ if (cfg->protocol == PROT_SERIAL)
+ cfg->serspeed = atoi(buf);
+ else
+ cfg->port = atoi(buf);
+ }
+}
+
+struct hostport {
+ union control *host, *port;
+};
+
+/*
+ * We export this function so that platform-specific config
+ * routines can use it to conveniently identify the protocol radio
+ * buttons in order to add to them.
+ */
+void config_protocolbuttons_handler(union control *ctrl, void *dlg,