X-Git-Url: http://git.ozlabs.org/?p=yaboot.git;a=blobdiff_plain;f=second%2Fcfg.c;h=2787558181a16768f957666b6f9cbc7ae720ac0a;hp=4167582ae538324bae1572fe536eb4d116ba3a44;hb=ad973226cb9266ce5cf6946833387c0549c4f3f2;hpb=be7cdc5970eef6bf45394304a0aaeb1ae203d456 diff --git a/second/cfg.c b/second/cfg.c index 4167582..2787558 100644 --- a/second/cfg.c +++ b/second/cfg.c @@ -29,6 +29,7 @@ /* Imported functions */ extern int strcasecmp(const char *s1, const char *s2); extern int strncasecmp(const char *cs, const char *ct, size_t n); +extern char bootoncelabel[1024]; typedef enum { cft_strg, cft_flag, cft_end @@ -40,8 +41,7 @@ typedef struct { void *data; } CONFIG; -#define MAX_TOKEN 200 -#define MAX_VAR_NAME MAX_TOKEN +#define MAX_TOKEN 511 #define EOF -1 CONFIG cf_options[] = @@ -91,7 +91,6 @@ CONFIG cf_image[] = {cft_flag, "pause-after", NULL}, {cft_strg, "pause-message", NULL}, {cft_flag, "novideo", NULL}, - {cft_strg, "sysmap", NULL}, {cft_end, NULL, NULL}}; static char flag_set; @@ -102,7 +101,6 @@ static char *currp = NULL; static char *endp = NULL; static char *file_name = NULL; static CONFIG *curr_table = cf_options; -static int ignore_entry; static jmp_buf env; static struct IMAGES { @@ -421,6 +419,30 @@ cfg_set_redo: return 0; } +static int cfg_reset () +{ + CONFIG *walk; +#if DEBUG + prom_printf("Resetting image table\n"); +#endif + line_num = 0; + images = NULL; + curr_table = NULL; + curr_table = cf_options; + for (walk = curr_table; walk->type != cft_end; walk++) { +#if DEBUG + prom_printf("ItemA %s = %s\n", walk->name, (char *)walk->data); +#endif + if (walk->data != NULL) + walk->data = NULL; +#if DEBUG + prom_printf("ItemB %s = %s\n\n", walk->name, (char *)walk->data); +#endif + } + + return 0; +} + int cfg_parse (char *cfg_file, char *buff, int len) { char *item, *value; @@ -429,6 +451,8 @@ int cfg_parse (char *cfg_file, char *buff, int len) currp = buff; endp = currp + len; + cfg_reset(); + if (setjmp (env)) return -1; while (1) { @@ -482,10 +506,16 @@ static int printl_count = 0; static void printlabel (char *label, int defflag) { int len = strlen (label); + char a = ' '; if (!printl_count) prom_printf ("\n"); - prom_printf ("%s %s",defflag?"*":" ", label); + switch (defflag) { + case 1: a='*'; break; + case 2: a='&'; break; + default: a=' '; break; + } + prom_printf ("%c %s", a, label); while (len++ < 25) prom_putchar (' '); printl_count++; @@ -513,7 +543,9 @@ void cfg_print_images (void) if (alias) label = alias + 1; } - if(!strcmp(ret,label)) + if(!strcmp(bootoncelabel,label)) + defflag=2; + else if(!strcmp(ret,label)) defflag=1; else defflag=0; @@ -550,6 +582,43 @@ char *cfg_get_default (void) return ret; } +/* + * cfg_set_default_by_mac () + * return 1 if the default cf_option was changed to label with the MAC addr + * return 0 if not changed + */ +int cfg_set_default_by_mac (char *mac_addr) +{ + CONFIG *walk; + struct IMAGES *tmp; + char * label = NULL; + int haslabel = 0; + + /* check if there is an image label equal to mac_addr */ + for (tmp = images; tmp; tmp = tmp->next) { + label = cfg_get_strg_i (tmp->table, "label"); + if (!strcmp(label,mac_addr)){ + haslabel = 1; + } + } + + if (!haslabel) + return 0; + else { + /* + * if there is an image label equal to mac_addr, change the default + * cf_options to this image label + */ + for (walk = cf_options; walk->type != cft_end; walk++) { + if (!strcasecmp(walk->name,"default")) { + walk->data = mac_addr; + return 1; + } + } + return 0; + } +} + /* * Local variables: * c-file-style: "k&r"