Edward O'Callaghan has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/72822 )
Change subject: cli_classic.c: Replace weird strtok() implementation with canonical ......................................................................
cli_classic.c: Replace weird strtok() implementation with canonical
Prepare to use libflashrom flashrom_programmer_init() API over internal programmer_init() implementation from flashrom.c
Change-Id: Icc9473b5b60012a736371dc8545ee0491cb06dc4 Signed-off-by: Edward O'Callaghan quasisec@google.com --- M cli_classic.c 1 file changed, 20 insertions(+), 28 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/22/72822/1
diff --git a/cli_classic.c b/cli_classic.c index c72836f..d4aa27a 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -572,7 +572,7 @@ struct flashctx flashes[8] = {{0}}; struct flashctx *fill_flash; const char *name; - int namelen, opt, i, j; + int opt, i, j; int startchip = -1, chipcount = 0, option_index = 0; int operation_specified = 0; unsigned int wp_start = 0, wp_len = 0; @@ -825,33 +825,11 @@ "with ",". Please see the man page " "for details.\n"); } - size_t p; - for (p = 0; p < programmer_table_size; p++) { - name = programmer_table[p]->name; - namelen = strlen(name); - if (strncmp(optarg, name, namelen) == 0) { - switch (optarg[namelen]) { - case ':': - pparam = strdup(optarg + namelen + 1); - if (!strlen(pparam)) { - free(pparam); - pparam = NULL; - } - prog = programmer_table[p]; - break; - case '\0': - prog = programmer_table[p]; - break; - default: - /* The continue refers to the - * for loop. It is here to be - * able to differentiate between - * foo and foobar. - */ - continue; - } - break; - } + name = strtok(optarg, ":"); + if (name) { + const char *params = strtok(NULL, ":"); + pparam = params ? strdup(params) : NULL; + prog = programmer_name_to_entry(name); } if (prog == NULL) { fprintf(stderr, "Error: Unknown programmer "%s". Valid choices are:\n",