Author: mcayland Date: Sun Jan 13 16:26:57 2013 New Revision: 1088 URL: http://tracker.coreboot.org/trac/openbios/changeset/1088
Log: Switch partition argument parsing to use left-parse-string as per CHRP bindings.
As suggested in the PPC CHRP bindings, use the Forth left-parse-string word to parse the arguments passed to open in the mac-parts, sun-parts and pc-parts packages. This results is a much less complicated and more robust argument parser.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk
Modified: trunk/openbios-devel/packages/mac-parts.c trunk/openbios-devel/packages/pc-parts.c trunk/openbios-devel/packages/sun-parts.c
Modified: trunk/openbios-devel/packages/mac-parts.c ============================================================================== --- trunk/openbios-devel/packages/mac-parts.c Sun Jan 13 16:26:53 2013 (r1087) +++ trunk/openbios-devel/packages/mac-parts.c Sun Jan 13 16:26:57 2013 (r1088) @@ -49,8 +49,7 @@ macparts_open( macparts_info_t *di ) { char *str = my_args_copy(); - char *argstr = strdup(""); - char *parstr = strdup(""); + char *parstr = NULL, *argstr = NULL; int bs, parnum=-1, apple_parnum=-1; int parlist[2], parlist_size = 0; desc_map_t dmap; @@ -67,47 +66,32 @@ id: [0-7] [(id)][,][filespec] */ - - if( str ) { - if ( !strlen(str) ) - parnum = -1; - else { - /* Detect the boot parameters */ - char *ptr; - ptr = str; - - /* <id>,<file> */ - if (*ptr >= '0' && *ptr <= '9' && *(ptr + 1) == ',') { - parstr = ptr; - *(ptr + 1) = '\0'; - argstr = ptr + 2; - } - - /* <id> */ - else if (*ptr >= '0' && *ptr <='9' && *(ptr + 1) == '\0') { - parstr = ptr; - } - - /* ,<file> */ - else if (*ptr == ',') { - argstr = ptr + 1; - } - - /* <file> */ - else { - argstr = str; - } - - /* Convert the id to a partition number */ - if (strlen(parstr)) - parnum = atol(parstr); - - /* Detect if we are looking for the bootcode */ - if (strcmp(argstr, "%BOOT") == 0) - want_bootcode = 1; + + if ( strlen(str) ) { + /* Detect the arguments */ + if ((*str >= '0' && *str <= '9') || (*str == ',')) { + push_str(str); + PUSH(','); + fword("left-parse-string"); + parstr = pop_fstr_copy(); + argstr = pop_fstr_copy(); + } else { + argstr = str; } + + /* Convert the id to a partition number */ + if (parstr && strlen(parstr)) + parnum = atol(parstr); + + /* Detect if we are looking for the bootcode */ + if (strcmp(argstr, "%BOOT") == 0) + want_bootcode = 1; }
+ /* Make sure argstr is not null */ + if (argstr == NULL) + argstr = strdup(""); + DPRINTF("parstr: %s argstr: %s parnum: %d\n", parstr, argstr, parnum);
DPRINTF("want_bootcode %d\n", want_bootcode); @@ -230,7 +214,7 @@ /* Make sure our partition is valid */ parnum = parlist[j]; - DPRINTF("Selected partition %d to boot\n", parnum); + DPRINTF("Selected partition %d\n", parnum); SEEK( bs * parnum ); READ( &par, sizeof(par) );
Modified: trunk/openbios-devel/packages/pc-parts.c ============================================================================== --- trunk/openbios-devel/packages/pc-parts.c Sun Jan 13 16:26:53 2013 (r1087) +++ trunk/openbios-devel/packages/pc-parts.c Sun Jan 13 16:26:57 2013 (r1088) @@ -94,42 +94,27 @@ [(id)][,][filespec] */
- if( str ) { - if ( !strlen(str) ) - parnum = -1; - else { - /* Detect the boot parameters */ - char *ptr; - ptr = str; - - /* <id>,<file> */ - if (*ptr >= '0' && *ptr <= '9' && *(ptr + 1) == ',') { - parstr = ptr; - *(ptr + 1) = '\0'; - argstr = ptr + 2; - } - - /* <id> */ - else if (*ptr >= '0' && *ptr <='9' && *(ptr + 1) == '\0') { - parstr = ptr; - } - - /* ,<file> */ - else if (*ptr == ',') { - argstr = ptr + 1; - } - - /* <file> */ - else { - argstr = str; - } - - /* Convert the id to a partition number */ - if (strlen(parstr)) - parnum = atol(parstr); + if ( strlen(str) ) { + /* Detect the arguments */ + if ((*str >= '0' && *str <= '7') || (*str == ',')) { + push_str(str); + PUSH(','); + fword("left-parse-string"); + parstr = pop_fstr_copy(); + argstr = pop_fstr_copy(); + } else { + argstr = str; } + + /* Convert the id to a partition number */ + if (parstr && strlen(parstr)) + parnum = atol(parstr); }
+ /* Make sure argstr is not null */ + if (argstr == NULL) + argstr = strdup(""); + DPRINTF("parstr: %s argstr: %s parnum: %d\n", parstr, argstr, parnum); free(parstr);
Modified: trunk/openbios-devel/packages/sun-parts.c ============================================================================== --- trunk/openbios-devel/packages/sun-parts.c Sun Jan 13 16:26:53 2013 (r1087) +++ trunk/openbios-devel/packages/sun-parts.c Sun Jan 13 16:26:57 2013 (r1088) @@ -109,46 +109,31 @@ [(id)][,][filespec] */
- if( str ) { - if ( !strlen(str) ) - parnum = -1; - else { - /* Detect the boot parameters */ - char *ptr; - ptr = str; - - /* <id>,<file> */ - if (((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'a' && *ptr <= 'a' + 8)) && *(ptr + 1) == ',') { - parstr = ptr; - *(ptr + 1) = '\0'; - argstr = ptr + 2; - } - - /* <id> */ - else if (((*ptr >= '0' && *ptr <= '9') || (*ptr >= 'a' && *ptr <= 'a' + 8)) && *(ptr + 1) == '\0') { - parstr = ptr; - } - - /* ,<file> */ - else if (*ptr == ',') { - argstr = ptr + 1; - } - - /* <file> */ - else { - argstr = str; - } + if ( strlen(str) ) { + /* Detect the arguments */ + if ((*str >= '0' && *str <= '9') || (*str >= 'a' && *str < ('a' + 8)) || (*str == ',')) { + push_str(str); + PUSH(','); + fword("left-parse-string"); + parstr = pop_fstr_copy(); + argstr = pop_fstr_copy(); + } else { + argstr = str; + } - /* Convert the id to a partition number */ - if (parstr && strlen(parstr)) { - if (parstr[0] >= 'a' && parstr[0] < ('a' + 8)) - parnum = parstr[0] - 'a'; - else - parnum = atol(parstr); - } + /* Convert the id to a partition number */ + if (parstr && strlen(parstr)) { + if (parstr[0] >= 'a' && parstr[0] < ('a' + 8)) + parnum = parstr[0] - 'a'; + else + parnum = atol(parstr); } }
+ /* Make sure argstr is not null */ + if (argstr == NULL) + argstr = strdup(""); + DPRINTF("parstr: %s argstr: %s parnum: %d\n", parstr, argstr, parnum);
di->filesystem_ph = 0;