[3/7] cmd: Add support for EQU comparison operator in if statements (try 3)
Frédéric Delanoy
frederic.delanoy at gmail.com
Thu Sep 15 13:20:54 CDT 2011
---
programs/cmd/builtins.c | 8 ++++++++
programs/cmd/tests/test_builtins.cmd | 17 +++++++++++++++++
programs/cmd/tests/test_builtins.cmd.exp | 14 ++++++++++++++
3 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 0baac16..b1f0f27 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1504,6 +1504,7 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList) {
static const WCHAR eqeqW[] = {'=','=','\0'};
static const WCHAR lssW[] = {'l','s','s','\0'};
static const WCHAR leqW[] = {'l','e','q','\0'};
+ static const WCHAR equW[] = {'e','q','u','\0'};
static const WCHAR parmI[] = {'/','I','\0'};
int caseInsensitive = (strstrW(quals, parmI) != NULL);
@@ -1582,6 +1583,13 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList) {
test = caseInsensitive ? (lstrcmpiW(left, right) <= 0)
: (lstrcmpW (left, right) <= 0);
}
+ else if (!lstrcmpiW(compOp, equW)) {
+ if (bothInts)
+ test = (a == b);
+ else
+ test = caseInsensitive ? (lstrcmpiW(left, right) == 0)
+ : (lstrcmpW (left, right) == 0);
+ }
else {
HeapFree(GetProcessHeap(), 0, right);
HeapFree(GetProcessHeap(), 0, compOp);
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index f3187a6..5362438 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -631,10 +631,18 @@ if a LEQ B (echo a LEQ B) else echo NT4
if /I a LEQ B echo a LEQ B insensitive
if A LEQ b echo A LEQ b
if /I A LEQ b echo A LEQ b insensitive
+for %%i in (%STR_PARMS%) do call :EQUtest %%i A
+for %%i in (%STR_PARMS%) do call :EQUtest %%i B
+for %%i in (%STR_PARMS%) do call :EQUtest %%i AB
+for %%i in (%STR_PARMS%) do call :EQUtest %%i BA
+for %%i in (%STR_PARMS%) do call :EQUtest %%i AA
+if /I A EQU a echo A EQU a insensitive
echo ...... for numbers ......
if -1 LSS 1 (echo foo) else echo bar
if 11 LSS 101 (echo riri) else echo fifi
if 9 LSS 010 (echo loulou) else echo picsou
+if 0xA1 EQU "161" (echo hexa should be be recognized) else (echo string/hexa compare ok)
+if "0xA1" EQU 161 (echo hexa should be be recognized) else (echo string/hexa compare ok)
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
@@ -644,6 +652,12 @@ for %%i in (%INT_PARMS%) do call :LEQtest %%i 0
for %%i in (%INT_PARMS%) do call :LEQtest %%i 1
for %%i in (%INT_PARMS%) do call :LEQtest %%i 10
for %%i in (%INT_PARMS%) do call :LEQtest %%i 9
+for %%i in (%INT_PARMS%) do call :EQUtest %%i 0
+for %%i in (%INT_PARMS%) do call :EQUtest %%i 1
+for %%i in (%INT_PARMS%) do call :EQUtest %%i 10
+for %%i in (%INT_PARMS%) do call :EQUtest %%i 9
+if 011 EQU 9 (echo octal ok)
+if 0xA1 EQU 161 (echo hexa ok)
goto :endIfCompOpsSubroutines
rem IF subroutines helpers
@@ -653,6 +667,9 @@ goto :eof
:LEQtest
if %1 LEQ %2 echo %1 LEQ %2
goto :eof
+:EQUtest
+if %1 EQU %2 echo %1 EQU %2
+goto :eof
:endIfCompOpsSubroutines
set STR_PARMS=
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 26e50b0..d0b0d23 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -443,10 +443,18 @@ a LEQ B at or_broken@NT4
a LEQ B insensitive
A LEQ b
A LEQ b insensitive
+A EQU A
+B EQU B
+AB EQU AB
+BA EQU BA
+AA EQU AA
+A EQU a insensitive
...... for numbers ......
foo
riri
picsou
+string/hexa compare ok
+string/hexa compare ok
0 LSS 1
0 LSS 10
1 LSS 10
@@ -463,6 +471,12 @@ picsou
0 LEQ 9
1 LEQ 9
9 LEQ 9
+0 EQU 0
+1 EQU 1
+10 EQU 10
+9 EQU 9
+octal ok
+hexa ok
-----------Testing for -----------
...plain FOR
A
--
1.7.6
More information about the wine-patches
mailing list