Lines Matching refs:opt

9 static int opterror(const struct option *opt, const char *reason, int flags)
12 return error("switch `%c' %s", opt->short_name, reason);
14 return error("option `no-%s' %s", opt->long_name, reason);
15 return error("option `%s' %s", opt->long_name, reason);
18 static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,
21 if (p->opt) {
22 *arg = p->opt;
23 p->opt = NULL;
24 } else if ((opt->flags & PARSE_OPT_LASTARG_DEFAULT) && (p->argc == 1 ||
26 *arg = (const char *)opt->defval;
31 return opterror(opt, "requires a value", flags);
36 const struct option *opt, int flags)
41 if (unset && p->opt)
42 return opterror(opt, "takes no value", flags);
43 if (unset && (opt->flags & PARSE_OPT_NONEG))
44 return opterror(opt, "isn't available", flags);
46 if (!(flags & OPT_SHORT) && p->opt) {
47 switch (opt->type) {
49 if (!(opt->flags & PARSE_OPT_NOARG))
57 return opterror(opt, "takes no value", flags);
71 switch (opt->type) {
74 *(int *)opt->value &= ~opt->defval;
76 *(int *)opt->value |= opt->defval;
80 *(bool *)opt->value = unset ? false : true;
84 *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1;
88 *(unsigned int *)opt->value = unset ? 0 : opt->defval;
92 *(void **)opt->value = unset ? NULL : (void *)opt->defval;
97 *(const char **)opt->value = NULL;
98 else if (opt->flags & PARSE_OPT_OPTARG && !p->opt)
99 *(const char **)opt->value = (const char *)opt->defval;
101 return get_arg(p, opt, flags, (const char **)opt->value);
106 return (*opt->callback)(opt, NULL, 1) ? (-1) : 0;
107 if (opt->flags & PARSE_OPT_NOARG)
108 return (*opt->callback)(opt, NULL, 0) ? (-1) : 0;
109 if (opt->flags & PARSE_OPT_OPTARG && !p->opt)
110 return (*opt->callback)(opt, NULL, 0) ? (-1) : 0;
111 if (get_arg(p, opt, flags, &arg))
113 return (*opt->callback)(opt, arg, 0) ? (-1) : 0;
117 *(int *)opt->value = 0;
120 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
121 *(int *)opt->value = opt->defval;
124 if (get_arg(p, opt, flags, &arg))
126 *(int *)opt->value = strtol(arg, (char **)&s, 10);
128 return opterror(opt, "expects a numerical value", flags);
133 *(unsigned int *)opt->value = 0;
136 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
137 *(unsigned int *)opt->value = opt->defval;
140 if (get_arg(p, opt, flags, &arg))
142 *(unsigned int *)opt->value = strtol(arg, (char **)&s, 10);
144 return opterror(opt, "expects a numerical value", flags);
149 *(long *)opt->value = 0;
152 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
153 *(long *)opt->value = opt->defval;
156 if (get_arg(p, opt, flags, &arg))
158 *(long *)opt->value = strtol(arg, (char **)&s, 10);
160 return opterror(opt, "expects a numerical value", flags);
165 *(u64 *)opt->value = 0;
168 if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
169 *(u64 *)opt->value = opt->defval;
172 if (get_arg(p, opt, flags, &arg))
174 *(u64 *)opt->value = strtoull(arg, (char **)&s, 10);
176 return opterror(opt, "expects a numerical value", flags);
190 if (options->short_name == *p->opt) {
191 p->opt = p->opt[1] ? p->opt + 1 : NULL;
241 p->opt = arg_end + 1;
265 p->opt = rest + 1;
326 /* we must reset ->opt, unknown short option leave it dangling */
327 ctx->opt = NULL;
340 ctx->opt = arg + 1;
341 if (internal_help && *ctx->opt == 'h')
351 if (ctx->opt)
353 while (ctx->opt) {
354 if (internal_help && *ctx->opt == 'h')
365 ctx->argv[0] = strdup(ctx->opt - 1);
402 ctx->opt = NULL;
437 error("unknown switch `%c'", *ctx.opt);
568 int parse_opt_verbosity_cb(const struct option *opt,
572 int *target = opt->value;
577 else if (opt->short_name == 'v') {