aboutsummaryrefslogtreecommitdiff
path: root/lib/args.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2008-02-12 17:36:13 -0600
committerRob Landley <rob@landley.net>2008-02-12 17:36:13 -0600
commit26bf9e642eba4ea00cdf736d7ac4cd6be095a6af (patch)
treefbe81a228562910fc1eeac79e6f07e521cc097f0 /lib/args.c
parent0a521a217d7f1de33a56d75694ed7b8160f7874c (diff)
downloadtoybox-26bf9e642eba4ea00cdf736d7ac4cd6be095a6af.tar.gz
Add toys.optc, an argv-style count for toys.optargs.
Diffstat (limited to 'lib/args.c')
-rw-r--r--lib/args.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/args.c b/lib/args.c
index 96e1e6d3..2391daa3 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 (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;
}