diff options
author | Mattias Andrée <maandree@operamail.com> | 2013-06-21 19:03:39 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2013-06-21 19:03:39 +0200 |
commit | bbc13ab23b04022106fae3685fb7179ea9cac025 (patch) | |
tree | 2194800b86fff88fc60c28629c07a7bbece0a607 | |
parent | give value to args_message (diff) | |
download | argparser-bbc13ab23b04022106fae3685fb7179ea9cac025.tar.gz argparser-bbc13ab23b04022106fae3685fb7179ea9cac025.tar.bz2 argparser-bbc13ab23b04022106fae3685fb7179ea9cac025.tar.xz |
determine a upper bound for the queues sizes
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r-- | src/argparser.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/argparser.c b/src/argparser.c index f1b9359..9f5118d 100644 --- a/src/argparser.c +++ b/src/argparser.c @@ -640,16 +640,31 @@ extern long args_parse(int argc, char** argv) { char** argend = argv + argc; long dashed = false, tmpdashed = false, get = 0, dontget = 0, rc = true; - long argptr = 0, optptr = 0, freeptr = 0, queuesize/*TODO*/ = argc - 1; + long argptr = 0, optptr = 0, freeptr = 0, queuesize = argc - 1; char** argqueue; char** optqueue; char** freequeue; args_unrecognised_count = 0; args_arguments_count = argc - 1; - args_arguments = argv + 1; + args_arguments = ++argv; args_files = (char**)malloc((argc - 1) * sizeof(char*)); + while (argv != argend) + { + char* arg = *argv++; + if (((*arg == '-') || (*arg == '+')) && (*(arg + 1) != 0)) + if (*arg != *(arg + 1)) + { + long i = 1; + while (*(arg + i)) + i++; + queuesize += i - 1; + } + } + + argv = args_arguments; + argqueue = (char**)malloc(queuesize * sizeof(char*)); optqueue = (char**)malloc(queuesize * sizeof(char*)); freequeue = (char**)malloc(queuesize * sizeof(char*)); |