From 77679bcf7e25a5ca3ef58e0b4b51c1ea76449606 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 21 Aug 2013 15:26:12 +0200 Subject: issue 4, c version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/argparser.c | 37 +++++++++++++++++++++++++++++++++---- src/argparser.h | 8 ++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/argparser.c b/src/argparser.c index ec1da0a..e507986 100644 --- a/src/argparser.c +++ b/src/argparser.c @@ -668,6 +668,21 @@ char* args_optmap_get_standard(char* name) return (*(args_options + args_optmap_get_index(name))).standard; } +/** + * Trigger an option + * + * @param name The option's alternative name + * @param value The use value, `null` if argumentless or variadic + */ +void args_optmap_trigger(char* name, char* value) +{ + args_Option* opt = args_options + args_optmap_get_index(name); + if (value == null) + opt->trigger(name, opt->standard); + else + opt->triggerv(name, opt->standard, value); +} + /** * Adds an option @@ -1223,7 +1238,7 @@ long args_parse(int argc, char** argv) char* arg = *argv++; if ((get > 0) && (dontget == 0)) { - get--; + args_optmap_trigger(*(optqueue + optptr - get--), arg); *(argqueue + argptr++) = arg; } else if (tmpdashed) @@ -1259,6 +1274,7 @@ long args_parse(int argc, char** argv) { *(optqueue + optptr++) = arg; *(argqueue + argptr++) = null; + args_optmap_trigger(arg, null); } else if (*(arg + eq) == '=') { @@ -1273,7 +1289,12 @@ long args_parse(int argc, char** argv) *(argqueue + argptr++) = arg + eq + 1; *(args_freequeue + args_freeptr++) = arg_opt; if (type == VARIADIC) - dashed = true; + { + dashed = true; + args_optmap_trigger(arg_opt, null); + } + else + args_optmap_trigger(arg_opt, arg + eq + 1); } else { @@ -1293,6 +1314,7 @@ long args_parse(int argc, char** argv) *(optqueue + optptr++) = arg; *(argqueue + argptr++) = null; dashed = true; + args_optmap_trigger(arg, null); } } } @@ -1313,11 +1335,17 @@ long args_parse(int argc, char** argv) *(args_freequeue + args_freeptr++) = narg; *(optqueue + optptr++) = narg; if (type == ARGUMENTLESS) - *(argqueue + argptr++) = null; + { + *(argqueue + argptr++) = null; + args_optmap_trigger(narg, null); + } else if (type == ARGUMENTED) { if (*(arg + i)) - *(argqueue + argptr++) = arg + i; + { + *(argqueue + argptr++) = arg + i; + args_optmap_trigger(narg, arg + i); + } else get++; break; @@ -1326,6 +1354,7 @@ long args_parse(int argc, char** argv) { *(argqueue + argptr++) = *(arg + i) ? (arg + i) : null; dashed = true; + args_optmap_trigger(narg, null); break; } } diff --git a/src/argparser.h b/src/argparser.h index 41040ad..32e2dd5 100644 --- a/src/argparser.h +++ b/src/argparser.h @@ -296,6 +296,14 @@ extern char* args_options_get_argument(long index); */ extern char* args_options_get_standard(long index); +/** + * Trigger an option + * + * @param name The option's alternative name + * @param value The use value, `null` if argumentless or variadic + */ +void args_optmap_trigger(char* name, char* value); + /** * Gets the help text for a option with a specific index * -- cgit v1.2.3-70-g09d2