hush: fix "case ... in <newline> word)..."
authorDenis Vlasenko <vda.linux@googlemail.com>
Thu, 31 Jul 2008 10:09:26 +0000 (10:09 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Thu, 31 Jul 2008 10:09:26 +0000 (10:09 -0000)
shell/hush.c
shell/hush_test/hush-misc/case1.right
shell/hush_test/hush-misc/case1.tests

index 564b62c54651bc47fb8cec848a21fac250103517..8be0ecf1c8420058c227ebc5dfa2365aad5b8ae6 100644 (file)
@@ -3659,6 +3659,15 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
                         * a newline as a command separator.
                         * [why we don't handle it exactly like ';'? --vda] */
                        if (end_trigger && ch == '\n') {
+#if ENABLE_HUSH_CASE
+                               /* "case ... in <newline> word) ..." -
+                                * newlines are ignored (but ';' wouldn't be) */
+                               if (dest->length == 0 // && argv[0] == NULL
+                                && ctx->ctx_res_w == RES_MATCH
+                               ) {
+                                       continue;
+                               }
+#endif
                                done_pipe(ctx, PIPE_SEQ);
                        }
                }
@@ -3839,7 +3848,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
                        done_word(dest, ctx);
 #if ENABLE_HUSH_CASE
                        if (ctx->ctx_res_w == RES_MATCH)
-                               break;
+                               break; /* we are in case's "word | word)" */
 #endif
                        if (next == '|') {
                                i_getch(input);
@@ -3853,6 +3862,7 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
                        break;
                case '(':
 #if ENABLE_HUSH_CASE
+                       /* "case... in [(]word)..." - skip '(' */
                        if (dest->length == 0 // && argv[0] == NULL
                         && ctx->ctx_res_w == RES_MATCH
                        ) {
index 9b88658af6f13ba67b4e8af859e44ccd1bb39cdf..e9e371ac0d13b0a6d5b720ad4830584124416370 100644 (file)
@@ -1,4 +1,5 @@
 OK_1
+OK_1
 OK_21
 OK_22
 OK_23
index 15f60f3a68ba06f403bc25e054855ccd8da56213..0174893ec9c0679ce03d6b7d63d750a663e3713e 100755 (executable)
@@ -1,5 +1,13 @@
 case w in a) echo SKIP;; w) echo OK_1;; w) echo WRONG;; esac
 
+case w in
+ a) echo SKIP;;
+ w)echo OK_1 ;;
+ w)
+ echo WRONG
+ ;;
+esac
+
 t=w
 case $t in a) echo SKIP;; w) echo OK_21;; w) echo WRONG;; esac;
 case "$t" in a) echo SKIP;; w) echo OK_22;; w) echo WRONG;; esac;