Fixed the following code:
```plaintext echo 1. && echo ok || echo failed echo 2. || echo failed && echo --- & echo 3. ```
From: Dmitry Sokolov mr.dmitry.sokolov@gmail.com
Fixed the following code:
echo 1. && echo ok || echo failed echo 2. || echo failed && echo --- & echo 3.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=55489 --- programs/cmd/builtins.c | 2 ++ programs/cmd/wcmdmain.c | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 419e812103a..4481eb7177e 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -1485,6 +1485,8 @@ void WCMD_echo (const WCHAR *args) const WCHAR *origcommand = args; WCHAR *trimmed;
+ errorlevel = 0; + if ( args[0]==' ' || args[0]=='\t' || args[0]=='.' || args[0]==':' || args[0]==';' || args[0]=='/') args++; diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index d00c6e07566..f6123fb2173 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -58,6 +58,8 @@ static int max_width; static int numChars;
#define MAX_WRITECONSOLE_SIZE 65535 +#define CMD_SUCCEEDED(res) ((res)==0) +#define CMD_FAILED(res) ((res)!=0)
/* * Returns a buffer for reading from/writing to file @@ -2360,6 +2362,7 @@ CMD_LIST *WCMD_process_commands(CMD_LIST *thisCmd, BOOL oneBracket, BOOL retrycall) {
int bdepth = -1; + CMD_LIST *prevCmd = NULL;
if (thisCmd && oneBracket) bdepth = thisCmd->bracketDepth;
@@ -2381,12 +2384,41 @@ CMD_LIST *WCMD_process_commands(CMD_LIST *thisCmd, BOOL oneBracket, about them and it will be handled in there) Also, skip over any batch labels (eg. :fred) */ if (thisCmd->command && thisCmd->command[0] != ':') { - WINE_TRACE("Executing command: '%s'\n", wine_dbgstr_w(thisCmd->command)); - WCMD_execute (thisCmd->command, thisCmd->redirects, &thisCmd, retrycall); + /* Process the command chaining */ + if ( (thisCmd->prevDelim == CMD_ONSUCCESS && CMD_FAILED(errorlevel)) || + (thisCmd->prevDelim == CMD_ONFAILURE && CMD_SUCCEEDED(errorlevel)) ) { + if (prevCmd && prevCmd->bracketDepth < thisCmd->bracketDepth) { + /* Skipping the chain of commands in brackets */ + int bd = thisCmd->bracketDepth; + do { + WINE_TRACE("Skipping command '%s'\n", wine_dbgstr_w(thisCmd->command)); + prevCmd = thisCmd; + thisCmd = thisCmd->nextcommand; + } while (thisCmd && bd <= thisCmd->bracketDepth); + continue; + } else if (thisCmd->prevDelim == CMD_ONFAILURE && CMD_SUCCEEDED(errorlevel)) { + /* Skipping all chaining commands after '||', i.e. '|| cmd2 && cmd3 || cmd4'*/ + do { + WINE_TRACE("Skipping command '%s'\n", wine_dbgstr_w(thisCmd->command)); + prevCmd = thisCmd; + thisCmd = thisCmd->nextcommand; + } while (thisCmd && (thisCmd->prevDelim == CMD_ONSUCCESS || thisCmd->prevDelim == CMD_ONFAILURE)); + continue; + } else { + /* Skipping the next command */ + WINE_TRACE("Skipping command '%s'\n", wine_dbgstr_w(thisCmd->command)); + } + } else { + WINE_TRACE("Executing command: '%s'\n", wine_dbgstr_w(thisCmd->command)); + WCMD_execute (thisCmd->command, thisCmd->redirects, &thisCmd, retrycall); + } }
/* Step on unless the command itself already stepped on */ - if (thisCmd == origCmd) thisCmd = thisCmd->nextcommand; + if (thisCmd == origCmd) { + prevCmd = thisCmd; + thisCmd = thisCmd->nextcommand; + } } return NULL; }
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=136736
Your paranoid android.
=== debian11 (32 bit report) ===
cmd.exe: batch.c:321: Test succeeded inside todo block: unexpected char 0x0 position -1 in line 285 (got 'j3', wanted 'j3') batch.c:321: Test succeeded inside todo block: unexpected char 0x0 position -1 in line 308 (got 'g3', wanted 'g3') batch.c:321: Test succeeded inside todo block: unexpected char 0x0 position -1 in line 313 (got 'i3', wanted 'i3') batch.c:321: Test succeeded inside todo block: unexpected char 0x0 position -1 in line 631 (got 'foo3 not created', wanted 'foo3 not created') batch.c:321: Test failed: unexpected char 0x46 position 0 in line 1592 (got 'Failed: errorlevel invalid check 1', wanted 'Passed: Did not find dir1\file1') batch.c:321: Test failed: unexpected char 0x44 position 8 in line 1593 (got 'Passed: Did not find dir1\file1', wanted 'Passed: errorlevel invalid check 2') batch.c:321: Test failed: unexpected char 0x32 position 33 in line 1594 (got 'Passed: errorlevel invalid check 2', wanted 'Passed: errorlevel invalid check 3') batch.c:321: Test failed: unexpected char 0x46 position 0 in line 1595 (got 'Failed: errorlevel invalid check 2', wanted '------------ Testing setlocal/endlocal ------------') batch.c:321: Test failed: unexpected char 0x50 position 0 in line 1596 (got 'Passed: errorlevel invalid check 3', wanted '------------ Testing setlocal/endlocal ------------') batch.c:321: Test failed: unexpected char 0x46 position 0 in line 1597 (got 'Failed: errorlevel invalid check 3', wanted '------------ Testing setlocal/endlocal ------------') batch.c:321: Test failed: unexpected char 0x77 position 11 in line 1665 (got 'errorlevel with negative number OK', wanted 'errorlevel just right, good') batch.c:321: Test failed: unexpected char 0x61 position 0 in line 1666 (got 'abc0def', wanted 'errorlevel with leading zero just right, good') batch.c:321: Test failed: unexpected char 0x7a position 11 in line 1667 (got 'errorlevel zero, good', wanted 'errorlevel with negative number OK') batch.c:321: Test failed: unexpected char 0x37 position 0 in line 1668 (got '7 should be 7', wanted 'abc0def@or_broken@abc1def') batch.c:321: Test failed: unexpected char 0x37 position 0 in line 1669 (got '7 should still be 7', wanted 'errorlevel zero, good@or_broken@errorlevel nonzero, bad') batch.c:321: Test failed: unexpected char 0x2d position 0 in line 1670 (got '------------ Testing GOTO ------------', wanted '7 should be 7') batch.c:321: Test failed: unexpected char 0x2d position 0 in line 1671 (got '------------ Testing GOTO ------------', wanted '7 should still be 7')
=== debian11b (64 bit WoW report) ===
cmd.exe: batch.c:321: Test succeeded inside todo block: unexpected char 0x0 position -1 in line 285 (got 'j3', wanted 'j3') batch.c:321: Test succeeded inside todo block: unexpected char 0x0 position -1 in line 308 (got 'g3', wanted 'g3') batch.c:321: Test succeeded inside todo block: unexpected char 0x0 position -1 in line 313 (got 'i3', wanted 'i3') batch.c:321: Test succeeded inside todo block: unexpected char 0x0 position -1 in line 631 (got 'foo3 not created', wanted 'foo3 not created') batch.c:321: Test failed: unexpected char 0x46 position 0 in line 1592 (got 'Failed: errorlevel invalid check 1', wanted 'Passed: Did not find dir1\file1') batch.c:321: Test failed: unexpected char 0x44 position 8 in line 1593 (got 'Passed: Did not find dir1\file1', wanted 'Passed: errorlevel invalid check 2') batch.c:321: Test failed: unexpected char 0x32 position 33 in line 1594 (got 'Passed: errorlevel invalid check 2', wanted 'Passed: errorlevel invalid check 3') batch.c:321: Test failed: unexpected char 0x46 position 0 in line 1595 (got 'Failed: errorlevel invalid check 2', wanted '------------ Testing setlocal/endlocal ------------') batch.c:321: Test failed: unexpected char 0x50 position 0 in line 1596 (got 'Passed: errorlevel invalid check 3', wanted '------------ Testing setlocal/endlocal ------------') batch.c:321: Test failed: unexpected char 0x46 position 0 in line 1597 (got 'Failed: errorlevel invalid check 3', wanted '------------ Testing setlocal/endlocal ------------') batch.c:321: Test failed: unexpected char 0x77 position 11 in line 1665 (got 'errorlevel with negative number OK', wanted 'errorlevel just right, good') batch.c:321: Test failed: unexpected char 0x61 position 0 in line 1666 (got 'abc0def', wanted 'errorlevel with leading zero just right, good') batch.c:321: Test failed: unexpected char 0x7a position 11 in line 1667 (got 'errorlevel zero, good', wanted 'errorlevel with negative number OK') batch.c:321: Test failed: unexpected char 0x37 position 0 in line 1668 (got '7 should be 7', wanted 'abc0def@or_broken@abc1def') batch.c:321: Test failed: unexpected char 0x37 position 0 in line 1669 (got '7 should still be 7', wanted 'errorlevel zero, good@or_broken@errorlevel nonzero, bad') batch.c:321: Test failed: unexpected char 0x2d position 0 in line 1670 (got '------------ Testing GOTO ------------', wanted '7 should be 7') batch.c:321: Test failed: unexpected char 0x2d position 0 in line 1671 (got '------------ Testing GOTO ------------', wanted '7 should still be 7')