From: Rob Landley Date: Tue, 12 Feb 2008 23:36:13 +0000 (-0600) Subject: Add toys.optc, an argv-style count for toys.optargs. X-Git-Tag: 0.0.5~22 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=26bf9e642eba4ea00cdf736d7ac4cd6be095a6af;p=platform%2Fupstream%2Ftoybox.git Add toys.optc, an argv-style count for toys.optargs. --- diff --git a/lib/args.c b/lib/args.c index 96e1e6d..2391daa 100644 --- a/lib/args.c +++ b/lib/args.c @@ -66,15 +66,13 @@ struct opts { 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 @@ static void gotflag(void) 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 @@ void get_optflags(void) // 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 (optargmaxargs) + if (toys.optc>maxargs) error_exit("Max %d argument%s", maxargs, maxargs ? "s" : ""); if (CFG_HELP) toys.exithelp = 0; } diff --git a/toys.h b/toys.h index 3c48fb8..f1f83c6 100644 --- a/toys.h +++ b/toys.h @@ -77,6 +77,7 @@ extern struct toy_context { char **argv; // Original command line arguments unsigned optflags; // Command line option flags from get_optflags() char **optargs; // Arguments left over from get_optflags() + int optc; // Count of optargs int exithelp; // Should error_exit print a usage message first? (Option parsing.) } toys;