Lines Matching refs:opt

12 static int opterror(const struct option *opt, const char *reason, int flags)  in opterror()  argument
15 return error("switch `%c' %s", opt->short_name, reason); in opterror()
17 return error("option `no-%s' %s", opt->long_name, reason); in opterror()
18 return error("option `%s' %s", opt->long_name, reason); in opterror()
21 static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt, in get_arg() argument
24 if (p->opt) { in get_arg()
25 *arg = p->opt; in get_arg()
26 p->opt = NULL; in get_arg()
27 } else if ((opt->flags & PARSE_OPT_LASTARG_DEFAULT) && (p->argc == 1 || in get_arg()
29 *arg = (const char *)opt->defval; in get_arg()
34 return opterror(opt, "requires a value", flags); in get_arg()
39 const struct option *opt, int flags) in get_value() argument
45 if (unset && p->opt) in get_value()
46 return opterror(opt, "takes no value", flags); in get_value()
47 if (unset && (opt->flags & PARSE_OPT_NONEG)) in get_value()
48 return opterror(opt, "isn't available", flags); in get_value()
49 if (opt->flags & PARSE_OPT_DISABLED) in get_value()
50 return opterror(opt, "is not usable", flags); in get_value()
52 if (opt->flags & PARSE_OPT_EXCLUSIVE) { in get_value()
53 if (p->excl_opt && p->excl_opt != opt) { in get_value()
64 opterror(opt, msg, flags); in get_value()
67 p->excl_opt = opt; in get_value()
69 if (!(flags & OPT_SHORT) && p->opt) { in get_value()
70 switch (opt->type) { in get_value()
72 if (!(opt->flags & PARSE_OPT_NOARG)) in get_value()
80 return opterror(opt, "takes no value", flags); in get_value()
94 switch (opt->type) { in get_value()
97 *(int *)opt->value &= ~opt->defval; in get_value()
99 *(int *)opt->value |= opt->defval; in get_value()
103 *(bool *)opt->value = unset ? false : true; in get_value()
104 if (opt->set) in get_value()
105 *(bool *)opt->set = true; in get_value()
109 *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1; in get_value()
113 *(unsigned int *)opt->value = unset ? 0 : opt->defval; in get_value()
117 *(void **)opt->value = unset ? NULL : (void *)opt->defval; in get_value()
123 *(const char **)opt->value = NULL; in get_value()
124 else if (opt->flags & PARSE_OPT_OPTARG && !p->opt) in get_value()
125 *(const char **)opt->value = (const char *)opt->defval; in get_value()
127 err = get_arg(p, opt, flags, (const char **)opt->value); in get_value()
130 if (opt->flags & PARSE_OPT_NOEMPTY) { in get_value()
131 const char *val = *(const char **)opt->value; in get_value()
138 *(const char **)opt->value = NULL; in get_value()
147 return (*opt->callback)(opt, NULL, 1) ? (-1) : 0; in get_value()
148 if (opt->flags & PARSE_OPT_NOARG) in get_value()
149 return (*opt->callback)(opt, NULL, 0) ? (-1) : 0; in get_value()
150 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) in get_value()
151 return (*opt->callback)(opt, NULL, 0) ? (-1) : 0; in get_value()
152 if (get_arg(p, opt, flags, &arg)) in get_value()
154 return (*opt->callback)(opt, arg, 0) ? (-1) : 0; in get_value()
158 *(int *)opt->value = 0; in get_value()
161 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { in get_value()
162 *(int *)opt->value = opt->defval; in get_value()
165 if (get_arg(p, opt, flags, &arg)) in get_value()
167 *(int *)opt->value = strtol(arg, (char **)&s, 10); in get_value()
169 return opterror(opt, "expects a numerical value", flags); in get_value()
174 *(unsigned int *)opt->value = 0; in get_value()
177 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { in get_value()
178 *(unsigned int *)opt->value = opt->defval; in get_value()
181 if (get_arg(p, opt, flags, &arg)) in get_value()
183 *(unsigned int *)opt->value = strtol(arg, (char **)&s, 10); in get_value()
185 return opterror(opt, "expects a numerical value", flags); in get_value()
190 *(long *)opt->value = 0; in get_value()
193 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { in get_value()
194 *(long *)opt->value = opt->defval; in get_value()
197 if (get_arg(p, opt, flags, &arg)) in get_value()
199 *(long *)opt->value = strtol(arg, (char **)&s, 10); in get_value()
201 return opterror(opt, "expects a numerical value", flags); in get_value()
206 *(u64 *)opt->value = 0; in get_value()
209 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) { in get_value()
210 *(u64 *)opt->value = opt->defval; in get_value()
213 if (get_arg(p, opt, flags, &arg)) in get_value()
215 *(u64 *)opt->value = strtoull(arg, (char **)&s, 10); in get_value()
217 return opterror(opt, "expects a numerical value", flags); in get_value()
231 if (options->short_name == *p->opt) { in parse_short_opt()
232 p->opt = p->opt[1] ? p->opt + 1 : NULL; in parse_short_opt()
300 p->opt = arg_end + 1; in parse_long_opt()
325 p->opt = rest + 1; in parse_long_opt()
390 ctx->opt = NULL; in parse_options_step()
402 ctx->opt = ++arg; in parse_options_step()
403 if (internal_help && *ctx->opt == 'h') { in parse_options_step()
416 if (ctx->opt) in parse_options_step()
418 while (ctx->opt) { in parse_options_step()
419 if (internal_help && *ctx->opt == 'h') in parse_options_step()
421 arg = ctx->opt; in parse_options_step()
431 ctx->argv[0] = strdup(ctx->opt - 1); in parse_options_step()
476 ctx->opt = NULL; in parse_options_step()
484 char opt = ctx->excl_opt->short_name; in parse_options_step() local
485 parse_options_usage(NULL, options, &opt, 1); in parse_options_step()
549 *ctx.opt); in parse_options_subcommand()
691 static bool option__in_argv(const struct option *opt, const struct parse_opt_ctx_t *ctx) in option__in_argv() argument
700 if (arg[0] == opt->short_name) in option__in_argv()
705 if (opt->long_name && strcmp(opt->long_name, arg) == 0) in option__in_argv()
708 if (opt->help && strcasestr(opt->help, arg) != NULL) in option__in_argv()
714 if (arg[1] == opt->short_name || in option__in_argv()
715 (arg[1] == '-' && opt->long_name && strcmp(opt->long_name, arg + 2) == 0)) in option__in_argv()
796 goto opt; in parse_options_usage()
809 opt: in parse_options_usage()
833 int parse_opt_verbosity_cb(const struct option *opt, in parse_opt_verbosity_cb() argument
837 int *target = opt->value; in parse_opt_verbosity_cb()
842 else if (opt->short_name == 'v') { in parse_opt_verbosity_cb()