changeset 499:bc4615e2e339

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.
author Rob Landley <rob@landley.net>
date Sun, 26 Feb 2012 16:11:25 -0600
parents c9aaceccd6bd
children cd70270dbc51
files lib/args.c toys/kill.c
diffstat 2 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/lib/args.c	Sun Feb 26 13:48:00 2012 -0600
+++ b/lib/args.c	Sun Feb 26 16:11:25 2012 -0600
@@ -23,8 +23,10 @@
 //       Same <LOW>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 @@
 
 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 @@
 			}
 			new->edx[idx] |= 1<<i;
 		} else if (*options == '[') { // TODO
-		} else if (*options == '|') new->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 @@
 
 			// 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) ) {
--- a/toys/kill.c	Sun Feb 26 13:48:00 2012 -0600
+++ b/toys/kill.c	Sun Feb 26 16:11:25 2012 -0600
@@ -6,7 +6,7 @@
  *
  * See http://opengroup.org/onlinepubs/9699919799/utilities/kill.html
 
-USE_KILL(NEWTOY(kill, "?s:l", TOYFLAG_BIN))
+USE_KILL(NEWTOY(kill, "?s: l", TOYFLAG_BIN))
 
 config KILL
 	bool "kill"
@@ -45,10 +45,8 @@
 	}
 
 	// signal must come before pids, so "kill -9 -1" isn't confusing.
-printf("*args=%s\n", *args);
 
 	if (!TT.signame && *args && **args=='-') TT.signame=*(args++)+1;
-printf("TT.signame=%s\n", TT.signame);
 	if (TT.signame) {
 		char *arg;
 		int i = strtol(TT.signame, &arg, 10);