[1/7] cmd: Add support for LSS comparison operator in if statements
Frédéric Delanoy
frederic.delanoy at gmail.com
Thu Sep 1 06:02:19 CDT 2011
Adapted from John Gilik's patches
See http://www.winehq.org/pipermail/wine-patches/2010-March/085912.html
---
programs/cmd/Makefile.in | 2 +-
programs/cmd/builtins.c | 20 ++++++++++++++++-
programs/cmd/tests/test_builtins.cmd | 34 ++++++++++++++++++++++++++++++
programs/cmd/tests/test_builtins.cmd.exp | 24 +++++++++++++++++++++
4 files changed, 78 insertions(+), 2 deletions(-)
diff --git a/programs/cmd/Makefile.in b/programs/cmd/Makefile.in
index 1203eb9..97e1025 100644
--- a/programs/cmd/Makefile.in
+++ b/programs/cmd/Makefile.in
@@ -1,7 +1,7 @@
MODULE = cmd.exe
APPMODE = -mconsole -municode
EXTRADEFS = -DWINE_NO_UNICODE_MACROS
-IMPORTS = shell32 user32 advapi32
+IMPORTS = shell32 user32 advapi32 shlwapi
C_SRCS = \
batch.c \
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 7f003ed..e338812 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -37,6 +37,7 @@
#include "wcmd.h"
#include <shellapi.h>
+#include <shlwapi.h>
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(cmd);
@@ -1477,13 +1478,15 @@ void WCMD_popd (void) {
void WCMD_if (WCHAR *p, CMD_LIST **cmdList) {
- int negate = 0, test = 0;
+ int negate = 0, test = 0, a, b;
WCHAR condition[MAX_PATH], *command, *s;
static const WCHAR notW[] = {'n','o','t','\0'};
static const WCHAR errlvlW[] = {'e','r','r','o','r','l','e','v','e','l','\0'};
static const WCHAR existW[] = {'e','x','i','s','t','\0'};
static const WCHAR defdW[] = {'d','e','f','i','n','e','d','\0'};
static const WCHAR eqeqW[] = {'=','=','\0'};
+ static const WCHAR lssW[] = {'l','s','s','\0'};
+ static const WCHAR zeroW[] = {'0','\0'};
static const WCHAR parmI[] = {'/','I','\0'};
if (!lstrcmpiW (param1, notW)) {
@@ -1521,6 +1524,21 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList) {
}
WCMD_parameter (s, 1, &command);
}
+ else if ((s = StrStrIW (p, lssW))) {
+ s += 3;
+ a = StrToIntW(condition);
+ b = StrToIntW(WCMD_parameter (s, 0, NULL));
+ if ((a != 0 || lstrcmpW(condition, zeroW) == 0) && (b != 0 || lstrcmpW(WCMD_parameter (s, 0, NULL), zeroW) == 0)) {
+ if (a < b) test = 1;
+ }
+ else if (strstrW (quals, parmI) == NULL) {
+ if (lstrcmpW (condition, WCMD_parameter (s, 0, NULL)) < 0) test = 1;
+ }
+ else {
+ if (lstrcmpiW (condition, WCMD_parameter (s, 0, NULL)) < 0) test = 1;
+ }
+ WCMD_parameter (s, 1, &command);
+ }
else {
WCMD_output (WCMD_LoadMessage(WCMD_SYNTAXERR));
return;
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index 5bd375e..eae4fbe 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -583,6 +583,40 @@ if at tab@not @tab at 1==@tab at 0 @tab at echo lol
if 1==0 at tab@(echo doom) else echo quake
if 1==0 (echo doom)@tab at else echo quake
if 1==0 (echo doom) else at tab@echo quake
+echo Testing comparison operators
+rem NT4 misevaluates conditionals in for loops so we have to use subroutines as workarounds
+rem Imbricated for loops parameters are currently not expanded correctly; this prevents usage of simpler imbricated for loops in tests
+echo ... comparison operators for strings
+set STR_PARMS=A B AB BA AA
+for %%i in (%STR_PARMS%) do call :LSStest %%i A
+for %%i in (%STR_PARMS%) do call :LSStest %%i B
+for %%i in (%STR_PARMS%) do call :LSStest %%i AB
+for %%i in (%STR_PARMS%) do call :LSStest %%i BA
+for %%i in (%STR_PARMS%) do call :LSStest %%i AA
+if b LSS B (echo b LSS B) else echo NT4
+if /I b LSS B echo b LSS B insensitive
+if b LSS A echo b LSS A
+if /I b LSS A echo b LSS A insensitive
+if a LSS B (echo a LSS B) else echo NT4
+if /I a LSS B echo a LSS B insensitive
+if A LSS b echo A LSS b
+if /I A LSS b echo A LSS b insensitive
+echo ... comparison operators for numbers
+set INT_PARMS=0 1 10 9
+for %%i in (%INT_PARMS%) do call :LSStest %%i 0
+for %%i in (%INT_PARMS%) do call :LSStest %%i 1
+for %%i in (%INT_PARMS%) do call :LSStest %%i 10
+for %%i in (%INT_PARMS%) do call :LSStest %%i 9
+goto :endIfCompOpsSubroutines
+
+rem IF subroutines helpers
+:LSStest
+if %1 LSS %2 echo %1 LSS %2
+goto :eof
+
+:endIfCompOpsSubroutines
+set STR_PARMS=
+set INT_PARMS=
echo -----------Testing for -----------
echo ...plain FOR
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index c67b10f..28782c5 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -394,6 +394,30 @@ lol
quake
quake
quake
+Testing comparison operators
+... comparison operators for strings
+A LSS B
+AB LSS B
+AA LSS B
+A LSS AB
+AA LSS AB
+A LSS BA
+B LSS BA
+AB LSS BA
+AA LSS BA
+A LSS AA
+b LSS B at or_broken@NT4
+a LSS B at or_broken@NT4
+a LSS B insensitive
+A LSS b
+A LSS b insensitive
+... comparison operators for numbers
+0 LSS 1
+0 LSS 10
+1 LSS 10
+9 LSS 10
+0 LSS 9
+1 LSS 9
-----------Testing for -----------
...plain FOR
A
--
1.7.6
More information about the wine-patches
mailing list