Lines Matching refs:options

8 opterror(struct optparse *options, const char *message, const char *data)  in opterror()  argument
12 options->errmsg[p++] = *message++; in opterror()
15 options->errmsg[p++] = *sep++; in opterror()
16 while (p < sizeof(options->errmsg) - 2 && *data) in opterror()
17 options->errmsg[p++] = *data++; in opterror()
18 options->errmsg[p++] = '\''; in opterror()
19 options->errmsg[p++] = '\0'; in opterror()
23 void optparse_init(struct optparse *options, char **argv) in optparse_init() argument
25 options->argv = argv; in optparse_init()
26 options->permute = 1; in optparse_init()
27 options->optind = 1; in optparse_init()
28 options->subopt = 0; in optparse_init()
29 options->optarg = 0; in optparse_init()
30 options->errmsg[0] = '\0'; in optparse_init()
52 permute(struct optparse *options, int index) in permute() argument
54 char *nonoption = options->argv[index]; in permute()
55 for (int i = index; i < options->optind - 1; i++) in permute()
56 options->argv[i] = options->argv[i + 1]; in permute()
57 options->argv[options->optind - 1] = nonoption; in permute()
74 int optparse(struct optparse *options, const char *optstring) in optparse() argument
76 options->errmsg[0] = '\0'; in optparse()
77 options->optopt = 0; in optparse()
78 options->optarg = 0; in optparse()
79 char *option = options->argv[options->optind]; in optparse()
83 options->optind++; /* consume "--" */ in optparse()
86 if (options->permute) { in optparse()
87 int index = options->optind; in optparse()
88 options->optind++; in optparse()
89 int r = optparse(options, optstring); in optparse()
90 permute(options, index); in optparse()
91 options->optind--; in optparse()
97 option += options->subopt + 1; in optparse()
98 options->optopt = option[0]; in optparse()
100 char *next = options->argv[options->optind + 1]; in optparse()
103 options->optind++; in optparse()
105 return opterror(options, MSG_INVALID, str); in optparse()
109 options->subopt++; in optparse()
111 options->subopt = 0; in optparse()
112 options->optind++; in optparse()
116 options->subopt = 0; in optparse()
117 options->optind++; in optparse()
119 options->optarg = option + 1; in optparse()
121 options->optarg = next; in optparse()
122 options->optind++; in optparse()
124 options->optarg = 0; in optparse()
126 return opterror(options, MSG_MISSING, str); in optparse()
130 options->subopt = 0; in optparse()
131 options->optind++; in optparse()
133 options->optarg = option + 1; in optparse()
135 options->optarg = 0; in optparse()
141 char *optparse_arg(struct optparse *options) in optparse_arg() argument
143 options->subopt = 0; in optparse_arg()
144 char *option = options->argv[options->optind]; in optparse_arg()
146 options->optind++; in optparse_arg()
195 long_fallback(struct optparse *options, in long_fallback() argument
201 int result = optparse(options, optstring); in long_fallback()
206 if (longopts[i].shortname == options->optopt) in long_fallback()
213 optparse_long(struct optparse *options, in optparse_long() argument
217 char *option = options->argv[options->optind]; in optparse_long()
221 options->optind++; /* consume "--" */ in optparse_long()
224 return long_fallback(options, longopts, longindex); in optparse_long()
226 if (options->permute) { in optparse_long()
227 int index = options->optind; in optparse_long()
228 options->optind++; in optparse_long()
229 int r = optparse_long(options, longopts, longindex); in optparse_long()
230 permute(options, index); in optparse_long()
231 options->optind--; in optparse_long()
239 options->errmsg[0] = '\0'; in optparse_long()
240 options->optopt = 0; in optparse_long()
241 options->optarg = 0; in optparse_long()
243 options->optind++; in optparse_long()
249 options->optopt = longopts[i].shortname; in optparse_long()
252 return opterror(options, MSG_TOOMANY, name); in optparse_long()
254 options->optarg = arg; in optparse_long()
256 options->optarg = options->argv[options->optind++]; in optparse_long()
257 if (options->optarg == 0) in optparse_long()
258 return opterror(options, MSG_MISSING, name); in optparse_long()
260 return options->optopt; in optparse_long()
263 return opterror(options, MSG_INVALID, option); in optparse_long()