Lines Matching defs:gof

133 static int gotflag(struct getoptflagstate *gof, struct opts *opt)
139 if (gof->noerror) return 1;
140 help_exit("Unknown option '%s'", gof->arg);
149 for (clr=gof->opts, i=1; clr; clr = clr->next, i<<=1)
156 gof->excludes |= opt->dex[2];
157 if (opt->flags&2) gof->stopearly=2;
159 if (toys.optflags & gof->excludes) {
163 for (bad=gof->opts, i=1; bad ;bad = bad->next, i<<=1) {
171 if (!gof->arg) {
173 gof->arg = "";
174 } else gof->arg++;
179 char *arg = gof->arg;
185 if (gof->nodash_now || (!arg[0] && !(opt->flags & 8)))
186 arg = toys.argv[++gof->argc];
193 for (lo = gof->longopts; lo->opt != opt; lo = lo->next);
222 if (!gof->nodash_now) gof->arg = "";
230 void parse_optflaglist(struct getoptflagstate *gof)
238 memset(gof, 0, sizeof(struct getoptflagstate));
239 gof->maxargs = INT_MAX;
244 if (*options == '^') gof->stopearly++;
245 else if (*options == '<') gof->minargs=*(++options)-'0';
246 else if (*options == '>') gof->maxargs=*(++options)-'0';
247 else if (*options == '?') gof->noerror++;
248 else if (*options == '&') gof->nodash_now = 1;
255 if (!*options) gof->stopearly++;
265 new->next = gof->opts;
266 gof->opts = new;
282 lo->next = gof->longopts;
286 gof->longopts = lo;
329 for (new = gof->opts; new; new = new->next) {
334 if (new->flags & 1) gof->requires |= u;
359 for (i=0, opt = gof->opts; ; i++, opt = opt->next) {
381 struct getoptflagstate gof;
396 parse_optflaglist(&gof);
398 if (toys.argv[1] && toys.argv[1][0] == '-') gof.nodash_now = 0;
401 for (gof.argc=1; toys.argv[gof.argc]; gof.argc++) {
402 gof.arg = toys.argv[gof.argc];
406 if (gof.stopearly>1) goto notflag;
408 if (gof.argc>1 || *gof.arg=='-') gof.nodash_now = 0;
411 if (*gof.arg == '-') {
414 if (!gof.arg[1]) goto notflag;
415 gof.arg++;
416 if (*gof.arg=='-') {
419 gof.arg++;
421 if (!*gof.arg) {
422 gof.stopearly += 2;
427 for (lo = gof.longopts; lo; lo = lo->next) {
428 if (!strncmp(gof.arg, lo->str, lo->len)) {
429 if (!gof.arg[lo->len]) gof.arg = 0;
430 else if (gof.arg[lo->len] == '=' && lo->opt->type)
431 gof.arg += lo->len;
440 if (!lo && gof.noerror) {
441 gof.arg -= 2;
446 gotflag(&gof, catch);
452 if (gof.nodash_now) toys.optflags |= FLAGS_NODASH;
459 while (*gof.arg) {
462 for (catch = gof.opts; catch; catch = catch->next)
463 if (*gof.arg == catch->c)
464 if (!((catch->flags&4) && gof.arg[1])) break;
467 if (gotflag(&gof, catch) ) {
469 gof.arg = toys.argv[gof.argc];
477 if (gof.stopearly) gof.stopearly++;
478 toys.optargs[toys.optc++] = toys.argv[gof.argc];
482 if (toys.optc<gof.minargs)
483 help_exit("Need%s %d argument%s", letters[!!(gof.minargs-1)],
484 gof.minargs, letters[!(gof.minargs-1)]);
485 if (toys.optc>gof.maxargs)
486 help_exit("Max %d argument%s", gof.maxargs, letters[!(gof.maxargs-1)]);
487 if (gof.requires && !(gof.requires & toys.optflags)) {
491 for (req = gof.opts; req; req = req->next)
501 llist_traverse(gof.opts, free);
502 llist_traverse(gof.longopts, free);