aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-31 10:09:26 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-31 10:09:26 +0000
commitf173607520e0455d267a7a4100e5018f30000c56 (patch)
tree6699a09a57e45890ac07eb4ec2964f9ed7486230
parentfbeeb328b8a2e0006f9a53ddea6892f9c1a03132 (diff)
downloadbusybox-w32-f173607520e0455d267a7a4100e5018f30000c56.tar.gz
busybox-w32-f173607520e0455d267a7a4100e5018f30000c56.tar.bz2
busybox-w32-f173607520e0455d267a7a4100e5018f30000c56.zip
hush: fix "case ... in <newline> word)..."
-rw-r--r--shell/hush.c12
-rw-r--r--shell/hush_test/hush-misc/case1.right1
-rwxr-xr-xshell/hush_test/hush-misc/case1.tests8
3 files changed, 20 insertions, 1 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 564b62c54..8be0ecf1c 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -3659,6 +3659,15 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
3659 * a newline as a command separator. 3659 * a newline as a command separator.
3660 * [why we don't handle it exactly like ';'? --vda] */ 3660 * [why we don't handle it exactly like ';'? --vda] */
3661 if (end_trigger && ch == '\n') { 3661 if (end_trigger && ch == '\n') {
3662#if ENABLE_HUSH_CASE
3663 /* "case ... in <newline> word) ..." -
3664 * newlines are ignored (but ';' wouldn't be) */
3665 if (dest->length == 0 // && argv[0] == NULL
3666 && ctx->ctx_res_w == RES_MATCH
3667 ) {
3668 continue;
3669 }
3670#endif
3662 done_pipe(ctx, PIPE_SEQ); 3671 done_pipe(ctx, PIPE_SEQ);
3663 } 3672 }
3664 } 3673 }
@@ -3839,7 +3848,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
3839 done_word(dest, ctx); 3848 done_word(dest, ctx);
3840#if ENABLE_HUSH_CASE 3849#if ENABLE_HUSH_CASE
3841 if (ctx->ctx_res_w == RES_MATCH) 3850 if (ctx->ctx_res_w == RES_MATCH)
3842 break; 3851 break; /* we are in case's "word | word)" */
3843#endif 3852#endif
3844 if (next == '|') { 3853 if (next == '|') {
3845 i_getch(input); 3854 i_getch(input);
@@ -3853,6 +3862,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
3853 break; 3862 break;
3854 case '(': 3863 case '(':
3855#if ENABLE_HUSH_CASE 3864#if ENABLE_HUSH_CASE
3865 /* "case... in [(]word)..." - skip '(' */
3856 if (dest->length == 0 // && argv[0] == NULL 3866 if (dest->length == 0 // && argv[0] == NULL
3857 && ctx->ctx_res_w == RES_MATCH 3867 && ctx->ctx_res_w == RES_MATCH
3858 ) { 3868 ) {
diff --git a/shell/hush_test/hush-misc/case1.right b/shell/hush_test/hush-misc/case1.right
index 9b88658af..e9e371ac0 100644
--- a/shell/hush_test/hush-misc/case1.right
+++ b/shell/hush_test/hush-misc/case1.right
@@ -1,4 +1,5 @@
1OK_1 1OK_1
2OK_1
2OK_21 3OK_21
3OK_22 4OK_22
4OK_23 5OK_23
diff --git a/shell/hush_test/hush-misc/case1.tests b/shell/hush_test/hush-misc/case1.tests
index 15f60f3a6..0174893ec 100755
--- a/shell/hush_test/hush-misc/case1.tests
+++ b/shell/hush_test/hush-misc/case1.tests
@@ -1,5 +1,13 @@
1case w in a) echo SKIP;; w) echo OK_1;; w) echo WRONG;; esac 1case w in a) echo SKIP;; w) echo OK_1;; w) echo WRONG;; esac
2 2
3case w in
4 a) echo SKIP;;
5 w)echo OK_1 ;;
6 w)
7 echo WRONG
8 ;;
9esac
10
3t=w 11t=w
4case $t in a) echo SKIP;; w) echo OK_21;; w) echo WRONG;; esac; 12case $t in a) echo SKIP;; w) echo OK_21;; w) echo WRONG;; esac;
5case "$t" in a) echo SKIP;; w) echo OK_22;; w) echo WRONG;; esac; 13case "$t" in a) echo SKIP;; w) echo OK_22;; w) echo WRONG;; esac;