summary refs log tree commit diff
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2005-10-29 14:03:32 +1000
committerHerbert Xu <herbert@gondor.apana.org.au>2005-10-29 14:15:36 +1000
commit982e3044a5e1f77cadd16d5adca999173c5bb42a (patch)
treec3a91c0673d63551173c1e7d349ff0db2e4e2ce4
parent[SIGNAL] Use bsd_signal if it exists and signal does not (diff)
downloaddash-982e3044a5e1f77cadd16d5adca999173c5bb42a.tar.gz
dash-982e3044a5e1f77cadd16d5adca999173c5bb42a.zip
[BUILTIN] Stop using sysexits.h in commandcmd
This gets rid of the only reference of sysexits.h in dash which is
from commandcmd.  This is needed for klibc support since it doesn't
have sysexits.h.

The only uses of sysexits.h in commandcmd is superfluous anyway.  In
fact, it is overly sensitive about usages such as 'command -vV ls'.
By making its behaviour close to that of bash/ksh, we end up saving
a bit of space too.
-rw-r--r--ChangeLog1
-rw-r--r--src/exec.c43
2 files changed, 13 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index 8cfcc6a..7c49913 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,7 @@
 	* Removed CVS IDs and inclusion of sys/cdefs.h.
 	* Removed use of __P from error.h.
 	* Use bsd_signal if it exists and signal does not.
+	* Stop using sysexits.h in commandcmd.
 
 2005-10-26  Herbert Xu <herbert@gondor.apana.org.au>
 
diff --git a/src/exec.c b/src/exec.c
index c098eed..9b1a8bf 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -37,7 +37,6 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <stdlib.h>
-#include <sysexits.h>
 #include <paths.h>
 
 /*
@@ -847,41 +846,23 @@ commandcmd(argc, argv)
 	char **argv;
 {
 	int c;
-	int default_path = 0;
-	int verify_only = 0;
-	int verbose_verify_only = 0;
+	enum {
+		VERIFY_BRIEF = 1,
+		VERIFY_VERBOSE = 2,
+	} verify = 0;
 
 	while ((c = nextopt("pvV")) != '\0')
-		switch (c) {
-		default:
+		if (c == 'V')
+			verify |= VERIFY_VERBOSE;
+		else if (c == 'v')
+			verify |= VERIFY_BRIEF;
 #ifdef DEBUG
-			outfmt(out2,
-"command: nextopt returned character code 0%o\n", c);
-			return EX_SOFTWARE;
+		else if (c != 'p')
+			abort();
 #endif
-		case 'p':
-			default_path = 1;
-			break;
-		case 'v':
-			verify_only = 1;
-			break;
-		case 'V':
-			verbose_verify_only = 1;
-			break;
-		}
-
-	if (default_path + verify_only + verbose_verify_only > 1 ||
-	    !*argptr) {
-			outfmt(out2,
-"command [-p] command [arg ...]\n");
-			outfmt(out2,
-"command {-v|-V} command\n");
-			return EX_USAGE;
-	}
 
-	if (verify_only || verbose_verify_only) {
-		return describe_command(out1, *argptr, verbose_verify_only);
-	}
+	if (verify)
+		return describe_command(out1, *argptr, verify - VERIFY_BRIEF);
 
 	return 0;
 }
IFS is set to an empty string, sepc is set to '\0' in varvalue(). > This then causes *quotedp to be set to true, meaning evalvar()'s quoted > variable is turned on. quoted is then passed to recordregion() as the > nulonly parameter. > > ifsp->nulonly has a bigger effect than merely selecting whether to use > $IFS or whether to only split on null bytes: in ifsbreakup(), nulonly > also causes string termination to be suppressed. That's correct: that > special treatment is required to preserve empty fields in "$@" > expansion. But it should *only* be used when $@ is quoted: ifsbreakup() > takes nulonly from the last IFS region, even if it's empty, so having an > additional zero-length region with nulonly enabled causes confusion. > > Passing quoted by value to varvalue() and not attempting to modify it > should therefore, and in my quick testing does, also work to fix the > original $@ bug. You're right. The proper fix to this is to ensure that nulonly is not set in varvalue for $*. It should only be set for $@ when it's inside double quotes. In fact there is another bug while we're playing with $@/$*. When IFS is set to a non-whitespace character such as :, $* outside quotes won't remove empty fields as it should. This patch fixes both problems. Reported-by: Martijn Dekker <martijn@inlv.org> Suggested-by: Harald van Dijk <harald@gigawatt.nl> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> 2018-04-02parser: Allow newlines within parameter substitutionHerbert Xu On Fri, Mar 16, 2018 at 11:27:22AM +0800, Herbert Xu wrote: > On Thu, Mar 15, 2018 at 10:49:15PM +0100, Harald van Dijk wrote: > > > > Okay, it can be trivially modified to something that does work in other > > shells (even if it were actually executed), but gets rejected at parse time > > by dash: > > > > if false; then > > : ${$+ > > } > > fi > > That's just a bug in dash's parser with ${} in general, because > it bombs out without the if clause too: > > : ${$+ > } This patch fixes the parsing of newlines with parameter substitution. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> 2018-04-02expand: Fix bugs with words connected to the right of $@Herbert Xu On Sun, Mar 04, 2018 at 12:44:59PM +0100, Harald van Dijk wrote: > > command: set -- a ""; space=" "; printf "<%s>" "$@"$space > bash: <a><> > dash 0.5.8: <a>< > > dash 0.5.9.1: <a>< > > dash patched: <a><> This is actually composed of two bugs. First of all our tracking of quotemark is wrong so anything after "$@" becomes quoted. Once we fix that then the problem is that the first space character after "$@" is not recognised as an IFS. This patch fixes both. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> 2018-03-25Revert "[BUILTIN] Remove unnecessary restoration of format string in printf"Herbert Xu This reverts commit 7bb413255368e94395237d789f522891093c5774. The commit breaks printf with more than argument. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> 2018-03-22parser: Fix backquote support in here-document EOF markHerbert Xu