Re: [RFC] Re: Convert 'git blame' to parse_options()

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [RFC] Re: Convert 'git blame' to parse_options()

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:44:48

Pierre Habouzit [off-list ref] writes:
  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);
}
Nice.  I have started doing the same (insignificant details are different;
e.g. I used "positive is unknown" convention instead ) and then the
solution is sitting in my mbox ;-)

Re: [RFC] Re: Convert 'git blame' to parse_options()

From: Pierre Habouzit <hidden>
Date: 2016-06-15 22:44:48

On Mon, Jun 23, 2008 at 09:23:58PM +0000, Junio C Hamano wrote:
Pierre Habouzit [off-list ref] writes:
quoted
  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);
}
Nice.  I have started doing the same (insignificant details are different;
e.g. I used "positive is unknown" convention instead ) and then the
solution is sitting in my mbox ;-)
Well it's still rough on the edges, totally untested (I didn't bother to
run the testsuite), but I wanted some feedback before I cook this to
something nicer.

-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help