cmd: Fix handling of nested if-for expressions on a single line.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50641
Signed-off-by: Roman Pišl <rpisl@seznam.cz>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
(cherry picked from commit 6809e0599e)
Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
This commit is contained in:
Roman Pišl 2021-02-08 19:06:43 +01:00 committed by Michael Stefaniuc
parent d0a38a32c7
commit 907c5a2135
3 changed files with 14 additions and 2 deletions

View File

@ -1599,8 +1599,14 @@ static void WCMD_part_execute(CMD_LIST **cmdList, const WCHAR *firstcmd,
the same bracket depth as the IF, then the IF statement is over. This is required the same bracket depth as the IF, then the IF statement is over. This is required
to handle nested ifs properly */ to handle nested ifs properly */
} else if (isIF && (*cmdList)->bracketDepth == myDepth) { } else if (isIF && (*cmdList)->bracketDepth == myDepth) {
WINE_TRACE("Found end of this nested IF statement, ending this if\n"); static const WCHAR doW[] = {'d','o'};
break; if (WCMD_keyword_ws_found(doW, ARRAY_SIZE(doW), (*cmdList)->command)) {
WINE_TRACE("Still inside FOR-loop, not an end of IF statement\n");
*cmdList = (*cmdList)->nextcommand;
} else {
WINE_TRACE("Found end of this nested IF statement, ending this if\n");
break;
}
} else if (!processThese) { } else if (!processThese) {
if (curPosition == *cmdList) *cmdList = (*cmdList)->nextcommand; if (curPosition == *cmdList) *cmdList = (*cmdList)->nextcommand;
WINE_TRACE("Skipping this command, as in not process mode (next = %p)\n", *cmdList); WINE_TRACE("Skipping this command, as in not process mode (next = %p)\n", *cmdList);

View File

@ -1242,6 +1242,10 @@ goto :eof
set WINE_STR_PARMS= set WINE_STR_PARMS=
set WINE_INT_PARMS= set WINE_INT_PARMS=
echo ------------ Testing if/for ------------
if ""=="" for %%i in (A) DO (echo %%i)
if not ""=="" for %%i in (B) DO (echo %%i)
echo ------------ Testing for ------------ echo ------------ Testing for ------------
echo --- plain FOR echo --- plain FOR
for %%i in (A B C) do echo %%i for %%i in (A B C) do echo %%i

View File

@ -914,6 +914,8 @@ x@space@
--- ---
x@space@ x@space@
--- ---
------------ Testing if/for ------------
A
------------ Testing for ------------ ------------ Testing for ------------
--- plain FOR --- plain FOR
A A