Lines Matching refs:gof
135 static int gotflag(struct getoptflagstate *gof, struct opts *opt) in gotflag() argument
141 if (gof->noerror) return 1; in gotflag()
142 help_exit("Unknown option %s", gof->arg); in gotflag()
151 for (clr=gof->opts, i=1; clr; clr = clr->next, i<<=1) in gotflag()
158 gof->excludes |= opt->dex[2]; in gotflag()
159 if (opt->flags&2) gof->stopearly=2; in gotflag()
161 if (toys.optflags & gof->excludes) { in gotflag()
165 for (bad=gof->opts, i=1; bad ;bad = bad->next, i<<=1) { in gotflag()
173 if (!gof->arg) { in gotflag()
175 gof->arg = ""; in gotflag()
176 } else gof->arg++; in gotflag()
181 char *arg = gof->arg; in gotflag()
187 if (gof->nodash_now || (!arg[0] && !(opt->flags & 8))) in gotflag()
188 arg = toys.argv[++gof->argc]; in gotflag()
195 for (lo = gof->longopts; lo->opt != opt; lo = lo->next); in gotflag()
224 if (!gof->nodash_now) gof->arg = ""; in gotflag()
232 void parse_optflaglist(struct getoptflagstate *gof) in parse_optflaglist() argument
240 memset(gof, 0, sizeof(struct getoptflagstate)); in parse_optflaglist()
241 gof->maxargs = INT_MAX; in parse_optflaglist()
246 if (*options == '^') gof->stopearly++; in parse_optflaglist()
247 else if (*options == '<') gof->minargs=*(++options)-'0'; in parse_optflaglist()
248 else if (*options == '>') gof->maxargs=*(++options)-'0'; in parse_optflaglist()
249 else if (*options == '?') gof->noerror++; in parse_optflaglist()
250 else if (*options == '&') gof->nodash_now = 1; in parse_optflaglist()
257 if (!*options) gof->stopearly++; in parse_optflaglist()
267 new->next = gof->opts; in parse_optflaglist()
268 gof->opts = new; in parse_optflaglist()
284 lo->next = gof->longopts; in parse_optflaglist()
288 gof->longopts = lo; in parse_optflaglist()
331 for (new = gof->opts; new; new = new->next) { in parse_optflaglist()
336 if (new->flags & 1) gof->requires |= u; in parse_optflaglist()
361 for (i=0, opt = gof->opts; ; i++, opt = opt->next) { in parse_optflaglist()
383 struct getoptflagstate gof; in get_optflags() local
398 parse_optflaglist(&gof); in get_optflags()
400 if (toys.argv[1] && toys.argv[1][0] == '-') gof.nodash_now = 0; in get_optflags()
403 for (gof.argc=1; toys.argv[gof.argc]; gof.argc++) { in get_optflags()
404 gof.arg = toys.argv[gof.argc]; in get_optflags()
408 if (gof.stopearly>1) goto notflag; in get_optflags()
410 if (gof.argc>1 || *gof.arg=='-') gof.nodash_now = 0; in get_optflags()
413 if (*gof.arg == '-') { in get_optflags()
416 if (!gof.arg[1]) goto notflag; in get_optflags()
417 gof.arg++; in get_optflags()
418 if (*gof.arg=='-') { in get_optflags()
421 gof.arg++; in get_optflags()
423 if (!*gof.arg) { in get_optflags()
424 gof.stopearly += 2; in get_optflags()
429 for (lo = gof.longopts; lo; lo = lo->next) { in get_optflags()
430 if (!strncmp(gof.arg, lo->str, lo->len)) { in get_optflags()
431 if (!gof.arg[lo->len]) gof.arg = 0; in get_optflags()
432 else if (gof.arg[lo->len] == '=' && lo->opt->type) in get_optflags()
433 gof.arg += lo->len; in get_optflags()
442 if (!lo && gof.noerror) { in get_optflags()
443 gof.arg -= 2; in get_optflags()
448 gotflag(&gof, catch); in get_optflags()
454 if (gof.nodash_now) toys.optflags |= FLAGS_NODASH; in get_optflags()
461 while (*gof.arg) { in get_optflags()
464 for (catch = gof.opts; catch; catch = catch->next) in get_optflags()
465 if (*gof.arg == catch->c) in get_optflags()
466 if (!((catch->flags&4) && gof.arg[1])) break; in get_optflags()
469 if (gotflag(&gof, catch) ) { in get_optflags()
471 gof.arg = toys.argv[gof.argc]; in get_optflags()
479 if (gof.stopearly) gof.stopearly++; in get_optflags()
480 toys.optargs[toys.optc++] = toys.argv[gof.argc]; in get_optflags()
484 if (toys.optc<gof.minargs) in get_optflags()
485 help_exit("Need%s %d argument%s", letters[!!(gof.minargs-1)], in get_optflags()
486 gof.minargs, letters[!(gof.minargs-1)]); in get_optflags()
487 if (toys.optc>gof.maxargs) in get_optflags()
488 help_exit("Max %d argument%s", gof.maxargs, letters[!(gof.maxargs-1)]); in get_optflags()
489 if (gof.requires && !(gof.requires & toys.optflags)) { in get_optflags()
493 for (req = gof.opts; req; req = req->next) in get_optflags()
503 llist_traverse(gof.opts, free); in get_optflags()
504 llist_traverse(gof.longopts, free); in get_optflags()