[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <151075906562.14434.17655499193254963975.stgit@hbathini.in.ibm.com>
Date: Wed, 15 Nov 2017 20:48:25 +0530
From: Hari Bathini <hbathini@...ux.vnet.ibm.com>
To: linuxppc-dev <linuxppc-dev@...abs.org>,
Andrew Morton <akpm@...ux-foundation.org>,
lkml <linux-kernel@...r.kernel.org>
Cc: Michael Ellerman <mpe@...erman.id.au>,
Ankit Kumar <ankit@...ux.vnet.ibm.com>,
Michal Suchánek <msuchanek@...e.de>,
Mahesh J Salgaonkar <mahesh@...ux.vnet.ibm.com>
Subject: [PATCH v9 5/8] lib/cmdline.c: implement single quotes in
commandline argument parsing
From: Michal Suchanek <msuchanek@...e.de>
This brings the kernel parser about on par with bourne shell, grub, and
other tools that chew the arguments before kernel does.
This should make it easier to deal with multiple levels of
nesting/quoting. With same quoting grammar on each level there is less
room for confusion.
Signed-off-by: Michal Suchanek <msuchanek@...e.de>
---
lib/cmdline.c | 29 ++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/lib/cmdline.c b/lib/cmdline.c
index d98bdc0..c5335a7 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -191,34 +191,45 @@ bool parse_option_str(const char *str, const char *option)
return false;
}
+#define squash_char { \
+ memmove(args + 1, args, i); \
+ args++; \
+ i--; \
+}
+
/*
* Parse a string to get a param value pair.
- * You can use " around spaces, and you can escape with \
+ * You can use " or ' around spaces, and you can escape with \
* Hyphens and underscores equivalent in parameter names.
*/
char *next_arg(char *args, char **param, char **val)
{
unsigned int i, equals = 0;
- int in_quote = 0, backslash = 0;
+ int in_quote = 0, backslash = 0, in_single = 0;
char *next;
for (i = 0; args[i]; i++) {
- if (isspace(args[i]) && !in_quote && !backslash)
+ if (isspace(args[i]) && !in_quote && !backslash && !in_single)
break;
if ((equals == 0) && (args[i] == '='))
equals = i;
- if (!backslash) {
- if ((args[i] == '"') || (args[i] == '\\')) {
+ if (in_single) {
+ if (args[i] == '\'') {
+ in_single = 0;
+ squash_char;
+ }
+ } else if (!backslash) {
+ if ((args[i] == '"') || (args[i] == '\\') ||
+ (args[i] == '\'')) {
if (args[i] == '"')
in_quote = !in_quote;
if (args[i] == '\\')
backslash = 1;
-
- memmove(args + 1, args, i);
- args++;
- i--;
+ if (args[i] == '\'')
+ in_single = 1;
+ squash_char;
}
} else {
backslash = 0;
Powered by blists - more mailing lists