summaryrefslogtreecommitdiffstats
path: root/lib/cmdline.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/cmdline.c')
-rw-r--r--lib/cmdline.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/cmdline.c b/lib/cmdline.c
index 8f13cf73c2ec..3c6432df7e63 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -15,6 +15,7 @@
15#include <linux/export.h> 15#include <linux/export.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/string.h> 17#include <linux/string.h>
18#include <linux/ctype.h>
18 19
19/* 20/*
20 * If a hyphen was found in get_option, this will handle the 21 * If a hyphen was found in get_option, this will handle the
@@ -189,3 +190,59 @@ bool parse_option_str(const char *str, const char *option)
189 190
190 return false; 191 return false;
191} 192}
193
194/*
195 * Parse a string to get a param value pair.
196 * You can use " around spaces, but can't escape ".
197 * Hyphens and underscores equivalent in parameter names.
198 */
199char *next_arg(char *args, char **param, char **val)
200{
201 unsigned int i, equals = 0;
202 int in_quote = 0, quoted = 0;
203 char *next;
204
205 if (*args == '"') {
206 args++;
207 in_quote = 1;
208 quoted = 1;
209 }
210
211 for (i = 0; args[i]; i++) {
212 if (isspace(args[i]) && !in_quote)
213 break;
214 if (equals == 0) {
215 if (args[i] == '=')
216 equals = i;
217 }
218 if (args[i] == '"')
219 in_quote = !in_quote;
220 }
221
222 *param = args;
223 if (!equals)
224 *val = NULL;
225 else {
226 args[equals] = '\0';
227 *val = args + equals + 1;
228
229 /* Don't include quotes in value. */
230 if (**val == '"') {
231 (*val)++;
232 if (args[i-1] == '"')
233 args[i-1] = '\0';
234 }
235 }
236 if (quoted && args[i-1] == '"')
237 args[i-1] = '\0';
238
239 if (args[i]) {
240 args[i] = '\0';
241 next = args + i + 1;
242 } else
243 next = args + i;
244
245 /* Chew up trailing spaces. */
246 return skip_spaces(next);
247 //return next;
248}