aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2013-08-27 23:15:41 +0200
committerMattias Andrée <maandree@operamail.com>2013-08-27 23:15:41 +0200
commitf5665923655e8743376969b27ddd8feee47eb84a (patch)
treec03ee02e9773e5a8a07c62b8fac795373c960341
parentc fix (diff)
downloadargparser-f5665923655e8743376969b27ddd8feee47eb84a.tar.gz
argparser-f5665923655e8743376969b27ddd8feee47eb84a.tar.bz2
argparser-f5665923655e8743376969b27ddd8feee47eb84a.tar.xz
version common bugs
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/argparser.bash9
-rw-r--r--src/argparser.c20
-rw-r--r--src/argparser.py11
3 files changed, 29 insertions, 11 deletions
diff --git a/src/argparser.bash b/src/argparser.bash
index e7d65cd..99711c3 100644
--- a/src/argparser.bash
+++ b/src/argparser.bash
@@ -635,7 +635,7 @@ function args_help
# @exit Whether no unrecognised option is used
function args_parse
{
- local nulqueue=() argqueue=() optqueue=() queue=() opt arg _arg argnull trigger
+ local nulqueue=() argqueue=() optqueue=() queue=() opt arg _arg argnull trigger value
local dashed=0 tmpdashed=0 get=0 dontget=0 rc=0 i n more std sign type opt_arg passed
args_argcount=$#
@@ -707,9 +707,10 @@ function args_parse
if [ -e "${args_optmap}/${_arg}" ]; then
type="$(head -n 2 < "${args_optmap}/${_arg}" | tail -n 1)"
fi
+ value="${arg#*=}"
if [ ! $type = x ] && (( $type >= ${args_ARGUMENTED} )); then
optqueue+=( "${_arg}" )
- argqueue+=( "${arg#*=}" )
+ argqueue+=( "${value}" )
nulqueue+=( 0 )
std="$(head -n 1 < "${args_optmap}/${_arg}")"
trigger="$(tail -n 1 < "${args_optmap}/${_arg}")"
@@ -717,13 +718,13 @@ function args_parse
dashed=1
"$trigger" "${_arg}" "${std}"
else
- "$trigger" "${_arg}" "${std}" "${arg#*=}"
+ "$trigger" "${_arg}" "${std}" "${value}"
fi
else
arg="${_arg}"
_arg="$(args__abbreviations "${arg}")"
if [ $? = 0 ]; then
- arg=( "${_arg}" "$@" )
+ arg=( "${_arg}=${value}" "$@" )
set -- "${arg[@]}"
else
(( args_unrecognised_count++ ))
diff --git a/src/argparser.c b/src/argparser.c
index aa9650a..7bbcb26 100644
--- a/src/argparser.c
+++ b/src/argparser.c
@@ -1382,7 +1382,7 @@ long args_parse(int argc, char** argv)
argqueue = (char**)malloc(queuesize * sizeof(char*));
optqueue = (char**)malloc(queuesize * sizeof(char*));
- args_freequeue = (void**)malloc(queuesize * sizeof(void*));
+ args_freequeue = (void**)malloc(queuesize * sizeof(void*) * 2);
while ((argv != argend) || injection)
{
@@ -1461,7 +1461,23 @@ long args_parse(int argc, char** argv)
}
else
{
- if ((injection = args__abbreviations(arg_opt)) == null)
+ if ((injection = args__abbreviations(arg_opt)))
+ {
+ long n = 1, i, j = 0;
+ char* _injection;
+ for (i = 0; *(injection + i); i++)
+ n++;
+ for (i = eq + 1; *(arg + i); i++)
+ n++;
+ *(args_freequeue + args_freeptr++) = _injection = (char*)malloc((n + 1) * sizeof(char));
+ for (i = 0; *(injection + i); i++)
+ *(_injection + j++) = *(injection + i);
+ *((injection = _injection) + j++) = '=';
+ for (i = eq + 1; *(arg + i); i++)
+ *(injection + j++) = *(arg + i);
+ *(injection + j) = 0;
+ }
+ else
{
if (++args_unrecognised_count <= 5)
fprintf(args_out, "%s: warning: unrecognised option %s\n", args_program, arg_opt);
diff --git a/src/argparser.py b/src/argparser.py
index fcdad91..8f94c2e 100644
--- a/src/argparser.py
+++ b/src/argparser.py
@@ -283,20 +283,21 @@ class ArgParser():
argqueue.append(None)
elif '=' in arg:
arg_opt = arg[:arg.index('=')]
+ value = arg[arg.index('=') + 1:]
if (arg_opt in self.optmap) and (self.optmap[arg_opt][1] >= ArgParser.ARGUMENTED):
optqueue.append(arg_opt)
- argqueue.append(arg[arg.index('=') + 1:])
+ argqueue.append(value)
if self.optmap[arg_opt][1] == ArgParser.VARIADIC:
dashed = True
self.optmap[arg_opt][2](arg_opt, self.optmap[arg_opt][0])
else:
- self.optmap[arg_opt][2](arg_opt, self.optmap[arg_opt][0], argqueue[-1])
+ self.optmap[arg_opt][2](arg_opt, self.optmap[arg_opt][0], value)
else:
- _arg = self.__abbreviations(arg)
+ _arg = self.__abbreviations(arg_opt)
if _arg is None:
- unrecognised(arg)
+ unrecognised(arg_opt)
else:
- queue[0:0] = [_arg]
+ queue[0:0] = ['%s=%s' % (_arg, value)]
elif (arg in self.optmap) and (self.optmap[arg][1] <= ArgParser.OPTARGUMENTED):
optqueue.append(arg)
get += 1