Lines Matching refs:gof
132 static int gotflag(struct getoptflagstate *gof, struct opts *opt) in gotflag() argument
138 if (gof->noerror) return 1; in gotflag()
139 help_exit("Unknown option %s", gof->arg); in gotflag()
148 for (clr=gof->opts, i=1; clr; clr = clr->next, i<<=1) in gotflag()
155 gof->excludes |= opt->dex[2]; in gotflag()
156 if (opt->flags&2) gof->stopearly=2; in gotflag()
158 if (toys.optflags & gof->excludes) { in gotflag()
162 for (bad=gof->opts, i=1; ;bad = bad->next, i<<=1) { in gotflag()
170 if (!gof->arg) { in gotflag()
172 gof->arg = ""; in gotflag()
173 } else gof->arg++; in gotflag()
178 char *arg = gof->arg; in gotflag()
184 if (gof->nodash_now || (!arg[0] && !(opt->flags & 8))) in gotflag()
185 arg = toys.argv[++gof->argc]; in gotflag()
192 for (lo = gof->longopts; lo->opt != opt; lo = lo->next); in gotflag()
221 if (!gof->nodash_now) gof->arg = ""; in gotflag()
229 void parse_optflaglist(struct getoptflagstate *gof) in parse_optflaglist() argument
237 memset(gof, 0, sizeof(struct getoptflagstate)); in parse_optflaglist()
238 gof->maxargs = INT_MAX; in parse_optflaglist()
243 if (*options == '^') gof->stopearly++; in parse_optflaglist()
244 else if (*options == '<') gof->minargs=*(++options)-'0'; in parse_optflaglist()
245 else if (*options == '>') gof->maxargs=*(++options)-'0'; in parse_optflaglist()
246 else if (*options == '?') gof->noerror++; in parse_optflaglist()
247 else if (*options == '&') gof->nodash++; in parse_optflaglist()
254 if (!*options) gof->stopearly++; in parse_optflaglist()
264 new->next = gof->opts; in parse_optflaglist()
265 gof->opts = new; in parse_optflaglist()
281 lo->next = gof->longopts; in parse_optflaglist()
285 gof->longopts = lo; in parse_optflaglist()
328 for (new = gof->opts; new; new = new->next) { in parse_optflaglist()
333 if (new->flags & 1) gof->requires |= u; in parse_optflaglist()
358 for (i=0, opt = gof->opts; ; i++, opt = opt->next) { in parse_optflaglist()
379 struct getoptflagstate gof; in get_optflags() local
392 parse_optflaglist(&gof); in get_optflags()
395 for (gof.argc=1; toys.argv[gof.argc]; gof.argc++) { in get_optflags()
396 gof.arg = toys.argv[gof.argc]; in get_optflags()
400 if (gof.stopearly>1) goto notflag; in get_optflags()
402 gof.nodash_now = 0; in get_optflags()
405 if (*gof.arg == '-') { in get_optflags()
408 if (!gof.arg[1]) goto notflag; in get_optflags()
409 gof.arg++; in get_optflags()
410 if (*gof.arg=='-') { in get_optflags()
413 gof.arg++; in get_optflags()
415 if (!*gof.arg) { in get_optflags()
416 gof.stopearly += 2; in get_optflags()
421 for (lo = gof.longopts; lo; lo = lo->next) { in get_optflags()
422 if (!strncmp(gof.arg, lo->str, lo->len)) { in get_optflags()
423 if (!gof.arg[lo->len]) gof.arg = 0; in get_optflags()
424 else if (gof.arg[lo->len] == '=' && lo->opt->type) in get_optflags()
425 gof.arg += lo->len; in get_optflags()
434 if (!lo && gof.noerror) { in get_optflags()
435 gof.arg -= 2; in get_optflags()
440 gotflag(&gof, catch); in get_optflags()
446 if (gof.nodash && (gof.nodash>1 || gof.argc == 1)) gof.nodash_now = 1; in get_optflags()
453 while (*gof.arg) { in get_optflags()
456 for (catch = gof.opts; catch; catch = catch->next) in get_optflags()
457 if (*gof.arg == catch->c) in get_optflags()
458 if (!((catch->flags&4) && gof.arg[1])) break; in get_optflags()
461 if (gotflag(&gof, catch) ) { in get_optflags()
463 gof.arg = toys.argv[gof.argc]; in get_optflags()
471 if (gof.stopearly) gof.stopearly++; in get_optflags()
472 toys.optargs[toys.optc++] = toys.argv[gof.argc]; in get_optflags()
476 if (toys.optc<gof.minargs) in get_optflags()
477 help_exit("Need%s %d argument%s", letters[!!(gof.minargs-1)], in get_optflags()
478 gof.minargs, letters[!(gof.minargs-1)]); in get_optflags()
479 if (toys.optc>gof.maxargs) in get_optflags()
480 help_exit("Max %d argument%s", gof.maxargs, letters[!(gof.maxargs-1)]); in get_optflags()
481 if (gof.requires && !(gof.requires & toys.optflags)) { in get_optflags()
485 for (req = gof.opts; req; req = req->next) in get_optflags()
493 llist_traverse(gof.opts, free); in get_optflags()
494 llist_traverse(gof.longopts, free); in get_optflags()