diff options
author | jhb <jhb@FreeBSD.org> | 2006-02-28 20:29:43 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2006-02-28 20:29:43 +0000 |
commit | 0aeeea8f00e36e75986095f9a9129081094ab8b2 (patch) | |
tree | 93c019b1413ec559e921369c9a6815b62bf56d9f /usr.sbin/sysinstall | |
parent | f4fef487daf4c65e5dc2847f7578cca52412accc (diff) | |
download | FreeBSD-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')
-rw-r--r-- | usr.sbin/sysinstall/Makefile | 25 | ||||
-rw-r--r-- | usr.sbin/sysinstall/config.c | 15 | ||||
-rw-r--r-- | usr.sbin/sysinstall/dmenu.c | 70 | ||||
-rw-r--r-- | usr.sbin/sysinstall/keymap.c | 64 | ||||
-rw-r--r-- | usr.sbin/sysinstall/main.c | 4 | ||||
-rw-r--r-- | usr.sbin/sysinstall/menus.c | 8 | ||||
-rw-r--r-- | usr.sbin/sysinstall/sysinstall.h | 14 |
7 files changed, 196 insertions, 4 deletions
diff --git a/usr.sbin/sysinstall/Makefile b/usr.sbin/sysinstall/Makefile index 77d8518..5ce9b34 100644 --- a/usr.sbin/sysinstall/Makefile +++ b/usr.sbin/sysinstall/Makefile @@ -12,7 +12,7 @@ SRCS= anonFTP.c cdrom.c command.c config.c devices.c dhcp.c \ label.c main.c makedevs.c media.c menus.c misc.c modules.c \ mouse.c msg.c network.c nfs.c options.c package.c \ system.c tape.c tcpip.c termcap.c ttys.c ufs.c user.c \ - variable.c ${_wizard} keymap.h + variable.c ${_wizard} keymap.h countries.h CFLAGS+= -DUSE_GZIP=1 .if ${MACHINE} == "pc98" @@ -24,7 +24,7 @@ DPADD= ${LIBDIALOG} ${LIBNCURSES} ${LIBUTIL} ${LIBDISK} ${LIBFTPIO} LDADD= -ldialog -lncurses -lutil -ldisk -lftpio CLEANFILES= makedevs.c rtermcap -CLEANFILES+= keymap.tmp keymap.h +CLEANFILES+= keymap.tmp keymap.h countries.tmp countries.h .if exists(${.CURDIR}/../../share/termcap/termcap.src) RTERMCAP= TERMCAP=${.CURDIR}/../../share/termcap/termcap.src ./rtermcap @@ -99,4 +99,25 @@ keymap.h: ( echo " { 0 }"; echo "};" ; echo "" ) >> keymap.tmp mv keymap.tmp keymap.h +countries.h: ${.CURDIR}/../../share/misc/iso3166 + rm -f countries.tmp + awk 'BEGIN { \ + FS = "\t"; \ + num = 1; \ + print "DMenu MenuCountry = {"; \ + print " DMENU_NORMAL_TYPE | DMENU_SELECTION_RETURNS,"; \ + print " \"Country Selection\","; \ + print " \"Please choose a country, region, or group.\\n\""; \ + print " \"Select an item using [SPACE] or [ENTER].\","; \ + printf " NULL,\n NULL,\n { "; \ + } \ + /^[[:space:]]*#/ {next;} \ + {if (num > 1) {printf " ";} \ + print "{ \"" num "\", \"" $$4 "\"" \ + ", dmenuVarCheck, dmenuSetCountryVariable" \ + ", NULL, VAR_COUNTRY \"=" tolower($$1) "\" },"; \ + ++num;} \ + END {print " { NULL } }\n};\n";}' < ${.ALLSRC} > countries.tmp + mv countries.tmp ${.TARGET} + .include <bsd.prog.mk> diff --git a/usr.sbin/sysinstall/config.c b/usr.sbin/sysinstall/config.c index d41c4ea..dae6d06 100644 --- a/usr.sbin/sysinstall/config.c +++ b/usr.sbin/sysinstall/config.c @@ -506,6 +506,21 @@ configNTP(dialogMenuItem *self) } int +configCountry(dialogMenuItem *self) +{ + int choice, scroll, curr, max; + + WINDOW *w = savescr(); + + dialog_clear_norefresh(); + dmenuSetDefaultItem(&MenuCountry, NULL, NULL, + VAR_COUNTRY "=" DEFAULT_COUNTRY, &choice, &scroll, &curr, &max); + dmenuOpen(&MenuCountry, &choice, &scroll, &curr, &max, FALSE); + restorescr(w); + return DITEM_SUCCESS; +} + +int configUsers(dialogMenuItem *self) { WINDOW *w = savescr(); 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) diff --git a/usr.sbin/sysinstall/keymap.c b/usr.sbin/sysinstall/keymap.c index 3c53a00..da08707 100644 --- a/usr.sbin/sysinstall/keymap.c +++ b/usr.sbin/sysinstall/keymap.c @@ -50,6 +50,70 @@ struct keymapInfo { * the language name only. */ +static int +keymapSetDefault(const char *prefix) +{ + dialogMenuItem *items = MenuSysconsKeymap.items; + int i; + size_t plen = strlen(prefix); + + for (i = 0; items[i].data; ++i) + if (!strncmp(prefix, items[i].data, plen)) + return i; + + return -1; +} + +int +keymapMenuSelect(dialogMenuItem *self) +{ + static const struct { + const char *country, *lang; + } map[] = { + {"dk", "danish"}, + {"ee", "estonian"}, + {"fi", "finnish"}, + {"de", "german"}, + {"is", "icelandic"}, + {"no", "norwegian"}, + {"pl", "pl_PL"}, + {"es", "spanish"}, + {"se", "swedish"}, + {"ch", "swiss"}, + {"gb", "uk"}, + {NULL, NULL} + }; + const char *country, *lang; + int i; + int choice, scroll, curr, max; + char prefix[16 + 1]; + + if ((country = variable_get(VAR_COUNTRY)) != NULL) + { + lang = country; + for (i = 0; map[i].country; ++i) + if (!strcmp(country, map[i].country)) + { + lang = map[i].lang; + break; + } + + snprintf(prefix, sizeof(prefix), "keymap=%s.iso", lang); + if ((choice = keymapSetDefault(prefix)) == -1) + { + snprintf(prefix, sizeof(prefix), "keymap=%s", lang); + if ((choice = keymapSetDefault(prefix)) == -1) + choice = 0; + } + + dmenuSetDefaultIndex(&MenuSysconsKeymap, &choice, &scroll, &curr, &max); + return dmenuOpen(&MenuSysconsKeymap, &choice, &scroll, &curr, &max, FALSE); + } + else + return dmenuOpenSimple(&MenuSysconsKeymap, FALSE) ? DITEM_SUCCESS : + DITEM_FAILURE; +} + /* * Return values: * diff --git a/usr.sbin/sysinstall/main.c b/usr.sbin/sysinstall/main.c index d240584..ca31125 100644 --- a/usr.sbin/sysinstall/main.c +++ b/usr.sbin/sysinstall/main.c @@ -158,6 +158,10 @@ main(int argc, char **argv) systemShutdown(status); } + /* Get user's country and keymap */ + if (RunningAsInit) + configCountry(NULL); + /* Begin user dialog at outer menu */ dialog_clear(); while (1) { diff --git a/usr.sbin/sysinstall/menus.c b/usr.sbin/sysinstall/menus.c index c2eec9b..36ffa1b 100644 --- a/usr.sbin/sysinstall/menus.c +++ b/usr.sbin/sysinstall/menus.c @@ -203,6 +203,7 @@ DMenu MenuIndex = { NULL, { { " Anon FTP", "Configure anonymous FTP logins.", dmenuVarCheck, configAnonFTP, NULL, "anon_ftp" }, { " Commit", "Commit any pending actions (dangerous!)", NULL, installCustomCommit }, + { " Country", "Set the system's country", NULL, configCountry }, #ifdef WITH_SYSCONS { " Console settings", "Customize system console behavior.", NULL, dmenuSubmenu, NULL, &MenuSyscons }, #endif @@ -273,7 +274,7 @@ DMenu MenuIndex = { #ifndef PC98 { " Syscons, Font", "The console screen font.", NULL, dmenuSubmenu, NULL, &MenuSysconsFont }, #endif - { " Syscons, Keymap", "The console keymap configuration menu.", NULL, dmenuSubmenu, NULL, &MenuSysconsKeymap }, + { " Syscons, Keymap", "The console keymap configuration menu.", NULL, keymapMenuSelect }, { " Syscons, Keyrate", "The console key rate configuration menu.", NULL, dmenuSubmenu, NULL, &MenuSysconsKeyrate }, { " Syscons, Saver", "The console screen saver configuration menu.", NULL, dmenuSubmenu, NULL, &MenuSysconsSaver }, #ifndef PC98 @@ -291,6 +292,9 @@ DMenu MenuIndex = { { NULL } }, }; +/* The country menu */ +#include "countries.h" + /* The initial installation menu */ DMenu MenuInitial = { DMENU_NORMAL_TYPE, @@ -310,7 +314,7 @@ DMenu MenuInitial = { { "Configure", "Do post-install configuration of FreeBSD", NULL, dmenuSubmenu, NULL, &MenuConfigure }, { "Doc", "Installation instructions, README, etc.", NULL, dmenuSubmenu, NULL, &MenuDocumentation }, #ifdef WITH_SYSCONS - { "Keymap", "Select keyboard type", NULL, dmenuSubmenu, NULL, &MenuSysconsKeymap }, + { "Keymap", "Select keyboard type", NULL, keymapMenuSelect }, #endif { "Options", "View/Set various installation options", NULL, optionsEditor }, { "Fixit", "Repair mode with CDROM/DVD/floppy or start shell", NULL, dmenuSubmenu, NULL, &MenuFixit }, diff --git a/usr.sbin/sysinstall/sysinstall.h b/usr.sbin/sysinstall/sysinstall.h index 3dfc048..d3a24c0 100644 --- a/usr.sbin/sysinstall/sysinstall.h +++ b/usr.sbin/sysinstall/sysinstall.h @@ -97,6 +97,7 @@ #define VAR_BOOTMGR "bootManager" #define VAR_BROWSER_BINARY "browserBinary" #define VAR_BROWSER_PACKAGE "browserPackage" +#define VAR_COUNTRY "country" #define VAR_CPIO_VERBOSITY "cpioVerbose" #define VAR_DEBUG "debug" #define VAR_DESKSTYLE "_deskStyle" @@ -198,6 +199,11 @@ #define VAR_TERM "TERM" #define VAR_CONSTERM "_consterm" +#ifdef PC98 +#define DEFAULT_COUNTRY "jp" +#else +#define DEFAULT_COUNTRY "us" +#endif #define DEFAULT_TAPE_BLOCKSIZE "20" /* One MB worth of blocks */ @@ -414,6 +420,7 @@ extern unsigned int SrcDists; /* Which src distributions we want */ extern unsigned int XOrgDists; /* Which X.Org dists we want */ extern int BootMgr; /* Which boot manager to use */ extern int StatusLine; /* Where to print our status messages */ +extern DMenu MenuCountry; /* Country menu */ extern DMenu MenuInitial; /* Initial installation menu */ extern DMenu MenuFixit; /* Fixit repair menu */ #if defined(__i386__) || defined(__amd64__) @@ -522,6 +529,7 @@ extern int configNTP(dialogMenuItem *self); #ifdef __alpha__ extern int configOSF1(dialogMenuItem *self); #endif +extern int configCountry(dialogMenuItem *self); extern int configUsers(dialogMenuItem *self); extern int configRouter(dialogMenuItem *self); extern int configPCNFSD(dialogMenuItem *self); @@ -605,11 +613,16 @@ extern int dmenuSystemCommandBox(dialogMenuItem *tmp); extern int dmenuExit(dialogMenuItem *tmp); extern int dmenuISetVariable(dialogMenuItem *tmp); extern int dmenuSetVariable(dialogMenuItem *tmp); +extern int dmenuSetCountryVariable(dialogMenuItem *tmp); extern int dmenuSetKmapVariable(dialogMenuItem *tmp); extern int dmenuSetVariables(dialogMenuItem *tmp); extern int dmenuToggleVariable(dialogMenuItem *tmp); extern int dmenuSetFlag(dialogMenuItem *tmp); extern int dmenuSetValue(dialogMenuItem *tmp); +extern int dmenuFindItem(DMenu *menu, const char *prompt, const char *title, void *data); +extern void dmenuSetDefaultIndex(DMenu *menu, int *choice, int *scroll, int *curr, int *max); +extern int dmenuSetDefaultItem(DMenu *menu, const char *prompt, const char *title, void *data, + int *choice, int *scroll, int *curr, int *max); extern Boolean dmenuOpen(DMenu *menu, int *choice, int *scroll, int *curr, int *max, Boolean buttons); extern Boolean dmenuOpenSimple(DMenu *menu, Boolean buttons); extern int dmenuVarCheck(dialogMenuItem *item); @@ -677,6 +690,7 @@ extern Boolean copySelf(void); extern int kget(char *out); /* keymap.c */ +extern int keymapMenuSelect(dialogMenuItem *self); extern int loadKeymap(const char *lang); /* label.c */ |