summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2007-02-28 15:46:58 -0800
committerH. Peter Anvin <hpa@zytor.com>2007-02-28 15:46:58 -0800
commit6844ea5cffe96f2b07ff7f5748b551869a40ffb5 (patch)
treeb49714b34384b55c7c1e263ea26fc09a939e7679
parent26d94271ebf3f0463d09d7009fa83a9e2705fed8 (diff)
downloadsyslinux-6844ea5cffe96f2b07ff7f5748b551869a40ffb5.tar.gz
Simple menu system: unified way to handle message strings; add NOTABMSGsyslinux-3.40-pre9
A unified way to handle the message strings (for i18n/customization); add a MENU NOTABMSG customizable string.
-rw-r--r--README.menu6
-rw-r--r--com32/modules/menu.h18
-rw-r--r--com32/modules/menumain.c17
-rw-r--r--com32/modules/readconfig.c62
4 files changed, 74 insertions, 29 deletions
diff --git a/README.menu b/README.menu
index efa79891..4eccf068 100644
--- a/README.menu
+++ b/README.menu
@@ -132,6 +132,12 @@ MENU TABMSG message
Replaces the message "Press [Tab] to edit options".
+MENU NOTABMSG message
+
+ Takes the place of the TABMSG message if option editing is
+ disabled. Defaults to blank.
+
+
MENU PASSPROMPT message
Replaces the message "Password required".
diff --git a/com32/modules/menu.h b/com32/modules/menu.h
index 0a5808d5..c15b84d5 100644
--- a/com32/modules/menu.h
+++ b/com32/modules/menu.h
@@ -56,6 +56,23 @@ enum kernel_type {
extern const char *kernel_types[];
+/* Configurable messages */
+enum message_number {
+ MSG_TITLE,
+ MSG_AUTOBOOT,
+ MSG_TAB,
+ MSG_NOTAB,
+ MSG_PASSPROMPT,
+
+ MSG_COUNT
+};
+struct messages {
+ const char *name; /* Message configuration name */
+ const char *defmsg; /* Default message text */
+ char *msg; /* Actual message text */
+};
+extern struct messages messages[MSG_COUNT];
+
/* 512 is the current definition inside syslinux */
#define MAX_CMDLINE_LEN 512
@@ -77,7 +94,6 @@ extern int timeout;
extern int shiftkey;
extern long long totaltimeout;
-extern char *menu_title;
extern char *ontimeout;
extern char *onerror;
extern char *menu_master_passwd;
diff --git a/com32/modules/menumain.c b/com32/modules/menumain.c
index 7c96a706..d661dbf6 100644
--- a/com32/modules/menumain.c
+++ b/com32/modules/menumain.c
@@ -297,8 +297,8 @@ ask_passwd(const char *menu_entry)
putchar('q');
printf("j\017\033[%d;%dH\1#12 %s \033[%d;%dH\1#13",
- PASSWD_ROW, (WIDTH-(strlen(menu_passprompt_msg)+2))/2,
- menu_passprompt_msg, PASSWD_ROW+1, PASSWD_MARGIN+3);
+ PASSWD_ROW, (WIDTH-(strlen(messages[MSG_PASSPROMPT].msg)+2))/2,
+ messages[MSG_PASSPROMPT].msg, PASSWD_ROW+1, PASSWD_MARGIN+3);
/* Actually allow user to type a password, then compare to the SHA1 */
done = 0;
@@ -360,6 +360,7 @@ draw_menu(int sel, int top, int edit_line)
{
int x, y;
int sbtop = 0, sbbot = 0;
+ const char *tabmsg;
if ( nentries > MENU_ROWS ) {
int sblen = MENU_ROWS*MENU_ROWS/nentries;
@@ -375,7 +376,7 @@ draw_menu(int sel, int top, int edit_line)
printf("k\033[2;%dH\1#01x\017\1#02 %s \1#01\016x",
MARGIN+1,
- pad_line(menu_title, 1, WIDTH-2*MARGIN-4));
+ pad_line(messages[MSG_TITLE].msg, 1, WIDTH-2*MARGIN-4));
printf("\033[3;%dH\1#01t", MARGIN+1);
for ( x = 2 ; x <= WIDTH-2*MARGIN-1 ; x++ )
@@ -391,7 +392,11 @@ draw_menu(int sel, int top, int edit_line)
fputs("j\017", stdout);
if ( edit_line && allowedit && !menu_master_passwd )
- printf("\1#08\033[%d;1H%s", TABMSG_ROW, pad_line(menu_tab_msg, 1, WIDTH));
+ tabmsg = messages[MSG_TAB].msg;
+ else
+ tabmsg = messages[MSG_NOTAB].msg;
+
+ printf("\1#08\033[%d;1H%s", TABMSG_ROW, pad_line(tabmsg, 1, WIDTH));
printf("\1#00\033[%d;1H", END_ROW);
}
@@ -630,11 +635,11 @@ run_menu(void)
char buf[256];
int tol = timeout_left/CLK_TCK;
int nc = 0, nnc;
- const char *tp = menu_autoboot_msg;
+ const char *tp = messages[MSG_AUTOBOOT].msg;
char tc;
char *tq = buf;
- while ((tq-buf) < (sizeof buf-16) && (tc = *tp)) {
+ while ((size_t)(tq-buf) < (sizeof buf-16) && (tc = *tp)) {
if (tc == '#') {
nnc = sprintf(tq, "\1#15%d\1#14", tol);
tq += nnc;
diff --git a/com32/modules/readconfig.c b/com32/modules/readconfig.c
index 6dd0cb3e..0fa5a6aa 100644
--- a/com32/modules/readconfig.c
+++ b/com32/modules/readconfig.c
@@ -32,28 +32,36 @@ int timeout = 0;
int shiftkey = 0; /* Only display menu if shift key pressed */
long long totaltimeout = 0;
-char *menu_title = NULL;
char *ontimeout = NULL;
char *onerror = NULL;
char *menu_master_passwd = NULL;
-
-char *menu_tab_msg;
-char *menu_autoboot_msg;
-char *menu_passprompt_msg;
-
char *menu_background = NULL;
struct menu_entry menu_entries[MAX_ENTRIES];
struct menu_entry hide_entries[MAX_ENTRIES];
struct menu_entry *menu_hotkeys[256];
+struct messages messages[MSG_COUNT] = {
+ [MSG_TITLE] =
+ { "title", "", NULL },
+ [MSG_AUTOBOOT] =
+ { "autoboot", "Automatic boot in # seconds", NULL },
+ [MSG_TAB] =
+ { "tabmsg", "Press [Tab] to edit options", NULL },
+ [MSG_NOTAB] =
+ { "notabmsg", "", NULL },
+ [MSG_PASSPROMPT] =
+ { "passprompt", "Password required", NULL },
+};
+
#define astrdup(x) ({ char *__x = (x); \
size_t __n = strlen(__x) + 1; \
char *__p = alloca(__n); \
if ( __p ) memcpy(__p, __x, __n); \
__p; })
+/* Must match enum kernel_type */
const char *kernel_types[] = {
"none",
"localboot",
@@ -414,10 +422,26 @@ static char *is_kernel_type(char *cmdstr, enum kernel_type *type)
return NULL;
}
+static char *is_message_name(char *cmdstr, struct messages **msgptr)
+{
+ char *q;
+ int i;
+
+ for (i = 0; i < MSG_COUNT; i++) {
+ if ((q = looking_at(cmdstr, messages[i].name))) {
+ *msgptr = &messages[i];
+ return q;
+ }
+ }
+
+ return NULL;
+}
+
static void parse_config_file(FILE *f)
{
char line[MAX_LINE], *p, *ep, ch;
enum kernel_type type;
+ struct messages *msgptr;
while ( fgets(line, sizeof line, f) ) {
p = strchr(line, '\r');
@@ -432,9 +456,7 @@ static void parse_config_file(FILE *f)
if ( looking_at(p, "menu") ) {
p = skipspace(p+4);
- if ( looking_at(p, "title") ) {
- menu_title = strdup(skipspace(p+5));
- } else if ( looking_at(p, "label") ) {
+ if ( looking_at(p, "label") ) {
if ( ld.label )
ld.menulabel = strdup(skipspace(p+5));
} else if ( looking_at(p, "default") ) {
@@ -460,15 +482,9 @@ static void parse_config_file(FILE *f)
if (menu_background)
free(menu_background);
menu_background = dup_word(&p);
- } else if ( (ep = looking_at(p, "autoboot")) ) {
- free(menu_autoboot_msg);
- menu_autoboot_msg = strdup(skipspace(ep));
- } else if ( (ep = looking_at(p, "tabmsg")) ) {
- free(menu_tab_msg);
- menu_tab_msg = strdup(skipspace(ep));
- } else if ( (ep = looking_at(p, "passprompt")) ) {
- free(menu_passprompt_msg);
- menu_passprompt_msg = strdup(skipspace(ep));
+ } else if ( (ep = is_message_name(p, &msgptr)) ) {
+ free(msgptr->msg);
+ msgptr->msg = strdup(skipspace(ep));
} else if ((ep = looking_at(p, "color")) ||
(ep = looking_at(p, "colour"))) {
int i;
@@ -598,13 +614,15 @@ static int parse_one_config(const char *filename)
void parse_configs(char **argv)
{
const char *filename;
+ int i;
/* Initialize defaults */
- menu_title = strdup("");
- menu_tab_msg = strdup("Press [Tab] to edit options");
- menu_autoboot_msg = strdup("Automatic boot in # sections");
- menu_passprompt_msg = strdup("Password required");
+ for (i = 0; i < MSG_COUNT; i++) {
+ if (messages[i].msg)
+ free(messages[i].msg);
+ messages[i].msg = strdup(messages[i].defmsg);
+ }
/* Other initialization */