[PATCH 05/11] parseopt: add a new PARSE_OPT_ARGV0_IS_AN_OPTION option

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Miklos Vajna
Date: Thursday, June 19, 2008 - 4:22 pm

This new option tells parse-options not to ignore argv[0]. This is
useful when argv cames from split_cmdline(), as in that case argv[0]
contains a valuable option as well.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
---
 parse-options.c |    5 +++++
 parse-options.h |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/parse-options.c b/parse-options.c
index b98833c..1d01a86 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -249,6 +249,11 @@ int parse_options(int argc, const char **argv, const struct option *options,
 {
 	struct optparse_t args = { argv + 1, argv, argc - 1, 0, NULL };
 
+	if (flags & PARSE_OPT_ARGV0_IS_AN_OPTION) {
+		args.argv = argv;
+		args.argc = argc;
+	}
+
 	for (; args.argc; args.argc--, args.argv++) {
 		const char *arg = args.argv[0];
 
diff --git a/parse-options.h b/parse-options.h
index 4ee443d..3238401 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -20,6 +20,7 @@ enum parse_opt_type {
 enum parse_opt_flags {
 	PARSE_OPT_KEEP_DASHDASH = 1,
 	PARSE_OPT_STOP_AT_NON_OPTION = 2,
+	PARSE_OPT_ARGV0_IS_AN_OPTION = 4,
 };
 
 enum parse_opt_option_flags {
-- 
1.5.6

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/11] Build in merge, Miklos Vajna, (Thu Jun 19, 4:22 pm)
[PATCH 01/11] Move split_cmdline() to alias.c, Miklos Vajna, (Thu Jun 19, 4:22 pm)
[PATCH 02/11] Move commit_list_count() to commit.c, Miklos Vajna, (Thu Jun 19, 4:22 pm)
[PATCH 05/11] parseopt: add a new PARSE_OPT_ARGV0_IS_AN_OP ..., Miklos Vajna, (Thu Jun 19, 4:22 pm)
[PATCH 10/11] Build in merge, Miklos Vajna, (Thu Jun 19, 4:22 pm)