Module: wine
Branch: master
Commit: 1a9413b98a04358935424c54a73fa8b38f03832e
URL: http://source.winehq.org/git/wine.git/?a=commit;h=1a9413b98a04358935424c54a…
Author: Jason Edmeades <us(a)edmeades.me.uk>
Date: Sun Sep 2 23:25:21 2012 +0100
cmd: for /l with zero iterations failed to skip its commands.
---
programs/cmd/builtins.c | 18 +++++++++++-------
programs/cmd/tests/test_builtins.cmd | 5 +++++
programs/cmd/tests/test_builtins.cmd.exp | 4 ++--
3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index e28ff10..a83947b 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -968,7 +968,7 @@ void WCMD_echo (const WCHAR *command)
*/
static void WCMD_part_execute(CMD_LIST **cmdList, const WCHAR *firstcmd,
const WCHAR *variable, const WCHAR *value,
- BOOL isIF, BOOL conditionTRUE)
+ BOOL isIF, BOOL executecmds)
{
CMD_LIST *curPosition = *cmdList;
int myDepth = (*cmdList)->bracketDepth;
@@ -976,13 +976,13 @@ static void WCMD_part_execute(CMD_LIST **cmdList, const WCHAR *firstcmd,
WINE_TRACE("cmdList(%p), firstCmd(%p), with variable '%s'='%s', doIt(%d)\n",
cmdList, wine_dbgstr_w(firstcmd),
wine_dbgstr_w(variable), wine_dbgstr_w(value),
- conditionTRUE);
+ executecmds);
/* Skip leading whitespace between condition and the command */
while (firstcmd && *firstcmd && (*firstcmd==' ' || *firstcmd=='\t')) firstcmd++;
/* Process the first command, if there is one */
- if (conditionTRUE && firstcmd && *firstcmd) {
+ if (executecmds && firstcmd && *firstcmd) {
WCHAR *command = WCMD_strdupW(firstcmd);
WCMD_execute (firstcmd, (*cmdList)->redirects, variable, value, cmdList);
HeapFree(GetProcessHeap(), 0, command);
@@ -994,9 +994,7 @@ static void WCMD_part_execute(CMD_LIST **cmdList, const WCHAR *firstcmd,
/* Process any other parts of the command */
if (*cmdList) {
- BOOL processThese = TRUE;
-
- if (isIF) processThese = conditionTRUE;
+ BOOL processThese = executecmds;
while (*cmdList) {
static const WCHAR ifElse[] = {'e','l','s','e'};
@@ -1372,8 +1370,14 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
thisCmdStart = cmdStart;
WCMD_part_execute(&thisCmdStart, firstCmd, variable, thisNum, FALSE, TRUE);
- cmdEnd = thisCmdStart;
}
+
+ /* Now skip over the subsequent commands if we did not perform the for loop */
+ if (thisCmdStart == cmdStart) {
+ WINE_TRACE("Skipping for loop commands due to no valid iterations\n");
+ WCMD_part_execute(&thisCmdStart, firstCmd, variable, thisNum, FALSE, FALSE);
+ }
+ cmdEnd = thisCmdStart;
}
/* When the loop ends, either something like a GOTO or EXIT /b has terminated
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index 4856578..36bc73f 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -685,6 +685,11 @@ for /L %%i in (1,1,1) do echo %%i
for /L %%i in (1,-2,-1) do echo %%i
for /L %%i in (-1,-1,-1) do echo %%i
for /L %%i in (1,2, 3) do echo %%i
+rem Test zero iteration skips the body of the for
+for /L %%i in (2,2,1) do (
+ echo %%i
+ echo FAILED
+)
echo --- for /a
rem No output when using "set expr" syntax, unless in interactive mode
rem Need to use "set envvar=expr" to use in a batch script
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 0011d35..c444be6 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -469,8 +469,8 @@ bar
2
1
-1
-@todo_wine@ErrorLevel 0
-@todo_wine@ErrorLevel 0
+ErrorLevel 0
+ErrorLevel 0
1
2
3
Module: wine
Branch: master
Commit: 3a25888f38dbfed5d80368aaea4c2bd4f601dc7b
URL: http://source.winehq.org/git/wine.git/?a=commit;h=3a25888f38dbfed5d80368aae…
Author: Jason Edmeades <us(a)edmeades.me.uk>
Date: Sun Sep 2 22:08:57 2012 +0100
cmd: for loops did not respect boundaries.
---
programs/cmd/builtins.c | 2 +-
programs/cmd/tests/test_builtins.cmd | 18 ++++++++++++------
programs/cmd/tests/test_builtins.cmd.exp | 19 +++++++++++++++++++
3 files changed, 32 insertions(+), 7 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index ebb1c80..e28ff10 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1364,7 +1364,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) {
WINE_TRACE("FOR /L provided range from %d to %d step %d\n",
numbers[0], numbers[2], numbers[1]);
for (i=numbers[0];
- (numbers[1]<0)? i>numbers[2] : i<numbers[2];
+ (numbers[1]<0)? i>=numbers[2] : i<=numbers[2];
i=i + numbers[1]) {
sprintfW(thisNum, fmt, i);
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index 6295f9e..4856578 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -673,12 +673,18 @@ for /L %%i in (1,2,a) do echo %%i
echo ErrorLevel %ErrorLevel%
for /L %%i in (1,a,b) do echo %%i
echo ErrorLevel %ErrorLevel%
-rem FIXME: following test cases cannot be currently tested due to an inconsistent/buggy 'for /L' parsing.
-rem for /L %%i in (a,2,b) do echo %%i
-rem for /L %%i in (1,1,1) do echo %%i
-rem for /L %%i in (1,-2,-1) do echo %%i
-rem for /L %%i in (-1,-1,-1) do echo %%i
-rem for /L %%i in (1,2, 3) do echo %%i
+rem Test boundaries
+for /l %%i in (1,1,4) do echo %%i
+for /l %%i in (1,2,4) do echo %%i
+for /l %%i in (4,-1,1) do echo %%i
+for /l %%i in (4,-2,1) do echo %%i
+for /l %%i in (1,-1,4) do echo %%i
+for /l %%i in (4,1,1) do echo %%i
+for /L %%i in (a,2,b) do echo %%i
+for /L %%i in (1,1,1) do echo %%i
+for /L %%i in (1,-2,-1) do echo %%i
+for /L %%i in (-1,-1,-1) do echo %%i
+for /L %%i in (1,2, 3) do echo %%i
echo --- for /a
rem No output when using "set expr" syntax, unless in interactive mode
rem Need to use "set envvar=expr" to use in a batch script
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index bb75515..0011d35 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -471,6 +471,25 @@ bar
-1
@todo_wine@ErrorLevel 0
@todo_wine@ErrorLevel 0
+1
+2
+3
+4
+1
+3
+4
+3
+2
+1
+4
+2
+0
+1
+1
+-1
+-1
+1
+3
--- for /a
------ individual operations
0