From c1a22bbca751bc6ae7ffb8d7cfaf5100306e897b Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 17 Dec 2018 20:26:19 -0600 Subject: Only set FLAGS_NODASH when arguments didn't have a dash. This (eventually) lets "ps ax" and "ps -ax" behave differently. --- lib/args.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/args.c b/lib/args.c index 1927a930..b24dd417 100644 --- a/lib/args.c +++ b/lib/args.c @@ -244,7 +244,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 == '&') toys.optflags |= FLAGS_NODASH; + else if (*options == '&') gof->nodash_now = 1; else break; options++; } @@ -392,6 +392,8 @@ void get_optflags(void) parse_optflaglist(&gof); + if (toys.argv[1] && toys.argv[1][0] == '-') gof.nodash_now = 0; + // Iterate through command line arguments, skipping argv[0] for (gof.argc=1; toys.argv[gof.argc]; gof.argc++) { gof.arg = toys.argv[gof.argc]; @@ -400,7 +402,7 @@ void get_optflags(void) // Parse this argument if (gof.stopearly>1) goto notflag; - gof.nodash_now = 0; + if (gof.argc>1 || *gof.arg=='-') gof.nodash_now = 0; // Various things with dashes if (*gof.arg == '-') { @@ -444,7 +446,7 @@ void get_optflags(void) // Handle things that don't start with a dash. } else { - if ((toys.optflags & FLAGS_NODASH) && gof.argc == 1) gof.nodash_now = 1; + if (gof.nodash_now) toys.optflags |= FLAGS_NODASH; else goto notflag; } -- cgit v1.2.3