ash: allow newline after variable name in for loop
authorRon Yorston <rmy@pobox.com>
Mon, 3 Aug 2015 12:46:00 +0000 (13:46 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 29 Oct 2015 18:30:55 +0000 (19:30 +0100)
Newline is a valid delimiter between the variable name and `in`
keyword in for loops.

Based on commit 22e8fb4 from git://git.kernel.org/pub/scm/utils/dash/dash.git
by Herbert Xu.

function                                             old     new   delta
parse_command                                       1568    1563      -5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-5)               Total: -5 bytes

Signed-off-by: Ron Yorston <rmy@pobox.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/ash.c
shell/ash_test/ash-misc/for.right [new file with mode: 0644]
shell/ash_test/ash-misc/for.tests [new file with mode: 0755]

index 17121aa9b7b897e80030f6a5488ff53f70fabc86..3339666b9db0232c740c9911655b395054bf73a6 100644 (file)
@@ -10913,7 +10913,7 @@ parse_command(void)
                n1 = stzalloc(sizeof(struct nfor));
                n1->type = NFOR;
                n1->nfor.var = wordtext;
-               checkkwd = CHKKWD | CHKALIAS;
+               checkkwd = CHKNL | CHKKWD | CHKALIAS;
                if (readtoken() == TIN) {
                        app = &ap;
                        while (readtoken() == TWORD) {
@@ -10940,7 +10940,7 @@ parse_command(void)
                         * Newline or semicolon here is optional (but note
                         * that the original Bourne shell only allowed NL).
                         */
-                       if (lasttoken != TNL && lasttoken != TSEMI)
+                       if (lasttoken != TSEMI)
                                tokpushback = 1;
                }
                checkkwd = CHKNL | CHKKWD | CHKALIAS;
diff --git a/shell/ash_test/ash-misc/for.right b/shell/ash_test/ash-misc/for.right
new file mode 100644 (file)
index 0000000..d86bac9
--- /dev/null
@@ -0,0 +1 @@
+OK
diff --git a/shell/ash_test/ash-misc/for.tests b/shell/ash_test/ash-misc/for.tests
new file mode 100755 (executable)
index 0000000..4889a9f
--- /dev/null
@@ -0,0 +1,5 @@
+for i
+in OK
+do
+       echo $i
+done