[3/6] cmd: Add support for EQU comparison operator in if statements (try 3) (resend)

Frédéric Delanoy frederic.delanoy at gmail.com
Sat Oct 22 07:52:15 CDT 2011


---
 programs/cmd/builtins.c                  |    9 +++++++++
 programs/cmd/tests/test_builtins.cmd     |   17 +++++++++++++++++
 programs/cmd/tests/test_builtins.cmd.exp |   14 ++++++++++++++
 3 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index e096c04..1794d45 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1504,6 +1504,7 @@ static int evaluate_if_extended_operator(WCHAR *leftOperand, WCHAR *operator, WC
     BOOL int_operands;
     static const WCHAR lssW[] = {'l','s','s','\0'};
     static const WCHAR leqW[] = {'l','e','q','\0'};
+    static const WCHAR equW[] = {'e','q','u','\0'};
 
     /* Check if we have plain integers (in decimal, octal or hexadecimal notation) */
     leftOperand_int = strtolW(leftOperand, &endptr_leftOp, 0);
@@ -1527,6 +1528,14 @@ static int evaluate_if_extended_operator(WCHAR *leftOperand, WCHAR *operator, WC
                                : (lstrcmpW (leftOperand, rightOperand) <= 0);
     }
 
+    if (!lstrcmpiW(operator, equW)) {
+      if (int_operands)
+        return (leftOperand_int == rightOperand_int);
+      else
+        return caseInsensitive ? (lstrcmpiW(leftOperand, rightOperand) == 0)
+                               : (lstrcmpW (leftOperand, rightOperand) == 0);
+    }
+
     return -1;
 }
 
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index 0aaeaa0..ccee317 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -631,6 +631,12 @@ 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 negative numbers handled)
 if not -1 LSS -10 (echo negative numbers handled)
@@ -648,6 +654,14 @@ 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)
+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)
 goto :endIfCompOpsSubroutines
 
 rem IF subroutines helpers
@@ -657,6 +671,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 f6c2224..3823139 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -443,6 +443,12 @@ 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 ......
 negative numbers handled
 negative numbers handled
@@ -467,6 +473,14 @@ also in negative form
 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
+string/hexa compare ok
+string/hexa compare ok
 -----------Testing for -----------
 ...plain FOR
 A
-- 
1.7.7




More information about the wine-patches mailing list