[PATCH v3] cmd: if 'if' condition is not met and cmdList->nextCommand is not null, all commands in the list should be ignored as well

Carlos Rafael Ramirez crramirez at gmail.com
Mon Oct 31 18:57:33 CDT 2016


Fixes https://bugs.winehq.org/show_bug.cgi?id=33636

Changes in version 3 of this patch: Correct the subject

Changes in version 2 of this patch: It ensures eat all commands in the cmdList if the 'if' condition is not satified. Also it includes tests with the fixes.

Tested on Windows 10 and Ubuntu 16.04.1.

Signed-off-by: Carlos Rafael Ramirez <crramirez at gmail.com>
---
 programs/cmd/builtins.c                  |  3 +++
 programs/cmd/tests/test_builtins.cmd     | 11 +++++++++++
 programs/cmd/tests/test_builtins.cmd.exp | 13 +++++++++++++
 3 files changed, 27 insertions(+)

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 49c366a..a29a502 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1574,6 +1574,9 @@ static void WCMD_part_execute(CMD_LIST **cmdList, const WCHAR *firstcmd,
             }
           }
           if (curPosition == *cmdList) *cmdList = (*cmdList)->nextcommand;
+        } else if (!processThese) {
+          if (curPosition == *cmdList) *cmdList = (*cmdList)->nextcommand;
+          WINE_TRACE("Ignore the next command as well (next = %p)\n", *cmdList);
         } else {
           WINE_TRACE("Found end of this IF statement (next = %p)\n", *cmdList);
           break;
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index eac5dca..38a7700 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -836,6 +836,17 @@ if 1 GEQ "10" (echo 1 GEQ "10") else echo foo
 if "1" GEQ "10" (echo 1 GEQ "10") else echo foo
 if '1' GEQ "10" (echo '1' GEQ "10") else echo foo
 if "10" GEQ "10" (echo "10" GEQ "10")
+echo --- unconditional ampersand after if one line
+if "0"=="0" echo 1 & echo 2 & echo 3 else echo 4
+echo ---
+echo x & if "0"=="1" echo 1 & echo 2
+echo ---
+echo x & if "0"=="1" echo 1 & echo 2 & echo 3
+echo ---
+echo x & if "0"=="1" (echo 1 & echo 2 & echo 3)
+echo ---
+echo x & if "0"=="1" echo 1 & echo 2 & echo 3 else echo 4
+echo ---
 goto :endIfCompOpsSubroutines
 
 rem IF subroutines helpers
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 67e75e0..5775977 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -645,6 +645,19 @@ foo
 foo
 '1' GEQ "10"
 "10" GEQ "10"
+--- unconditional ampersand after if one line
+1 
+2 
+3 else echo 4
+---
+x 
+---
+x 
+---
+x 
+---
+x 
+---
 ------------ Testing for ------------
 --- plain FOR
 A
-- 
2.7.4




More information about the wine-patches mailing list