Support multiple configuration files in the menu systems.
authorH. Peter Anvin <hpa@zytor.com>
Wed, 20 Sep 2006 23:03:29 +0000 (16:03 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Wed, 20 Sep 2006 23:03:29 +0000 (16:03 -0700)
README.menu
com32/modules/menu.h
com32/modules/menumain.c
com32/modules/readconfig.c

index 83bf359..dac3596 100644 (file)
@@ -231,6 +231,10 @@ link; you probably want to set your baudrate to 38400 or higher if
 possible.  It requires a Linux/VT220/ANSI-compatible terminal on the
 other end.
 
+
+       +++ USING AN ALTERNATE CONFIGURATION FILE +++
+
+
 It is also possible to load a secondary configuration file, to get to
 another menu.  To do that, invoke menu.c32 with the name of the
 secondary configuration file.
@@ -239,3 +243,14 @@ LABEL othermenu
        MENU LABEL Another Menu
        KERNEL menu.c32
        APPEND othermenu.conf
+
+If you specify more than one file, they will all be read, in the order
+specified.  However, global APPEND and IPAPPEND will only apply to the
+file currently being processed.
+
+# The file graphics.conf contains common color and layout commands for
+# all menus.
+LABEL othermenu
+       MENU LABEL Another Menu
+       KERNEL vesamenu.c32
+       APPEND graphics.conf othermenu.conf
index e85e4ca..e856977 100644 (file)
@@ -65,7 +65,7 @@ extern char *menu_master_passwd;
 
 extern char *menu_background;
 
-void parse_config(const char *filename);
+void parse_configs(char **argv);
 extern int (*draw_background)(const char *filename);
 
 static inline int my_isspace(char c)
index 433f169..1f6d3c0 100644 (file)
@@ -858,7 +858,7 @@ int menu_main(int argc, char *argv[])
   }
 
   WIDTH = cols;
-  parse_config(argv[1]);
+  parse_configs(argv+1);
 
   /* If anyone has specified negative parameters, consider them
      relative to the bottom row of the screen. */
index 235db82..2c593f0 100644 (file)
@@ -361,22 +361,14 @@ static uint32_t parse_argb(char **p)
   return argb;
 }
 
-void parse_config(const char *filename)
+static void parse_config_file(FILE *f)
 {
   char line[MAX_LINE], *p, *ep;
-  FILE *f;
   char *append = NULL;
   unsigned int ipappend = 0;
-  static struct labeldata ld;
+  struct labeldata ld;
 
-  get_ipappend();
-
-  if ( !filename )
-    filename = get_config();
-
-  f = fopen(filename, "r");
-  if ( !f )
-    return;
+  memset(&ld, 0, sizeof ld);
 
   while ( fgets(line, sizeof line, f) ) {
     p = strchr(line, '\r');
@@ -502,8 +494,35 @@ void parse_config(const char *filename)
   }
 
   record(&ld, append);
+}
+
+static int parse_one_config(const char *filename)
+{
+  FILE *f = fopen(filename, "r");
+  if ( !f )
+    return -1;
+
+  parse_config_file(f);
   fclose(f);
 
+  return 0;
+}
+
+void parse_configs(char **argv)
+{
+  const char *filename;
+
+  get_ipappend();
+
+  if ( !*argv ) {
+    parse_one_config(get_config());
+  } else {
+    while ( (filename = *argv++) )
+      parse_one_config(filename);
+  }
+
+  /* Common postprocessing */
+
   if ( ontimeout )
     ontimeout = unlabel(ontimeout);
   if ( onerror )