Commit 58d21b33 authored by Jason Edmeades's avatar Jason Edmeades Committed by Alexandre Julliard

cmd: Handle single line 'if' as nested if or with redirects.

A single line if statement causes problems when it has redirects and/or continuation type operators (|, &&, || etc) because it is expected that if there is more than one command in the 'if', then it will use brackets. This patch changes the 'if' parsing to emulate brackets at a continuation character. In addition, 'for' and 'if' statements do not have their output redirected immediately, instead it is redirected on the individual commands being executed not the statement itself. We were opening the redirect once for the 'if' and once for the processing of the statement inside the if. Signed-off-by: 's avatarJason Edmeades <us@edmeades.me.uk> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 5c444c4e
......@@ -1544,8 +1544,8 @@ static void WCMD_part_execute(CMD_LIST **cmdList, const WCHAR *firstcmd,
CMD_LIST *curPosition = *cmdList;
int myDepth = (*cmdList)->bracketDepth;
WINE_TRACE("cmdList(%p), firstCmd(%s), doIt(%d)\n", cmdList, wine_dbgstr_w(firstcmd),
executecmds);
WINE_TRACE("cmdList(%p), firstCmd(%s), doIt(%d), isIF(%d)\n", cmdList,
wine_dbgstr_w(firstcmd), executecmds, isIF);
/* Skip leading whitespace between condition and the command */
while (firstcmd && *firstcmd && (*firstcmd==' ' || *firstcmd=='\t')) firstcmd++;
......@@ -1592,7 +1592,8 @@ static void WCMD_part_execute(CMD_LIST **cmdList, const WCHAR *firstcmd,
} else if ((*cmdList)->bracketDepth > myDepth) {
if (processThese) {
*cmdList = WCMD_process_commands(*cmdList, TRUE, FALSE);
WINE_TRACE("Back from processing commands, (next = %p)\n", *cmdList);
} else {
WINE_TRACE("Skipping command %p due to stack depth\n", *cmdList);
}
if (curPosition == *cmdList) *cmdList = (*cmdList)->nextcommand;
......@@ -1626,9 +1627,16 @@ static void WCMD_part_execute(CMD_LIST **cmdList, const WCHAR *firstcmd,
processThese = TRUE;
}
if (curPosition == *cmdList) *cmdList = (*cmdList)->nextcommand;
/* If we were in an IF statement and we didnt find an else and yet we get back to
the same bracket depth as the IF, then the IF statement is over. This is required
to handle nested ifs properly */
} else if (isIF && (*cmdList)->bracketDepth == myDepth) {
WINE_TRACE("Found end of this nested IF statement, ending this if\n");
break;
} else if (!processThese) {
if (curPosition == *cmdList) *cmdList = (*cmdList)->nextcommand;
WINE_TRACE("Ignore the next command as well (next = %p)\n", *cmdList);
WINE_TRACE("Skipping this command, as in not process mode (next = %p)\n", *cmdList);
} else {
WINE_TRACE("Found end of this IF statement (next = %p)\n", *cmdList);
break;
......
......@@ -179,6 +179,8 @@ if exist foo (type foo) else echo not supported
echo --- redirections within IF statements
if 1==1 echo foo1>bar
type bar & del bar
if 1==1 echo foo2>>bar
type bar & del bar
echo -----
if 1==1 (echo foo2>bar) else echo baz2>bar
type bar & del bar
......@@ -925,6 +927,13 @@ if %elseIF% == 1 (
) else (
echo else if seems to be broken
)
if "x" == "a" (
echo broken1
) else (
echo expected1
if "y" == "b" echo broken2
echo expected post-embedded if
)
echo --- case sensitivity with and without /i option
if bar==BAR echo if does not default to case sensitivity
if not bar==BAR echo if seems to default to case sensitivity
......
......@@ -205,7 +205,8 @@ food21
@todo_wine@foo7@space@@space@@or_broken@not supported@space@
@todo_wine@foo@or_broken@not supported
--- redirections within IF statements
@todo_wine@foo1
foo1
foo2
-----
foo2
foo3
......@@ -430,7 +431,7 @@ p1
q1
@todo_wine@---
--- chain else (if false)
@todo_wine@j3
j3
---
k3
l3
......@@ -661,6 +662,8 @@ if seems not to detect /c as parameter
else if seems to work
else if seems to work
else if seems to work
expected1
expected post-embedded if
--- case sensitivity with and without /i option
if seems to default to case sensitivity
if /i seems to work
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment