diff options
author | Mattias Andrée <maandree@operamail.com> | 2013-08-21 15:26:12 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2013-08-21 15:26:12 +0200 |
commit | 77679bcf7e25a5ca3ef58e0b4b51c1ea76449606 (patch) | |
tree | 2fa935c0031638e898d7ef18f75e916daf3d26c5 /src/argparser.c | |
parent | Half of the work for issue 4, c version (diff) | |
download | argparser-77679bcf7e25a5ca3ef58e0b4b51c1ea76449606.tar.gz argparser-77679bcf7e25a5ca3ef58e0b4b51c1ea76449606.tar.bz2 argparser-77679bcf7e25a5ca3ef58e0b4b51c1ea76449606.tar.xz |
issue 4, c version
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/argparser.c')
-rw-r--r-- | src/argparser.c | 37 |
1 files changed, 33 insertions, 4 deletions
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; } } |