Simple menu system updates
authorArne Georg Gleditsch <argggh@linpro.no>
Mon, 4 Sep 2006 06:50:44 +0000 (08:50 +0200)
committerH. Peter Anvin <hpa@zytor.com>
Tue, 5 Sep 2006 20:50:07 +0000 (13:50 -0700)
Hi,

I'm attaching a patch to Syslinux dealing with a handful of issues that
were preventing me from using the simple menu interface.  Issues covered:

* Enable "MENU ONERROR" as a keyword on par with "ONERROR".
* Enable hidden menu entries to be used as ontimeout and onerror entries
(probably the least estheticalla pleasing part, sorry about that.)
* Make global "IPAPPEND" directives apply also when using menu.c32.
* Memory allocation fix for the ontimeout-variable (unlabel does free()).
* Make menu.c32 add ipappend options at end of kernel commend line, as
pxelinux generally does.

I see 3.30-pre1 is out now, I haven't had time to check applicability of
these patches towards this.  Hope they can still be of use.

--

Arne.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
com32/modules/menu.c
com32/modules/menu.h
com32/modules/readconfig.c

index d9db563..f7d44c5 100644 (file)
@@ -838,8 +838,11 @@ int main(int argc, char *argv[])
     cmdline = run_menu();
 
     printf("\033[?25h\033[%d;1H\033[0m", END_ROW);
-    if ( cmdline )
+    if ( cmdline ) {
       execute(cmdline);
+      if ( onerror )
+         execute(onerror);
+    }
     else
       return 0;                        /* Exit */
   }
index cb2eb6e..ea17dbc 100644 (file)
@@ -60,6 +60,7 @@ extern long long totaltimeout;
 
 extern char *menu_title;
 extern char *ontimeout;
+extern char *onerror;
 extern char *menu_master_passwd;
 
 void parse_config(const char *filename);
index 37898eb..69404d0 100644 (file)
@@ -23,6 +23,7 @@
 #include "menu.h"
 
 int nentries     = 0;
+int nhidden      = 0;
 int defentry     = 0;
 int allowedit    = 1;          /* Allow edits of the command line */
 int timeout      = 0;
@@ -31,10 +32,12 @@ long long totaltimeout = 0;
 
 char *menu_title  = "";
 char *ontimeout   = NULL;
+char *onerror     = NULL;
 
 char *menu_master_passwd = NULL;
 
 struct menu_entry menu_entries[MAX_ENTRIES];
+struct menu_entry hide_entries[MAX_ENTRIES];
 struct menu_entry *menu_hotkeys[256];
 
 #define astrdup(x) ({ char *__x = (x); \
@@ -159,7 +162,7 @@ record(struct labeldata *ld, char *append)
     if ( !a ) a = append;
     if ( !a || (a[0] == '-' && !a[1]) ) a = "";
     s = a[0] ? " " : "";
-    asprintf(&me->cmdline, "%s%s%s%s", ld->kernel, ipoptions, s, a);
+    asprintf(&me->cmdline, "%s%s%s%s", ld->kernel, s, a, ipoptions);
 
     ld->label = NULL;
     ld->passwd = NULL;
@@ -181,6 +184,19 @@ record(struct labeldata *ld, char *append)
 
       nentries++;
     }
+    else {
+      hide_entries[nhidden].displayname = me->displayname;
+      hide_entries[nhidden].label       = me->label;
+      hide_entries[nhidden].cmdline     = me->cmdline;
+      hide_entries[nhidden].passwd      = me->passwd;
+
+      me->displayname = NULL;
+      me->label       = NULL;
+      me->cmdline     = NULL;
+      me->passwd      = NULL;
+
+      nhidden++;
+    }
   }
 }
 
@@ -215,6 +231,21 @@ unlabel(char *str)
     }
   }
 
+  for ( i = 0 ; i < nhidden ; i++ ) {
+    me = &hide_entries[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;
 }
 
@@ -223,6 +254,7 @@ void parse_config(const char *filename)
   char line[MAX_LINE], *p, *ep;
   FILE *f;
   char *append = NULL;
+  unsigned int ipappend = 0;
   static struct labeldata ld;
 
   get_ipappend();
@@ -260,6 +292,8 @@ void parse_config(const char *filename)
        ld.passwd = strdup(skipspace(p+6));
       } else if ( looking_at(p, "shiftkey") ) {
        shiftkey = 1;
+      } else if ( looking_at(p, "onerror") ) {
+       onerror = strdup(skipspace(p+7));
       } else if ( looking_at(p, "master") ) {
        p = skipspace(p+6);
        if ( looking_at(p, "passwd") ) {
@@ -289,7 +323,8 @@ void parse_config(const char *filename)
       ld.passwd    = NULL;
       ld.append    = NULL;
       ld.menulabel = NULL;
-      ld.ipappend  = ld.menudefault = ld.menuhide = 0;
+      ld.ipappend  = ipappend;
+      ld.menudefault = ld.menuhide = 0;
     } else if ( looking_at(p, "kernel") ) {
       if ( ld.label ) {
        free(ld.kernel);
@@ -300,11 +335,14 @@ 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 = skipspace(p+9);
+      ontimeout = strdup(skipspace(p+9));
     } else if ( looking_at(p, "allowoptions") ) {
       allowedit = atoi(skipspace(p+12));
     } else if ( looking_at(p, "ipappend") ) {
-      ld.ipappend = atoi(skipspace(p+8));
+      if (ld.label) 
+        ld.ipappend = atoi(skipspace(p+8));
+      else
+       ipappend = atoi(skipspace(p+8));
     } else if ( looking_at(p, "localboot") ) {
       ld.kernel = strdup(".localboot");
       ld.append = strdup(skipspace(p+9));
@@ -316,4 +354,6 @@ void parse_config(const char *filename)
 
   if ( ontimeout )
     ontimeout = unlabel(ontimeout);
+  if ( onerror )
+    onerror = unlabel(onerror);
 }