From 86b859553463668294b7b573ad067af538ffef1a Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Wed, 20 Sep 2006 16:03:29 -0700 Subject: [PATCH] Support multiple configuration files in the menu systems. --- README.menu | 15 +++++++++++++++ com32/modules/menu.h | 2 +- com32/modules/menumain.c | 2 +- com32/modules/readconfig.c | 41 ++++++++++++++++++++++++++++++----------- 4 files changed, 47 insertions(+), 13 deletions(-) diff --git a/README.menu b/README.menu index 83bf359..dac3596 100644 --- a/README.menu +++ b/README.menu @@ -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 diff --git a/com32/modules/menu.h b/com32/modules/menu.h index e85e4ca..e856977 100644 --- a/com32/modules/menu.h +++ b/com32/modules/menu.h @@ -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) diff --git a/com32/modules/menumain.c b/com32/modules/menumain.c index 433f169..1f6d3c0 100644 --- a/com32/modules/menumain.c +++ b/com32/modules/menumain.c @@ -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. */ diff --git a/com32/modules/readconfig.c b/com32/modules/readconfig.c index 235db82..2c593f0 100644 --- a/com32/modules/readconfig.c +++ b/com32/modules/readconfig.c @@ -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 ) -- 2.7.4