summaryrefslogtreecommitdiff
path: root/com32/menu
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-12-11 14:59:36 -0800
committerH. Peter Anvin <hpa@zytor.com>2008-12-14 13:53:58 -0800
commite21e66137b454fb3afd50a113de68599dd28de09 (patch)
tree807860047ee9e406888e49590aa5f13ce03b2a1c /com32/menu
parent36390f9712ac56be1dce7a635322bd96e15620c1 (diff)
downloadsyslinux-e21e66137b454fb3afd50a113de68599dd28de09.tar.gz
Add new "UI" directive instead of abusing the DEFAULT directive
Add a new "UI" directive to specify a user interface module, instead of abusing the DEFAULT directive. This allows the DEFAULT directive to be used for setting the default, even when the menu system is enabled. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'com32/menu')
-rw-r--r--com32/menu/menu.h3
-rw-r--r--com32/menu/readconfig.c42
2 files changed, 44 insertions, 1 deletions
diff --git a/com32/menu/menu.h b/com32/menu/menu.h
index 1fa1a24b..e2ffc1bc 100644
--- a/com32/menu/menu.h
+++ b/com32/menu/menu.h
@@ -49,7 +49,7 @@ enum menu_action {
};
struct menu_entry {
- int entry; /* Entry number inside menu */
+ struct menu *menu; /* Parent menu */
const char *displayname;
const char *label;
const char *passwd;
@@ -57,6 +57,7 @@ struct menu_entry {
const char *cmdline;
struct menu *submenu;
struct menu_entry *next; /* Linked list of all labels across menus */
+ int entry; /* Entry number inside menu */
enum menu_action action;
unsigned char hotkey;
};
diff --git a/com32/menu/readconfig.c b/com32/menu/readconfig.c
index 0d3093b2..01dadff9 100644
--- a/com32/menu/readconfig.c
+++ b/com32/menu/readconfig.c
@@ -33,6 +33,10 @@ int shiftkey = 0; /* Only display menu if shift key pressed */
int hiddenmenu = 0;
long long totaltimeout = 0;
+/* Keep track of global default */
+static int has_ui = 0; /* DEFAULT only counts if UI is found */
+static const char *globaldefault = NULL;
+
/* Linked list of all entires, hidden or not; used by unlabel() */
static struct menu_entry *all_entries;
static struct menu_entry **all_entries_end = &all_entries;
@@ -245,6 +249,7 @@ static struct menu_entry *new_entry(struct menu *m)
}
me = calloc(1, sizeof(struct menu_entry));
+ me->menu = m;
me->entry = m->nentries;
m->menu_entries[m->nentries++] = me;
*all_entries_end = me;
@@ -390,6 +395,27 @@ static struct menu *end_submenu(void)
return current_menu->parent ? current_menu->parent : current_menu;
}
+static struct menu_entry *find_label(const char *str)
+{
+ const char *p;
+ struct menu_entry *me;
+ int pos;
+
+ p = str;
+ while ( *p && !my_isspace(*p) )
+ p++;
+
+ /* p now points to the first byte beyond the kernel name */
+ pos = p-str;
+
+ for (me = all_entries; me; me = me->next) {
+ if (!strncmp(str, me->label, pos) && !me->label[pos])
+ return me;
+ }
+
+ return NULL;
+}
+
static const char *unlabel(const char *str)
{
/* Convert a CLI-style command line to an executable command line */
@@ -912,6 +938,11 @@ static void parse_config_file(FILE *f)
ld.ipappend = atoi(skipspace(p+8));
else
ipappend = atoi(skipspace(p+8));
+ } else if ( looking_at(p, "default") ) {
+ refstr_put(globaldefault);
+ globaldefault = refstrdup(skipspace(p+7));
+ } else if ( looking_at(p, "ui") ) {
+ has_ui = 1;
}
}
}
@@ -958,6 +989,7 @@ void parse_configs(char **argv)
{
const char *filename;
struct menu *m;
+ struct menu_entry *me;
empty_string = refstrdup("");
@@ -984,6 +1016,16 @@ void parse_configs(char **argv)
/* Common postprocessing */
resolve_gotos();
+ /* Handle global default */
+ if (has_ui && globaldefault) {
+ me = find_label(globaldefault);
+ if (me && me->menu != hide_menu) {
+ me->menu->defentry = me->entry;
+ start_menu = me->menu;
+ }
+ }
+
+ /* Final per-menu initialization, with all labels known */
for (m = menu_list; m; m = m->next) {
m->curentry = m->defentry; /* All menus start at their defaults */