[syslinux:elflink] linux.c32: Add find_arguments function
syslinux-bot for Matt Fleming
matt.fleming at intel.com
Mon Nov 5 08:03:09 PST 2012
Commit-ID: 8eaa4ebbe2a6999bd58aa68054dd48ec26cabd28
Gitweb: http://www.syslinux.org/commit/8eaa4ebbe2a6999bd58aa68054dd48ec26cabd28
Author: Matt Fleming <matt.fleming at intel.com>
AuthorDate: Fri, 2 Nov 2012 21:52:52 -0400
Committer: Shao Miller <sha0.miller at gmail.com>
CommitDate: Sat, 3 Nov 2012 01:02:07 -0400
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 at gmail.com>
Signed-off-by: Shao Miller <sha0.miller at gmail.com>
---
com32/modules/linux.c | 57 +++++++++++++++++++++++++++++++++++-------------
1 files 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... */
More information about the Syslinux-commits
mailing list