Re: [RFC] Re: Convert 'git blame' to parse_options()
- From
Pierre Habouzit <madcoder@debian.org>
- Date
- Jun 23, 2008, 21:09 UTC
- Message-ID
- <20080623210935.GC13395@artemis.madism.org>
- In-Reply-To
- <alpine.LFD.1.10.0806231158340.2926@woody.linux-foundation.org>
On Mon, Jun 23, 2008 at 07:16:17PM +0000, Linus Torvalds wrote:
Show 7 quoted lines
> > > On Mon, 23 Jun 2008, Linus Torvalds wrote: > > > > Or are we going to sit around discussing this for another five months? > > So the gauntlet is thrown.
Let's see if I can catch it elegantly.
Following is a series split into incremental patches to migrate the parse_options API to an incremental one. Only the last step provides a functional incremental API.
With that, you write parsers this way:
{
struct parse_opt_ctx_t ctx;parse_options_start(&ctx, argc, argv, 0);
for (;;) {
const char *arg; switch (parse_options_step(&ctx, options, usagestr)) {
case PARSE_OPT_HELP:
/* dump your help here, the one for options/usagestr is already dumped */
exit(129);
case PARSE_OPT_DONE:
goto done;
} arg = *ctx->argv++;
ctx->argc--; if (strcmp(arg, "-")) {
/* you're on baby ! */
} else if ....
} else {
error("unknown option %s", arg);
parse_options_usage(options, usagestr);
/* dump your help here */
exit(129);
}
}done:
argc = parse_options_end(&ctx);
}It's slightly more involved than what Linus handwaved, but I believe it's usable this way.
-- ·O· Pierre Habouzit ··O madcoder@debian.org OOO http://www.madism.org