From 8eaa4ebbe2a6999bd58aa68054dd48ec26cabd28 Mon Sep 17 00:00:00 2001 From: Matt Fleming Date: Fri, 2 Nov 2012 21:52:52 -0400 Subject: [PATCH] linux.c32: Add find_arguments function The 'find_argument' function already finds the last instance of a command-line option. For symmetry, we introduce a 'find_arguments' function which will help to iterate each instance of a command-line option. Also, this commit uses 'strncmp' in both, instead of 'memcmp'. Modified-by: Shao Miller Signed-off-by: Shao Miller --- com32/modules/linux.c | 57 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/com32/modules/linux.c b/com32/modules/linux.c index e4c067f..0d9e962 100644 --- a/com32/modules/linux.c +++ b/com32/modules/linux.c @@ -59,13 +59,34 @@ static char *find_argument(char **argv, const char *argument) char *ptr = NULL; for (arg = argv; *arg; arg++) { - if (!memcmp(*arg, argument, la)) + if (!strncmp(*arg, argument, la)) ptr = *arg + la; } return ptr; } +/* Find the next instance of a particular command line argument */ +static char **find_arguments(char **argv, char **ptr, + const char *argument) +{ + int la = strlen(argument); + char **arg; + + for (arg = argv; *arg; arg++) { + if (!strncmp(*arg, argument, la)) { + *ptr = *arg + la; + break; + } + } + + /* Exhausted all arguments */ + if (!*arg) + return NULL; + + return arg; +} + /* Search for a boolean argument; return its position, or 0 if not present */ static int find_boolean(char **argv, const char *argument) { @@ -246,24 +267,28 @@ int main(int argc, char *argv[]) if (!setup_data) goto bail; - for (argl = argv; (arg = *argl); argl++) { - if (!memcmp(arg, "dtb=", 4)) { - if (setup_data_file(setup_data, SETUP_DTB, arg+4, opt_quiet)) - goto bail; - } else if (!memcmp(arg, "blob.", 5)) { - uint32_t type; - char *ep; + argl = argv; + while ((argl = find_arguments(argl, &arg, "dtb="))) { + argl++; + if (setup_data_file(setup_data, SETUP_DTB, arg, opt_quiet)) + goto bail; + } - type = strtoul(arg + 5, &ep, 10); - if (ep[0] != '=' || !ep[1]) - continue; + argl = argv; + while ((argl = find_arguments(argl, &arg, "blob."))) { + uint32_t type; + char *ep; - if (!type) - continue; + argl++; + type = strtoul(arg, &ep, 10); + if (ep[0] != '=' || !ep[1]) + continue; - if (setup_data_file(setup_data, type, ep+1, opt_quiet)) - goto bail; - } + if (!type) + continue; + + if (setup_data_file(setup_data, type, ep+1, opt_quiet)) + goto bail; } /* This should not return... */ -- 2.7.4