mirror of
https://github.com/git/git.git
synced 2026-03-12 18:09:46 +01:00
parse-options: add two helper functions
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user