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

Frédéric Delanoy frederic.delanoy at gmail.com
Sun Oct 16 17:03:11 CDT 2011


---
 programs/cmd/builtins.c                  |   10 ++++++++++
 programs/cmd/tests/test_builtins.cmd     |   17 +++++++++++++++++
 programs/cmd/tests/test_builtins.cmd.exp |   14 ++++++++++++++
 programs/cmd/wcmd.h                      |    3 ++-
 4 files changed, 43 insertions(+), 1 deletions(-)

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index faffbf8..bc71ccd 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1484,6 +1484,7 @@ static CMD_IF_OPERATOR *match_if_operator(const WCHAR *operator)
 {
     static const WCHAR lssW[] = {'l','s','s','\0'};
     static const WCHAR leqW[] = {'l','e','q','\0'};
+    static const WCHAR equW[] = {'e','q','u','\0'};
     CMD_IF_OPERATOR *result = NULL;
 
     if (!operator) return NULL;
@@ -1494,6 +1495,8 @@ static CMD_IF_OPERATOR *match_if_operator(const WCHAR *operator)
         *result = CMD_IF_LSS;
     else if (!lstrcmpiW(operator, leqW))
         *result = CMD_IF_LEQ;
+    else if (!lstrcmpiW(operator, equW))
+        *result = CMD_IF_EQU;
     else {
         HeapFree(GetProcessHeap(), 0, result);
         result = NULL;
@@ -1611,6 +1614,13 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList)
           test = caseInsensitive ? (lstrcmpiW(leftOperand, rightOperand) <= 0)
                                  : (lstrcmpW (leftOperand, rightOperand) <= 0);
         break;
+      case CMD_IF_EQU:
+        if (int_operands)
+          test = (leftOperand_int == rightOperand_int);
+        else
+          test = caseInsensitive ? (lstrcmpiW(leftOperand, rightOperand) == 0)
+                                 : (lstrcmpW (leftOperand, rightOperand) == 0);
+        break;
     }
 
     HeapFree(GetProcessHeap(), 0, leftOperand);
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
diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h
index 47ddadd..ebc4e89 100644
--- a/programs/cmd/wcmd.h
+++ b/programs/cmd/wcmd.h
@@ -54,7 +54,8 @@ typedef struct _CMD_LIST {
 
 typedef enum _CMD_IF_OPERATOR {
     CMD_IF_LSS, /* <  */
-    CMD_IF_LEQ  /* <= */
+    CMD_IF_LEQ, /* <= */
+    CMD_IF_EQU  /* == */
 } CMD_IF_OPERATOR;
 
 void WCMD_assoc (const WCHAR *, BOOL);
-- 
1.7.7




More information about the wine-patches mailing list