On Mon, Jun 23, 2008 at 07:16:17PM +0000, Linus Torvalds wrote: > > > 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@xxxxxxxxxx OOO http://www.madism.org
Attachment:
pgp5cWR8q1rIJ.pgp
Description: PGP signature