From b081ce98999111aa5518388ed7eb8e5ceb5629f9 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 26 Feb 2012 16:11:25 -0600 Subject: Teach lib/args.c that " " this option must take a _separate_ argument, so "kill -stop" and "kill -s top" aren't the same thing. Make kill.c use it, and remove leftover debug printfs. --- lib/args.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'lib/args.c') diff --git a/lib/args.c b/lib/args.c index 0ec20375..8b209d97 100644 --- a/lib/args.c +++ b/lib/args.c @@ -23,8 +23,10 @@ // Same HIGH=DEFAULT as # // @ plus an occurrence counter (which is a long) // (longopt) -// | this is required. If more than one marked, only one required. +// | this is required. If more than one marked, only one required. TODO // ^ Stop parsing after encountering this argument +// " " (space char) the "plus an argument" must be separate +// I.E. "-j 3" not "-j3". So "kill -stop" != "kill -s top" // // These modify other option letters (previously seen in string): // +X enabling this enables X (switch on) @@ -175,7 +177,8 @@ static int gotflag(struct getoptflagstate *gof) void parse_optflaglist(struct getoptflagstate *gof) { - char *options = toys.which->options, *plustildenot = "+~!", *limits = "<>="; + char *options = toys.which->options, *plustildenot = "+~!", + *limits = "<>=", *flagbits="|^ "; long *nextarg = (long *)&this; struct opts *new = 0; int i; @@ -255,8 +258,8 @@ void parse_optflaglist(struct getoptflagstate *gof) } new->edx[idx] |= 1<flags |= 1; - else if (*options == '^') new->flags |= 2; + } else if (0 != (temp = strchr(flagbits, *options))) + new->flags |= 1<<(temp-flagbits); // bounds checking else if (0 != (temp = strchr(limits, *options))) { i = temp - limits; @@ -382,7 +385,8 @@ void get_optflags(void) // Identify next option char. for (gof.this = gof.opts; gof.this; gof.this = gof.this->next) - if (*gof.arg == gof.this->c) break; + if (*gof.arg == gof.this->c) + if (!((gof.this->flags&4) && gof.arg[1])) break; // Handle option char (advancing past what was used) if (gotflag(&gof) ) { -- cgit v1.2.3