Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Nov 2009 22:08:32 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r199282 - in head: bin/sh tools/regression/bin/sh/parser
Message-ID:  <200911142208.nAEM8Wh5014782@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sat Nov 14 22:08:32 2009
New Revision: 199282
URL: http://svn.freebsd.org/changeset/base/199282

Log:
  sh: Allow a newline before "in" in a for command, as required by POSIX.

Added:
  head/tools/regression/bin/sh/parser/for1.0   (contents, props changed)
Modified:
  head/bin/sh/parser.c

Modified: head/bin/sh/parser.c
==============================================================================
--- head/bin/sh/parser.c	Sat Nov 14 20:30:42 2009	(r199281)
+++ head/bin/sh/parser.c	Sat Nov 14 22:08:32 2009	(r199282)
@@ -364,7 +364,9 @@ TRACE(("expecting DO got %s %s\n", tokna
 		n1 = (union node *)stalloc(sizeof (struct nfor));
 		n1->type = NFOR;
 		n1->nfor.var = wordtext;
-		if (readtoken() == TWORD && ! quoteflag && equal(wordtext, "in")) {
+		while (readtoken() == TNL)
+			;
+		if (lasttoken == TWORD && ! quoteflag && equal(wordtext, "in")) {
 			app = &ap;
 			while (readtoken() == TWORD) {
 				n2 = (union node *)stalloc(sizeof (struct narg));

Added: head/tools/regression/bin/sh/parser/for1.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/parser/for1.0	Sat Nov 14 22:08:32 2009	(r199282)
@@ -0,0 +1,29 @@
+# $FreeBSD$
+
+nl='
+'
+list=' a b c'
+for s1 in "$nl" " "; do
+	for s2 in "$nl" ";"; do
+		for s3 in "$nl" " "; do
+			r=''
+			eval "for i${s1}in ${list}${s2}do${s3}r=\"\$r \$i\"; done"
+			[ "$r" = "$list" ] || exit 1
+		done
+	done
+done
+set -- $list
+for s2 in "$nl" " " ";"; do # s2=";" is an extension to POSIX
+	for s3 in "$nl" " "; do
+		r=''
+		eval "for i${s2}do${s3}r=\"\$r \$i\"; done"
+		[ "$r" = "$list" ] || exit 1
+	done
+done
+for s1 in "$nl" " "; do
+	for s2 in "$nl" ";"; do
+		for s3 in "$nl" " "; do
+			eval "for i${s1}in${s2}do${s3}exit 1; done"
+		done
+	done
+done



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200911142208.nAEM8Wh5014782>