summaryrefslogtreecommitdiffstats
path: root/usr.sbin/sysinstall/dmenu.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2006-02-28 20:29:43 +0000
committerjhb <jhb@FreeBSD.org>2006-02-28 20:29:43 +0000
commit0aeeea8f00e36e75986095f9a9129081094ab8b2 (patch)
tree93c019b1413ec559e921369c9a6815b62bf56d9f /usr.sbin/sysinstall/dmenu.c
parentf4fef487daf4c65e5dc2847f7578cca52412accc (diff)
downloadFreeBSD-src-0aeeea8f00e36e75986095f9a9129081094ab8b2.zip
FreeBSD-src-0aeeea8f00e36e75986095f9a9129081094ab8b2.tar.gz
- Autogenerate a menu containing a list of countries and keymaps supported
by syscons. - If we are running as init, popup the country menu before the main menu. If a non-default country is chosen, then a second menu is brought up to let the user choose a keymap. By default the default keymap for the country that was selected is highlighted. If the user chooses the default country, then the default keymap is just assumed and the user is not presented with the keymap menu. Currently the default country is set to "United States" except for PC98 which assumes "Japan". PR: bin/93853 Submitted by: Seth Kingsley sethk at magnesium dot net MFC after: 3 days
Diffstat (limited to 'usr.sbin/sysinstall/dmenu.c')
-rw-r--r--usr.sbin/sysinstall/dmenu.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/usr.sbin/sysinstall/dmenu.c b/usr.sbin/sysinstall/dmenu.c
index d89f8ce..aed89d8 100644
--- a/usr.sbin/sysinstall/dmenu.c
+++ b/usr.sbin/sysinstall/dmenu.c
@@ -35,6 +35,7 @@
*/
#include "sysinstall.h"
+#include <sys/param.h>
#include <errno.h>
#define MAX_MENU 15
@@ -111,6 +112,21 @@ dmenuSetVariables(dialogMenuItem *tmp)
}
int
+dmenuSetCountryVariable(dialogMenuItem *tmp)
+{
+ variable_set((char *)tmp->data, FALSE);
+#ifdef WITH_SYSCONS
+ /* Don't prompt the user for a keymap if they're using the default locale. */
+ if (!strcmp(variable_get(VAR_COUNTRY), DEFAULT_COUNTRY))
+ return DITEM_SUCCESS;
+
+ return keymapMenuSelect(tmp);
+#else
+ return DITEM_SUCCESS;
+#endif
+}
+
+int
dmenuSetKmapVariable(dialogMenuItem *tmp)
{
char *lang;
@@ -264,6 +280,60 @@ menu_height(DMenu *menu, int n)
return n > max ? max : n;
}
+/* Find a menu item that matches any field. */
+int
+dmenuFindItem(DMenu *menu, const char *prompt, const char *title, void *data)
+{
+ dialogMenuItem *items = menu->items;
+ int i;
+
+ for (i = 0; items[i].prompt; ++i)
+ if ((prompt && !strcmp(items[i].prompt, prompt)) ||
+ (title && !strcmp(items[i].title, title)) ||
+ (data && items[i].data == data))
+ return i;
+
+ return -1;
+}
+
+/* Set the default item for a menu by index and scroll to it. */
+void
+dmenuSetDefaultIndex(DMenu *menu, int *choice, int *scroll, int *curr, int *max)
+{
+ int nitem;
+ int height;
+
+ *curr = *max = 0;
+
+ for (nitem = 0; menu->items[nitem].prompt; ++nitem);
+
+ height = menu_height(menu, nitem);
+ if (*choice > height)
+ {
+ *scroll = MIN(nitem - height, *choice);
+ *choice = *choice - *scroll;
+ }
+ else
+ *scroll = 0;
+}
+
+/* Set the default menu item that matches any field and scroll to it. */
+Boolean
+dmenuSetDefaultItem(DMenu *menu, const char *prompt, const char *title, void *data,
+ int *choice, int *scroll, int *curr, int *max)
+{
+ if ((*choice = dmenuFindItem(menu, prompt, title, data)) != -1)
+ {
+ dmenuSetDefaultIndex(menu, choice, scroll, curr, max);
+ return TRUE;
+ }
+ else
+ {
+ *choice = *scroll = *curr = *max = 0;
+ return FALSE;
+ }
+}
+
/* Traverse over an internal menu */
Boolean
dmenuOpen(DMenu *menu, int *choice, int *scroll, int *curr, int *max, Boolean buttons)
OpenPOWER on IntegriCloud