14
OPT_UNSET = 1<<1,
15
};
16
17
-static int optbug(const struct option *opt, const char *reason)
17
+static void optbug(const struct option *opt, const char *reason)
18
{
19
- if (opt->long_name) {
20
- if (opt->short_name)
21
- return error("BUG: switch '%c' (--%s) %s",
22
- opt->short_name, opt->long_name, reason);
23
- return error("BUG: option '%s' %s", opt->long_name, reason);
24
- }
25
- return error("BUG: switch '%c' %s", opt->short_name, reason);
19
+ if (opt->long_name && opt->short_name)
20
+ bug("switch '%c' (--%s) %s", opt->short_name,
21
+ opt->long_name, reason);
22
+ else if (opt->long_name)
23
+ bug("option '%s' %s", opt->long_name, reason);
24
+ else
25
+ bug("switch '%c' %s", opt->short_name, reason);
26
}
27
28
static const char *optname(const struct option *opt, enum opt_parsed flags)
441
442
static void parse_options_check(const struct option *opts)
443
{
444
- int err = 0;
444
char short_opts[128];
445
446
memset(short_opts, '\0', sizeof(short_opts));
447
for (; opts->type != OPTION_END; opts++) {
448
if ((opts->flags & PARSE_OPT_LASTARG_DEFAULT) &&
449
(opts->flags & PARSE_OPT_OPTARG))
451
- err |= optbug(opts, "uses incompatible flags "
452
- "LASTARG_DEFAULT and OPTARG");
450
+ optbug(opts, "uses incompatible flags "
451
+ "LASTARG_DEFAULT and OPTARG");
452
if (opts->short_name) {
453
if (0x7F <= opts->short_name)
455
- err |= optbug(opts, "invalid short name");
454
+ optbug(opts, "invalid short name");
455
else if (short_opts[opts->short_name]++)
457
- err |= optbug(opts, "short name already used");
456
+ optbug(opts, "short name already used");
457
}
458
if (opts->flags & PARSE_OPT_NODASH &&
459
((opts->flags & PARSE_OPT_OPTARG) ||
460
!(opts->flags & PARSE_OPT_NOARG) ||
461
!(opts->flags & PARSE_OPT_NONEG) ||
462
opts->long_name))
464
- err |= optbug(opts, "uses feature "
465
- "not supported for dashless options");
463
+ optbug(opts, "uses feature "
464
+ "not supported for dashless options");
465
switch (opts->type) {
466
case OPTION_COUNTUP:
467
case OPTION_BIT:
470
case OPTION_NUMBER:
471
if ((opts->flags & PARSE_OPT_OPTARG) ||
472
!(opts->flags & PARSE_OPT_NOARG))
474
- err |= optbug(opts, "should not accept an argument");
473
+ optbug(opts, "should not accept an argument");
474
break;
475
case OPTION_CALLBACK:
476
if (!opts->callback && !opts->ll_callback)
493
}
494
if (opts->argh &&
495
strcspn(opts->argh, " _") != strlen(opts->argh))
497
- err |= optbug(opts, "multi-word argh should use dash to separate words");
496
+ optbug(opts, "multi-word argh should use dash to separate words");
497
}
499
- if (err)
500
- exit(128);
498
+ BUG_if_bug("invalid 'struct option'");
499
}
500
501
static void parse_options_start_1(struct parse_opt_ctx_t *ctx,