Mercurial > hg > toybox
diff lib/args.c @ 255:3fe66e630944
Add toys.optc, an argv-style count for toys.optargs.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 12 Feb 2008 17:36:13 -0600 |
parents | 7cb15eae1664 |
children | ae693c7bf2f7 |
line wrap: on
line diff
--- a/lib/args.c Tue Feb 12 17:35:10 2008 -0600 +++ b/lib/args.c Tue Feb 12 17:36:13 2008 -0600 @@ -66,15 +66,13 @@ long *arg; }; -struct getoptflagstate +static struct getoptflagstate { int argc; char *arg; struct opts *opts, *this; int noerror, nodash_now; -}; - -static struct getoptflagstate gof; +} gof; static void gotflag(void) { @@ -123,7 +121,7 @@ void get_optflags(void) { - int stopearly = 0, optarg = 0, nodash = 0, minargs = 0, maxargs; + int stopearly = 0, nodash = 0, minargs = 0, maxargs; struct longopts { struct longopts *next; struct opts *opt; @@ -293,13 +291,13 @@ // Not a flag, save value in toys.optargs[] notflag: if (stopearly) stopearly++; - toys.optargs[optarg++] = toys.argv[gof.argc]; + toys.optargs[toys.optc++] = toys.argv[gof.argc]; } // Sanity check - if (optarg<minargs) + if (toys.optc<minargs) error_exit("Need %d argument%s", minargs, minargs ? "s" : ""); - if (optarg>maxargs) + if (toys.optc>maxargs) error_exit("Max %d argument%s", maxargs, maxargs ? "s" : ""); if (CFG_HELP) toys.exithelp = 0; }