aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2012-11-02 21:52:52 -0400
committerShao Miller <sha0.miller@gmail.com>2012-11-03 01:02:07 -0400
commit8eaa4ebbe2a6999bd58aa68054dd48ec26cabd28 (patch)
treebfd1c7e1b3db27c88c0b202ad26e66f2af05344a
parentb210bd5bfd0d7182b0a65f507c7557eeb90d5b16 (diff)
downloadsyslinux-8eaa4ebbe2a6999bd58aa68054dd48ec26cabd28.tar.gz
syslinux-8eaa4ebbe2a6999bd58aa68054dd48ec26cabd28.tar.xz
syslinux-8eaa4ebbe2a6999bd58aa68054dd48ec26cabd28.zip
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 <sha0.miller@gmail.com> Signed-off-by: Shao Miller <sha0.miller@gmail.com>
-rw-r--r--com32/modules/linux.c57
1 files changed, 41 insertions, 16 deletions
diff --git a/com32/modules/linux.c b/com32/modules/linux.c
index e4c067ff..0d9e962e 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... */