X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fopt%2Fparse.c;h=5b2cec8b3d284e0b6795c87355d6ae00cf1290b9;hp=b92bcb14871eed40e4873e8473ac1c359e46d5e7;hb=926996e88c32445c874ff9c4f47f159db6b45995;hpb=74257cee33ae3033f961d5f22a0313b8cb1b18d4 diff --git a/ccan/opt/parse.c b/ccan/opt/parse.c index b92bcb14..5b2cec8b 100644 --- a/ccan/opt/parse.c +++ b/ccan/opt/parse.c @@ -29,12 +29,12 @@ static void consume_option(int *argc, char *argv[], unsigned optnum) } /* Returns 1 if argument consumed, 0 if all done, -1 on error. */ -int parse_one(int *argc, char *argv[], unsigned *offset, +int parse_one(int *argc, char *argv[], enum opt_type is_early, unsigned *offset, void (*errlog)(const char *fmt, ...)) { unsigned i, arg, len; const char *o, *optarg = NULL; - char *problem; + char *problem = NULL; if (getenv("POSIXLY_CORRECT")) { /* Don't find options after non-options. */ @@ -91,11 +91,12 @@ int parse_one(int *argc, char *argv[], unsigned *offset, len = 2; } - if (opt_table[i].type == OPT_NOARG) { + if ((opt_table[i].type & ~OPT_EARLY) == OPT_NOARG) { if (optarg) return parse_err(errlog, argv[0], o, len, "doesn't allow an argument"); - problem = opt_table[i].cb(opt_table[i].u.arg); + if ((opt_table[i].type & OPT_EARLY) == is_early) + problem = opt_table[i].cb(opt_table[i].u.arg); } else { if (!optarg) { /* Swallow any short options as optarg, eg -afile */ @@ -108,7 +109,9 @@ int parse_one(int *argc, char *argv[], unsigned *offset, if (!optarg) return parse_err(errlog, argv[0], o, len, "requires an argument"); - problem = opt_table[i].cb_arg(optarg, opt_table[i].u.arg); + if ((opt_table[i].type & OPT_EARLY) == is_early) + problem = opt_table[i].cb_arg(optarg, + opt_table[i].u.arg); } if (problem) {