[syslinux] [RFC PATCH] menu: support single key booting

Ferenc Wagner wferi at niif.hu
Sun May 30 04:51:23 PDT 2010


If MENU COMMIT is specified for a label, execute it automatically
when its hotkey is pressed.

Signed-off-by: Ferenc Wagner <wferi at niif.hu>
---
 com32/menu/menu.h       |    1 +
 com32/menu/menumain.c   |   10 ++++++++--
 com32/menu/readconfig.c |    6 +++++-
 3 files changed, 14 insertions(+), 3 deletions(-)

As mentioned on IRC, people ask for this.
So here's something to talk about.  Like the variable names...

diff --git a/com32/menu/menu.h b/com32/menu/menu.h
index 1e596e1..856c368 100644
--- a/com32/menu/menu.h
+++ b/com32/menu/menu.h
@@ -64,6 +64,7 @@ struct menu_entry {
     enum menu_action action;
     unsigned char hotkey;
     bool save;			/* Save this entry if selected */
+    bool commit;		/* Commit if selected by hotkey */
 };
 
 static inline bool is_disabled(struct menu_entry *me)
diff --git a/com32/menu/menumain.c b/com32/menu/menumain.c
index 0c39264..3be1bd4 100644
--- a/com32/menu/menumain.c
+++ b/com32/menu/menumain.c
@@ -746,6 +746,7 @@ static const char *run_menu(void)
 {
     int key;
     int done = 0;
+    int hotkey = 0;
     volatile int entry = cm->curentry;
     int prev_entry = -1;
     volatile int top = cm->curtop;
@@ -854,7 +855,12 @@ static const char *run_menu(void)
 	}
 
 	this_timeout = min(min(key_timeout, timeout_left), (clock_t) CLK_TCK);
-	key = mygetkey(this_timeout);
+
+	if (hotkey && me->commit)
+	    key = KEY_ENTER;
+	else
+	    key = mygetkey(this_timeout);
+	hotkey = 0;
 
 	if (key != KEY_NONE) {
 	    timeout_left = key_timeout;
@@ -1071,7 +1077,7 @@ static const char *run_menu(void)
 		if (cm->menu_hotkeys[key]) {
 		    key_timeout = 0;
 		    entry = cm->menu_hotkeys[key]->entry;
-		    /* Should we commit at this point? */
+		    hotkey = 1;
 		}
 	    }
 	    break;
diff --git a/com32/menu/readconfig.c b/com32/menu/readconfig.c
index d4c8848..7aed5a3 100644
--- a/com32/menu/readconfig.c
+++ b/com32/menu/readconfig.c
@@ -217,6 +217,7 @@ struct labeldata {
     unsigned int menuseparator;
     unsigned int menudisabled;
     unsigned int menuindent;
+    unsigned int menucommit;
     enum menu_action action;
     int save;
     struct menu *submenu;
@@ -304,6 +305,7 @@ static void record(struct menu *m, struct labeldata *ld, const char *append)
 	me->hotkey = 0;
 	me->action = ld->action ? ld->action : MA_CMD;
 	me->save = ld->save ? (ld->save > 0) : m->save;
+	me->commit = !!ld->menucommit;
 
 	if (ld->menuindent) {
 	    const char *dn;
@@ -653,6 +655,8 @@ static void parse_config_file(FILE * f)
 		}
 	    } else if (looking_at(p, "hide")) {
 		ld.menuhide = 1;
+	    } else if (looking_at(p, "commit")) {
+		ld.menucommit = 1;
 	    } else if (looking_at(p, "passwd")) {
 		if (ld.label) {
 		    refstr_put(ld.passwd);
@@ -931,7 +935,7 @@ do_include:
 	    ld.helptext = NULL;
 	    ld.ipappend = ipappend;
 	    ld.menudefault = ld.menuhide = ld.menuseparator =
-		ld.menudisabled = ld.menuindent = 0;
+		ld.menudisabled = ld.menuindent = ld.menucommit = 0;
 	} else if ((ep = is_kernel_type(p, &type))) {
 	    if (ld.label) {
 		refstr_put(ld.kernel);
-- 
1.6.5




More information about the Syslinux mailing list