Lines Matching refs:opt
20 static int opterror(const struct option *opt, const char *reason, int flags) in opterror() argument
23 fprintf(stderr, " Error: switch `%c' %s", opt->short_name, reason); in opterror()
25 fprintf(stderr, " Error: option `no-%s' %s", opt->long_name, reason); in opterror()
27 fprintf(stderr, " Error: option `%s' %s", opt->long_name, reason); in opterror()
38 static void optwarning(const struct option *opt, const char *reason, int flags) in optwarning() argument
41 fprintf(stderr, " Warning: switch `%c' %s", opt->short_name, reason); in optwarning()
43 fprintf(stderr, " Warning: option `no-%s' %s", opt->long_name, reason); in optwarning()
45 fprintf(stderr, " Warning: option `%s' %s", opt->long_name, reason); in optwarning()
48 static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt, in get_arg() argument
53 if (p->opt) { in get_arg()
54 res = p->opt; in get_arg()
55 p->opt = NULL; in get_arg()
56 } else if ((opt->flags & PARSE_OPT_LASTARG_DEFAULT) && (p->argc == 1 || in get_arg()
58 res = (const char *)opt->defval; in get_arg()
63 return opterror(opt, "requires a value", flags); in get_arg()
70 const struct option *opt, int flags) in get_value() argument
76 if (unset && p->opt) in get_value()
77 return opterror(opt, "takes no value", flags); in get_value()
78 if (unset && (opt->flags & PARSE_OPT_NONEG)) in get_value()
79 return opterror(opt, "isn't available", flags); in get_value()
80 if (opt->flags & PARSE_OPT_DISABLED) in get_value()
81 return opterror(opt, "is not usable", flags); in get_value()
83 if (opt->flags & PARSE_OPT_EXCLUSIVE) { in get_value()
84 if (p->excl_opt && p->excl_opt != opt) { in get_value()
95 opterror(opt, msg, flags); in get_value()
98 p->excl_opt = opt; in get_value()
100 if (!(flags & OPT_SHORT) && p->opt) { in get_value()
101 switch (opt->type) { in get_value()
103 if (!(opt->flags & PARSE_OPT_NOARG)) in get_value()
111 return opterror(opt, "takes no value", flags); in get_value()
126 if (opt->flags & PARSE_OPT_NOBUILD) { in get_value()
131 opt->flags & PARSE_OPT_CANSKIP ? in get_value()
134 opt->build_opt); in get_value()
138 strncpy(reason, opt->flags & PARSE_OPT_CANSKIP ? in get_value()
143 if (!(opt->flags & PARSE_OPT_CANSKIP)) in get_value()
144 return opterror(opt, reason, flags); in get_value()
149 if (opt->flags & PARSE_OPT_NOARG) in get_value()
151 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) in get_value()
154 switch (opt->type) { in get_value()
177 err = get_arg(p, opt, flags, NULL); in get_value()
181 optwarning(opt, reason, flags); in get_value()
185 switch (opt->type) { in get_value()
188 *(int *)opt->value &= ~opt->defval; in get_value()
190 *(int *)opt->value |= opt->defval; in get_value()
194 *(bool *)opt->value = unset ? false : true; in get_value()
195 if (opt->set) in get_value()
196 *(bool *)opt->set = true; in get_value()
200 *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1; in get_value()
204 *(unsigned int *)opt->value = unset ? 0 : opt->defval; in get_value()
208 *(void **)opt->value = unset ? NULL : (void *)opt->defval; in get_value()
214 *(const char **)opt->value = NULL; in get_value()
215 else if (opt->flags & PARSE_OPT_OPTARG && !p->opt) in get_value()
216 *(const char **)opt->value = (const char *)opt->defval; in get_value()
218 err = get_arg(p, opt, flags, (const char **)opt->value); in get_value()
220 if (opt->set) in get_value()
221 *(bool *)opt->set = true; in get_value()
224 if (opt->flags & PARSE_OPT_NOEMPTY) { in get_value()
225 const char *val = *(const char **)opt->value; in get_value()
232 *(const char **)opt->value = NULL; in get_value()
240 if (opt->set) in get_value()
241 *(bool *)opt->set = true; in get_value()
244 return (*opt->callback)(opt, NULL, 1) ? (-1) : 0; in get_value()
245 if (opt->flags & PARSE_OPT_NOARG) in get_value()
246 return (*opt->callback)(opt, NULL, 0) ? (-1) : 0; in get_value()
247 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) in get_value()
248 return (*opt->callback)(opt, NULL, 0) ? (-1) : 0; in get_value()
249 if (get_arg(p, opt, flags, &arg)) in get_value()
251 return (*opt->callback)(opt, arg, 0) ? (-1) : 0; in get_value()
255 *(int *)opt->value = 0; in get_value()
258 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { in get_value()
259 *(int *)opt->value = opt->defval; in get_value()
262 if (get_arg(p, opt, flags, &arg)) in get_value()
264 *(int *)opt->value = strtol(arg, (char **)&s, 10); in get_value()
266 return opterror(opt, "expects a numerical value", flags); in get_value()
271 *(unsigned int *)opt->value = 0; in get_value()
274 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { in get_value()
275 *(unsigned int *)opt->value = opt->defval; in get_value()
278 if (get_arg(p, opt, flags, &arg)) in get_value()
281 return opterror(opt, "expects an unsigned numerical value", flags); in get_value()
282 *(unsigned int *)opt->value = strtol(arg, (char **)&s, 10); in get_value()
284 return opterror(opt, "expects a numerical value", flags); in get_value()
289 *(long *)opt->value = 0; in get_value()
292 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { in get_value()
293 *(long *)opt->value = opt->defval; in get_value()
296 if (get_arg(p, opt, flags, &arg)) in get_value()
298 *(long *)opt->value = strtol(arg, (char **)&s, 10); in get_value()
300 return opterror(opt, "expects a numerical value", flags); in get_value()
305 *(unsigned long *)opt->value = 0; in get_value()
308 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { in get_value()
309 *(unsigned long *)opt->value = opt->defval; in get_value()
312 if (get_arg(p, opt, flags, &arg)) in get_value()
314 *(unsigned long *)opt->value = strtoul(arg, (char **)&s, 10); in get_value()
316 return opterror(opt, "expects a numerical value", flags); in get_value()
321 *(u64 *)opt->value = 0; in get_value()
324 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { in get_value()
325 *(u64 *)opt->value = opt->defval; in get_value()
328 if (get_arg(p, opt, flags, &arg)) in get_value()
331 return opterror(opt, "expects an unsigned numerical value", flags); in get_value()
332 *(u64 *)opt->value = strtoull(arg, (char **)&s, 10); in get_value()
334 return opterror(opt, "expects a numerical value", flags); in get_value()
349 if (options->short_name == *p->opt) { in parse_short_opt()
350 p->opt = p->opt[1] ? p->opt + 1 : NULL; in parse_short_opt()
425 p->opt = arg_end + 1; in parse_long_opt()
450 p->opt = rest + 1; in parse_long_opt()
523 ctx->opt = NULL; in parse_options_step()
535 ctx->opt = ++arg; in parse_options_step()
536 if (internal_help && *ctx->opt == 'h') { in parse_options_step()
549 if (ctx->opt) in parse_options_step()
551 while (ctx->opt) { in parse_options_step()
552 if (internal_help && *ctx->opt == 'h') in parse_options_step()
554 arg = ctx->opt; in parse_options_step()
564 ctx->argv[0] = strdup(ctx->opt - 1); in parse_options_step()
609 ctx->opt = NULL; in parse_options_step()
617 char opt = ctx->excl_opt->short_name; in parse_options_step() local
618 parse_options_usage(NULL, options, &opt, 1); in parse_options_step()
679 astrcatf(&error_buf, "unknown switch `%c'", *ctx.opt); in parse_options_subcommand()
811 struct option *opt, *ordered, *group; in options__order() local
823 for (opt = group = ordered; opt->type != OPTION_END; opt++) { in options__order()
824 if (opt->type == OPTION_GROUP) { in options__order()
825 qsort(group, nr_group, sizeof(*opt), option__cmp); in options__order()
826 group = opt + 1; in options__order()
832 qsort(group, nr_group, sizeof(*opt), option__cmp); in options__order()
838 static bool option__in_argv(const struct option *opt, const struct parse_opt_ctx_t *ctx) in option__in_argv() argument
847 if (arg[0] == opt->short_name) in option__in_argv()
852 if (opt->long_name && strcmp(opt->long_name, arg) == 0) in option__in_argv()
855 if (opt->help && strcasestr(opt->help, arg) != NULL) in option__in_argv()
861 if (arg[1] == opt->short_name || in option__in_argv()
862 (arg[1] == '-' && opt->long_name && strcmp(opt->long_name, arg + 2) == 0)) in option__in_argv()
944 goto opt; in parse_options_usage()
957 opt: in parse_options_usage()
981 int parse_opt_verbosity_cb(const struct option *opt, in parse_opt_verbosity_cb() argument
985 int *target = opt->value; in parse_opt_verbosity_cb()
990 else if (opt->short_name == 'v') { in parse_opt_verbosity_cb()
1019 struct option *opt = find_option(opts, shortopt, longopt); in set_option_flag() local
1021 if (opt) in set_option_flag()
1022 opt->flags |= flag; in set_option_flag()
1031 struct option *opt = find_option(opts, shortopt, longopt); in set_option_nobuild() local
1033 if (!opt) in set_option_nobuild()
1036 opt->flags |= PARSE_OPT_NOBUILD; in set_option_nobuild()
1037 opt->flags |= can_skip ? PARSE_OPT_CANSKIP : 0; in set_option_nobuild()
1038 opt->build_opt = build_opt; in set_option_nobuild()