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