On Mon, Jun 23, 2008 at 07:16:17PM +0000, Linus Torvalds wrote:
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 =3D *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 =3D parse_options_end(&ctx);
}
It's slightly more involved than what Linus handwaved, but I believe
it's usable this way.
--=20
=C2=B7O=C2=B7 Pierre Habouzit
=C2=B7=C2=B7O madcoder@debia=
n.org
OOO http://www.madism.org