@ -245,6 +245,25 @@ is_abbreviated:
return -2;
return -2;
}
}
static int parse_nodash_opt(struct parse_opt_ctx_t *p, const char *arg,
const struct option *options)
{
for (; options->type != OPTION_END; options++) {
if (!(options->flags & PARSE_OPT_NODASH))
continue;
if ((options->flags & PARSE_OPT_OPTARG) ||
!(options->flags & PARSE_OPT_NOARG))
die("BUG: dashless options don't support arguments");
if (!(options->flags & PARSE_OPT_NONEG))
die("BUG: dashless options don't support negation");
if (options->long_name)
die("BUG: dashless options can't be long");
if (options->short_name == arg[0] && arg[1] == '\0')
return get_value(p, options, OPT_SHORT);
}
return -2;
}
static void check_typos(const char *arg, const struct option *options)
static void check_typos(const char *arg, const struct option *options)
{
{
if (strlen(arg) < 3)
if (strlen(arg) < 3)
@ -295,6 +314,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
const char *arg = ctx->argv[0];
const char *arg = ctx->argv[0];
if (*arg != '-' || !arg[1]) {
if (*arg != '-' || !arg[1]) {
if (parse_nodash_opt(ctx, arg, options) == 0)
continue;
if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION)
if (ctx->flags & PARSE_OPT_STOP_AT_NON_OPTION)
break;
break;
ctx->out[ctx->cpidx++] = ctx->argv[0];
ctx->out[ctx->cpidx++] = ctx->argv[0];
@ -427,8 +448,12 @@ int usage_with_options_internal(const char * const *usagestr,
continue;
continue;
pos = fprintf(stderr, " ");
pos = fprintf(stderr, " ");
if (opts->short_name)
if (opts->short_name) {
pos += fprintf(stderr, "-%c", opts->short_name);
if (opts->flags & PARSE_OPT_NODASH)
pos += fprintf(stderr, "%c", opts->short_name);
else
pos += fprintf(stderr, "-%c", opts->short_name);
}
if (opts->long_name && opts->short_name)
if (opts->long_name && opts->short_name)
pos += fprintf(stderr, ", ");
pos += fprintf(stderr, ", ");
if (opts->long_name)
if (opts->long_name)