From: Bo Yang <struggleyb.nku@gmail.com>
To: git@vger.kernel.org
Cc: Jens.Lehmann@web.de, trast@student.ethz.ch, gitster@pobox.com
Subject: [PATCH V5 02/17] parse-options: add two helper functions
Date: Wed, 11 Aug 2010 23:03:27 +0800 [thread overview]
Message-ID: <1281539022-31616-3-git-send-email-struggleyb.nku@gmail.com> (raw)
In-Reply-To: <1281539022-31616-1-git-send-email-struggleyb.nku@gmail.com>
1. parse_options_current: get the current option/argument the API
is dealing with;
2. parse_options_next: skip the current argument, moving to the
next one. Unless 'keep' is set, discard the skipped argument
from the final argument list.
Signed-off-by: Bo Yang <struggleyb.nku@gmail.com>
---
parse-options.c | 19 +++++++++++++++++++
parse-options.h | 4 ++++
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index cbb49d3..e0c3641 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -439,6 +439,25 @@ unknown:
return PARSE_OPT_DONE;
}
+const char *parse_options_current(struct parse_opt_ctx_t *ctx)
+{
+ return ctx->argv[0];
+}
+
+int parse_options_next(struct parse_opt_ctx_t *ctx, int keep)
+{
+ if (ctx->argc <= 0)
+ return -1;
+
+ if (keep)
+ ctx->out[ctx->cpidx++] = ctx->argv[0];
+
+ ctx->argc--;
+ ctx->argv++;
+
+ return 0;
+}
+
int parse_options_end(struct parse_opt_ctx_t *ctx)
{
memmove(ctx->out + ctx->cpidx, ctx->argv, ctx->argc * sizeof(*ctx->out));
diff --git a/parse-options.h b/parse-options.h
index 407697a..d3b1932 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -187,6 +187,10 @@ extern int parse_options_step(struct parse_opt_ctx_t *ctx,
const struct option *options,
const char * const usagestr[]);
+extern const char *parse_options_current(struct parse_opt_ctx_t *ctx);
+
+extern int parse_options_next(struct parse_opt_ctx_t *ctx, int keep);
+
extern int parse_options_end(struct parse_opt_ctx_t *ctx);
extern int parse_options_concat(struct option *dst, size_t, struct option *src);
--
1.7.2.19.g79e5d
next prev parent reply other threads:[~2010-08-11 15:04 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-11 15:03 [PATCH V5 00/17] Reroll a version 5 of this series Bo Yang
2010-08-11 15:03 ` [PATCH V5 01/17] parse-options: enhance STOP_AT_NON_OPTION Bo Yang
2010-08-11 15:03 ` Bo Yang [this message]
2010-08-11 15:03 ` [PATCH V5 03/17] Add the basic data structure for line level history Bo Yang
2010-08-11 15:03 ` [PATCH V5 04/17] Refactor parse_loc Bo Yang
2010-08-11 15:03 ` [PATCH V5 05/17] Parse the -L options Bo Yang
2010-08-11 15:03 ` [PATCH V5 06/17] Export three functions from diff.c Bo Yang
2010-08-11 15:03 ` [PATCH V5 07/17] Add range clone functions Bo Yang
2010-08-11 15:03 ` [PATCH V5 08/17] map/take range to the parent of commits Bo Yang
2010-08-11 15:03 ` [PATCH V5 09/17] Print the line log Bo Yang
2010-08-11 15:03 ` [PATCH V5 10/17] Hook line history into cmd_log, ensuring a topo-ordered walk Bo Yang
2010-08-11 15:03 ` [PATCH V5 11/17] Make rewrite_parents public to other part of git Bo Yang
2010-08-11 15:03 ` [PATCH V5 12/17] Make graph_next_line external " Bo Yang
2010-08-11 15:03 ` [PATCH V5 13/17] Add parent rewriting to line history browser Bo Yang
2010-08-30 17:10 ` log -L crash (Re: [PATCH V5 13/17] Add parent rewriting to line history browser) Jonathan Nieder
2010-09-01 14:47 ` Bo Yang
2010-09-11 21:10 ` [PATCH] log -L: do not free parents lists we might need again Thomas Rast
2010-08-11 15:03 ` [PATCH V5 14/17] Add --graph prefix before line history output Bo Yang
2010-08-11 15:03 ` [PATCH V5 15/17] Add --full-line-diff option Bo Yang
2010-08-11 15:03 ` [PATCH V5 16/17] Add tests for line history browser Bo Yang
2010-08-12 1:25 ` Ævar Arnfjörð Bjarmason
2010-08-12 12:24 ` Bo Yang
2010-08-12 16:27 ` Ævar Arnfjörð Bjarmason
2010-08-12 20:37 ` Junio C Hamano
2010-08-12 21:06 ` Junio C Hamano
2010-08-11 15:03 ` [PATCH V5 17/17] Document " Bo Yang
2010-08-12 8:31 ` [PATCH V5 00/17] Reroll a version 5 of this series david
2010-08-12 17:23 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1281539022-31616-3-git-send-email-struggleyb.nku@gmail.com \
--to=struggleyb.nku@gmail.com \
--cc=Jens.Lehmann@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=trast@student.ethz.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).