summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 07fe54d)
raw | patch | inline | side by side (parent: 07fe54d)
author | Pierre Habouzit <madcoder@debian.org> | |
Mon, 23 Jun 2008 20:55:11 +0000 (22:55 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 30 Jun 2008 21:51:13 +0000 (14:51 -0700) |
If we begin to parse -abc and that the parser knew about -a and -b, it
will fake a -c switch for the caller to deal with.
Of course in the case of -acb (supposing -c is not taking an argument) the
caller will have to be especially clever to do the same thing. We could
think about exposing an API to do so if it's really needed, but oh well...
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
will fake a -c switch for the caller to deal with.
Of course in the case of -acb (supposing -c is not taking an argument) the
caller will have to be especially clever to do the same thing. We could
think about exposing an API to do so if it's really needed, but oh well...
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
parse-options.c | patch | blob | history | |
parse-options.h | patch | blob | history |
diff --git a/parse-options.c b/parse-options.c
index 19fc849f4b2728f9d40db9e0a8f50cecc165b86c..0d3818ab4884e1df51d5e082df2a1e80d2582cdd 100644 (file)
--- a/parse-options.c
+++ b/parse-options.c
#include "git-compat-util.h"
#include "parse-options.h"
+#include "cache.h"
#define OPT_SHORT 1
#define OPT_UNSET 2
const struct option *options,
const char * const usagestr[])
{
+ /* we must reset ->opt, unknown short option leave it dangling */
+ ctx->opt = NULL;
+
for (; ctx->argc; ctx->argc--, ctx->argv++) {
const char *arg = ctx->argv[0];
case -1:
return parse_options_usage(usagestr, options);
case -2:
+ /* fake a short option thing to hide the fact that we may have
+ * started to parse aggregated stuff
+ *
+ * This is leaky, too bad.
+ */
+ ctx->argv[0] = xstrdup(ctx->opt - 1);
+ *(char *)ctx->argv[0] = '-';
return PARSE_OPT_UNKNOWN;
}
}
diff --git a/parse-options.h b/parse-options.h
index 33c683cb5459f8da0e165e3d270a53a985227071..aeed627e9757df03df94a2c93bbd8112f4bb9a2c 100644 (file)
--- a/parse-options.h
+++ b/parse-options.h
PARSE_OPT_UNKNOWN,
};
+/*
+ * It's okay for the caller to consume argv/argc in the usual way.
+ * Other fields of that structure are private to parse-options and should not
+ * be modified in any way.
+ */
struct parse_opt_ctx_t {
const char **argv;
const char **out;