From 66c640578a72b22d79977ade5013ea653f7b718b Mon Sep 17 00:00:00 2001 From: Martin Stubenschrott Date: Thu, 18 Oct 2007 18:30:08 +0000 Subject: [PATCH] allow -option foo in adition to -option=foo --- content/commands.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/content/commands.js b/content/commands.js index b02a2b1f..10bcdb59 100644 --- a/content/commands.js +++ b/content/commands.js @@ -271,8 +271,9 @@ function Commands() //{{{ if (!options) options = []; + var invalid = false; var arg = null; - var count = 0; + var count = 0; // the length of the argument var i = 0; outer: while(i < str.length) @@ -293,11 +294,11 @@ function Commands() //{{{ optname = options[opt][0][name]; if (sub.indexOf(optname) == 0) { - var invalid = false; + invalid = false; + arg = null; // no value to the option - if (optname.length >= sub.length || /\s/.test(sub[optname.length])) + if (optname.length >= sub.length) { - arg = null; count = 0; } else if (sub[optname.length] == "=") @@ -308,6 +309,18 @@ function Commands() //{{{ count++; // to compensate the "=" character } + else if (options[opt][1] != OPTION_NOARG && /\s/.test(sub[optname.length])) + { + [count, arg] = getNextArg(sub.substr(optname.length + 1)); + if (count == -1) + return { error: "Invalid argument for option " + optname, opts: [], args: [] } + + // if we add the argument to an option after a space, it MUST not be empty + if (arg.length == 0) + arg = null; + + count++; // to compensate the " " character + } else { // this isn't really an option as it has trailing characters, parse it as an argument