aboutsummaryrefslogtreecommitdiff
path: root/lib/args.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-03-10 20:22:52 -0600
committerRob Landley <rob@landley.net>2018-03-10 20:22:52 -0600
commit9d84dc3564a6bc2e4a9ac83c0c84e7e295b420a4 (patch)
tree4a5a5ff647e5c21e3991dc446221204e02f32403 /lib/args.c
parenta36cf940366ed0ad303fa25044e9964617e73c22 (diff)
downloadtoybox-9d84dc3564a6bc2e4a9ac83c0c84e7e295b420a4.tar.gz
Add a way for commands to distinguish "ps -ax" from "ps ax".
Diffstat (limited to 'lib/args.c')
-rw-r--r--lib/args.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/args.c b/lib/args.c
index 00932de9..7b9350f8 100644
--- a/lib/args.c
+++ b/lib/args.c
@@ -76,8 +76,7 @@
// <0 die if less than # leftover arguments (default 0)
// >9 die if > # leftover arguments (default MAX_INT)
// ? Allow unknown arguments (pass them through to command).
-// & first argument has imaginary dash (ala tar/ps)
-// If given twice, all arguments have imaginary dash
+// & first arg has imaginary dash (ala tar/ps/ar) which sets FLAGS_NODASH
//
// At the end: [groups] of previously seen options
// - Only one in group (switch off) [-abc] means -ab=-b, -ba=-a, -abc=-c
@@ -120,7 +119,7 @@ struct longopts {
// State during argument parsing.
struct getoptflagstate
{
- int argc, minargs, maxargs, nodash;
+ int argc, minargs, maxargs;
char *arg;
struct opts *opts;
struct longopts *longopts;
@@ -244,7 +243,7 @@ void parse_optflaglist(struct getoptflagstate *gof)
else if (*options == '<') gof->minargs=*(++options)-'0';
else if (*options == '>') gof->maxargs=*(++options)-'0';
else if (*options == '?') gof->noerror++;
- else if (*options == '&') gof->nodash++;
+ else if (*options == '&') toys.optflags |= FLAGS_NODASH;
else break;
options++;
}
@@ -444,7 +443,7 @@ void get_optflags(void)
// Handle things that don't start with a dash.
} else {
- if (gof.nodash && (gof.nodash>1 || gof.argc == 1)) gof.nodash_now = 1;
+ if ((toys.optflags & FLAGS_NODASH) && gof.argc == 1) gof.nodash_now = 1;
else goto notflag;
}