diff options
author | H. Peter Anvin <hpa@zytor.com> | 2006-01-07 13:51:22 -0800 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2006-01-07 13:51:22 -0800 |
commit | becc57991cb724d7888f0d6fefd368f5a4c1815b (patch) | |
tree | 36ac2e4f17fbfa1bd7f9c2e3dc5f6198156472c1 | |
parent | a22c4aff0e5649fa22bbb4b7fda9433d7a8c44de (diff) | |
download | syslinux-becc57991cb724d7888f0d6fefd368f5a4c1815b.tar.gz |
Handle "ontimeout" with label correctly in menu.c32; add "menu shiftkey"syslinux-3.20-pre4
-rw-r--r-- | com32/modules/menu.c | 19 | ||||
-rw-r--r-- | com32/modules/menu.h | 1 | ||||
-rw-r--r-- | com32/modules/readconfig.c | 44 |
3 files changed, 59 insertions, 5 deletions
diff --git a/com32/modules/menu.c b/com32/modules/menu.c index 9f34061e..df0fe998 100644 --- a/com32/modules/menu.c +++ b/com32/modules/menu.c @@ -1,7 +1,7 @@ #ident "$Id$" /* ----------------------------------------------------------------------- * * - * Copyright 2004-2005 H. Peter Anvin - All Rights Reserved + * Copyright 2004-2006 H. Peter Anvin - All Rights Reserved * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -534,6 +534,14 @@ clear_screen(void) printf("\033e\033%%@\033)0\033(B%s\033[?25l\033[2J", menu_attrib->screen); } +static inline int +shift_is_held(void) +{ + uint8_t shift_bits = *(uint8_t *)0x417; + + return !!(shift_bits & 0x5d); /* Caps/Scroll/Alt/Shift */ +} + static const char * run_menu(void) { @@ -548,6 +556,11 @@ run_menu(void) /* Note: for both key_timeout and timeout == 0 means no limit */ timeout_left = key_timeout = timeout; + /* If we're in shiftkey mode, exit immediately unless a shift key is pressed */ + if ( shiftkey && !shift_is_held() ) { + return menu_entries[defentry].cmdline; + } + /* Handle both local and global timeout */ if ( setjmp(timeout_jump) ) { entry = defentry; @@ -777,13 +790,13 @@ execute(const char *cmdline) kernel = q; p = cmdline; - while ( *p && !isspace(*p) ) { + while ( *p && *p > ' ' ) { *q++ = *p++; } *q++ = '\0'; args = q; - while ( *p && isspace(*p) ) + while ( *p && *p <= ' ' ) p++; strcpy(q, p); diff --git a/com32/modules/menu.h b/com32/modules/menu.h index 78a553c6..53af4003 100644 --- a/com32/modules/menu.h +++ b/com32/modules/menu.h @@ -56,6 +56,7 @@ extern int nentries; extern int defentry; extern int allowedit; extern int timeout; +extern int shiftkey; extern long long totaltimeout; extern char *menu_title; diff --git a/com32/modules/readconfig.c b/com32/modules/readconfig.c index 16bb136f..2208d23f 100644 --- a/com32/modules/readconfig.c +++ b/com32/modules/readconfig.c @@ -1,7 +1,7 @@ #ident "$Id$" /* ----------------------------------------------------------------------- * * - * Copyright 2004-2005 H. Peter Anvin - All Rights Reserved + * Copyright 2004-2006 H. Peter Anvin - All Rights Reserved * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +27,7 @@ int nentries = 0; int defentry = 0; int allowedit = 1; /* Allow edits of the command line */ int timeout = 0; +int shiftkey = 0; /* Only display menu if shift key pressed */ long long totaltimeout = 0; char *menu_title = ""; @@ -184,6 +185,40 @@ record(struct labeldata *ld, char *append) } } +static char * +unlabel(char *str) +{ + /* Convert a CLI-style command line to an executable command line */ + const char *p; + char *q; + struct menu_entry *me; + int i, pos; + + p = str; + while ( *p && !isspace(*p) ) + p++; + + /* p now points to the first byte beyond the kernel name */ + pos = p-str; + + for ( i = 0 ; i < nentries ; i++ ) { + me = &menu_entry[i]; + + if ( !strncmp(str, me->label, pos) && !me->label[pos] ) { + /* Found matching label */ + q = malloc(strlen(me->cmdline) + strlen(p) + 1); + strcpy(q, me->cmdline); + strcat(q, p); + + free(str); + + return q; + } + } + + return str; +} + void parse_config(const char *filename) { char line[MAX_LINE], *p, *ep; @@ -224,6 +259,8 @@ void parse_config(const char *filename) ld.menuhide = 1; } else if ( looking_at(p, "passwd") ) { ld.passwd = strdup(skipspace(p+6)); + } else if ( looking_at(p, "shiftkey") ) { + shiftkey = 1; } else if ( looking_at(p, "master") ) { p = skipspace(p+6); if ( looking_at(p, "passwd") ) { @@ -264,7 +301,7 @@ void parse_config(const char *filename) } else if ( looking_at(p, "totaltimeout") ) { totaltimeout = (atoll(skipspace(p+13))*CLK_TCK+9)/10; } else if ( looking_at(p, "ontimeout") ) { - ontimeout = strdup(skipspace(p+9)); + ontimeout = skipspace(p+9); } else if ( looking_at(p, "allowoptions") ) { allowedit = atoi(skipspace(p+12)); } else if ( looking_at(p, "ipappend") ) { @@ -277,4 +314,7 @@ void parse_config(const char *filename) record(&ld, append); fclose(f); + + if ( ontimeout ) + ontimeout = unlabel(ontimeout); } |