cmd: Fix subdirectory prefix in for loops.
A for loop can be working through a wildcarded subdirectory, but when processing the first file in the subdirectory, it stores the prefix in a static variable which gets overwritten during the 'for' body processing. Signed-off-by: Jason Edmeades <us@edmeades.me.uk> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
f53d57c854
commit
15215bd071
|
@ -2261,19 +2261,25 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
|
||||||
thisSet->bracketDepth >= thisDepth) {
|
thisSet->bracketDepth >= thisDepth) {
|
||||||
|
|
||||||
/* Loop through all entries on the same line */
|
/* Loop through all entries on the same line */
|
||||||
WCHAR *item;
|
WCHAR *staticitem;
|
||||||
WCHAR *itemStart;
|
WCHAR *itemStart;
|
||||||
WCHAR buffer[MAXSTRING];
|
WCHAR buffer[MAXSTRING];
|
||||||
|
|
||||||
WINE_TRACE("Processing for set %p\n", thisSet);
|
WINE_TRACE("Processing for set %p\n", thisSet);
|
||||||
i = 0;
|
i = 0;
|
||||||
while (*(item = WCMD_parameter (thisSet->command, i, &itemStart, TRUE, FALSE))) {
|
while (*(staticitem = WCMD_parameter (thisSet->command, i, &itemStart, TRUE, FALSE))) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the parameter within the set has a wildcard then search for matching files
|
* If the parameter within the set has a wildcard then search for matching files
|
||||||
* otherwise do a literal substitution.
|
* otherwise do a literal substitution.
|
||||||
*/
|
*/
|
||||||
static const WCHAR wildcards[] = {'*','?','\0'};
|
static const WCHAR wildcards[] = {'*','?','\0'};
|
||||||
|
|
||||||
|
/* Take a copy of the item returned from WCMD_parameter as it is held in a
|
||||||
|
static buffer which can be overwritten during parsing of the for body */
|
||||||
|
WCHAR item[MAXSTRING];
|
||||||
|
strcpyW(item, staticitem);
|
||||||
|
|
||||||
thisCmdStart = cmdStart;
|
thisCmdStart = cmdStart;
|
||||||
|
|
||||||
itemNum++;
|
itemNum++;
|
||||||
|
|
|
@ -1155,9 +1155,16 @@ mkdir foobar & cd foobar
|
||||||
mkdir foo
|
mkdir foo
|
||||||
mkdir bar
|
mkdir bar
|
||||||
mkdir baz
|
mkdir baz
|
||||||
|
mkdir pop
|
||||||
echo > bazbaz
|
echo > bazbaz
|
||||||
echo --- basic wildcards
|
echo --- basic wildcards
|
||||||
for %%i in (ba*) do echo %%i
|
for %%i in (ba*) do echo %%i
|
||||||
|
echo --- wildcards in subdirs
|
||||||
|
echo something>pop\bar1
|
||||||
|
echo something>pop\bar2.txt
|
||||||
|
echo something>pop\bar3
|
||||||
|
for %%f in (pop\ba*) do ( call echo %%f )
|
||||||
|
rmdir /s/q pop
|
||||||
echo --- for /d
|
echo --- for /d
|
||||||
for /d %%i in (baz foo bar) do echo %%i 2>&1
|
for /d %%i in (baz foo bar) do echo %%i 2>&1
|
||||||
rem Confirm we don't match files:
|
rem Confirm we don't match files:
|
||||||
|
|
|
@ -917,6 +917,10 @@ B C
|
||||||
B D
|
B D
|
||||||
--- basic wildcards
|
--- basic wildcards
|
||||||
bazbaz
|
bazbaz
|
||||||
|
--- wildcards in subdirs
|
||||||
|
pop\bar1@space@
|
||||||
|
pop\bar2.txt@space@
|
||||||
|
pop\bar3@space@
|
||||||
--- for /d
|
--- for /d
|
||||||
baz@space@
|
baz@space@
|
||||||
foo@space@
|
foo@space@
|
||||||
|
|
Loading…
Reference in New Issue