cmd: Fix handling of brackets in if-set expressions on a single line.

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

View File

@ -1246,6 +1246,11 @@ echo ------------ Testing if/for ------------
if ""=="" for %%i in (A) DO (echo %%i)
if not ""=="" for %%i in (B) DO (echo %%i)
echo ------------ Testing if/set ------------
set x=C:\Program Files (x86)
if ""=="" set y=%x%\dummy
echo %y%
echo ------------ Testing for ------------
echo --- plain FOR
for %%i in (A B C) do echo %%i

View File

@ -916,6 +916,8 @@ x@space@
---
------------ Testing if/for ------------
A
------------ Testing if/set ------------
C:\Program Files (x86)\dummy
------------ Testing for ------------
--- plain FOR
A

View File

@ -1817,6 +1817,7 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
static const WCHAR forCmd[] = {'f','o','r'};
static const WCHAR ifCmd[] = {'i','f'};
static const WCHAR ifElse[] = {'e','l','s','e'};
static const WCHAR setCmd[] = {'s','e','t'};
BOOL inOneLine = FALSE;
BOOL inFor = FALSE;
BOOL inIn = FALSE;
@ -1829,6 +1830,8 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
BOOL lastWasElse = FALSE;
BOOL lastWasRedirect = TRUE;
BOOL lastWasCaret = FALSE;
BOOL ignoreBracket = FALSE; /* Some expressions after if (set) require */
/* handling brackets as a normal character */
int lineCurDepth; /* Bracket depth when line was read in */
BOOL resetAtEndOfLine = FALSE; /* Do we need to reset curdepth at EOL */
@ -1957,6 +1960,9 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
curPos+=if_condition_len;
}
if (WCMD_keyword_ws_found(setCmd, ARRAY_SIZE(setCmd), curPos))
ignoreBracket = TRUE;
} else if (WCMD_keyword_ws_found(ifElse, ARRAY_SIZE(ifElse), curPos)) {
const int keyw_len = ARRAY_SIZE(ifElse) + 1;
inElse = TRUE;
@ -2146,7 +2152,7 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
In an ELSE statement, only allow it straight away after
the ELSE and whitespace
*/
} else if (inIf ||
} else if ((inIf && !ignoreBracket) ||
(inElse && lastWasElse && onlyWhiteSpace) ||
(inFor && (lastWasIn || lastWasDo) && onlyWhiteSpace)) {