summaryrefslogtreecommitdiffstats
path: root/src/cli/opt.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/cli/opt.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/cli/opt.c b/src/cli/opt.c
index 62a3430..9242e22 100644
--- a/src/cli/opt.c
+++ b/src/cli/opt.c
@@ -10,7 +10,7 @@
* This file was produced by using the `rename.pl` script included with
* adopt. The command-line specified was:
*
- * ./rename.pl cli_opt --filename=opt --include=cli.h --inline=GIT_INLINE --header-guard=CLI_opt_h__ --lowercase-status --without-usage
+ * ./rename.pl cli_opt --filename=opt --include=common.h --inline=GIT_INLINE --header-guard=CLI_opt_h__ --lowercase-status --without-usage
*/
#include <stdlib.h>
@@ -19,7 +19,11 @@
#include <limits.h>
#include <assert.h>
-#include "cli.h"
+#if defined(__sun) || defined(__illumos__)
+# include <alloca.h>
+#endif
+
+#include "common.h"
#include "opt.h"
#ifdef _WIN32
@@ -73,7 +77,7 @@ GIT_INLINE(const cli_opt_spec *) spec_for_long(
/* Handle --option=value arguments */
if (spec->type == CLI_OPT_TYPE_VALUE &&
- eql &&
+ spec->name && eql &&
strncmp(arg, spec->name, eql_pos) == 0 &&
spec->name[eql_pos] == '\0') {
*has_value = 1;
@@ -575,6 +579,28 @@ cli_opt_status_t cli_opt_parse(
return validate_required(opt, specs, given_specs);
}
+int cli_opt_foreach(
+ const cli_opt_spec specs[],
+ char **args,
+ size_t args_len,
+ unsigned int flags,
+ int (*callback)(cli_opt *, void *),
+ void *callback_data)
+{
+ cli_opt_parser parser;
+ cli_opt opt;
+ int ret;
+
+ cli_opt_parser_init(&parser, specs, args, args_len, flags);
+
+ while (cli_opt_parser_next(&opt, &parser)) {
+ if ((ret = callback(&opt, callback_data)) != 0)
+ return ret;
+ }
+
+ return 0;
+}
+
static int spec_name_fprint(FILE *file, const cli_opt_spec *spec)
{
int error;