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

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


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

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index bc71ccd..f928ca0 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1485,6 +1485,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'};
+    static const WCHAR neqW[] = {'n','e','q','\0'};
     CMD_IF_OPERATOR *result = NULL;
 
     if (!operator) return NULL;
@@ -1497,6 +1498,8 @@ static CMD_IF_OPERATOR *match_if_operator(const WCHAR *operator)
         *result = CMD_IF_LEQ;
     else if (!lstrcmpiW(operator, equW))
         *result = CMD_IF_EQU;
+    else if (!lstrcmpiW(operator, neqW))
+        *result = CMD_IF_NEQ;
     else {
         HeapFree(GetProcessHeap(), 0, result);
         result = NULL;
@@ -1621,6 +1624,13 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList)
           test = caseInsensitive ? (lstrcmpiW(leftOperand, rightOperand) == 0)
                                  : (lstrcmpW (leftOperand, rightOperand) == 0);
         break;
+      case CMD_IF_NEQ:
+        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 ccee317..4815b03 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -637,6 +637,11 @@ 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
+for %%i in (%STR_PARMS%) do call :NEQtest %%i A
+for %%i in (%STR_PARMS%) do call :NEQtest %%i B
+for %%i in (%STR_PARMS%) do call :NEQtest %%i AB
+for %%i in (%STR_PARMS%) do call :NEQtest %%i BA
+for %%i in (%STR_PARMS%) do call :NEQtest %%i AA
 echo ...... for numbers ......
 if -1 LSS 1 (echo negative numbers handled)
 if not -1 LSS -10 (echo negative numbers handled)
@@ -662,6 +667,10 @@ 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)
+for %%i in (%INT_PARMS%) do call :NEQtest %%i 0
+for %%i in (%INT_PARMS%) do call :NEQtest %%i 1
+for %%i in (%INT_PARMS%) do call :NEQtest %%i 10
+for %%i in (%INT_PARMS%) do call :NEQtest %%i 9
 goto :endIfCompOpsSubroutines
 
 rem IF subroutines helpers
@@ -674,6 +683,9 @@ goto :eof
 :EQUtest
 if %1 EQU %2 echo %1 EQU %2
 goto :eof
+:NEQtest
+if %1 NEQ %2 echo %1 NEQ %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 3823139..ad5083f 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -449,6 +449,26 @@ AB EQU AB
 BA EQU BA
 AA EQU AA
 A EQU a insensitive
+B NEQ A
+AB NEQ A
+BA NEQ A
+AA NEQ A
+A NEQ B
+AB NEQ B
+BA NEQ B
+AA NEQ B
+A NEQ AB
+B NEQ AB
+BA NEQ AB
+AA NEQ AB
+A NEQ BA
+B NEQ BA
+AB NEQ BA
+AA NEQ BA
+A NEQ AA
+B NEQ AA
+AB NEQ AA
+BA NEQ AA
 ...... for numbers ......
 negative numbers handled
 negative numbers handled
@@ -481,6 +501,18 @@ octal ok
 hexa ok
 string/hexa compare ok
 string/hexa compare ok
+1 NEQ 0
+10 NEQ 0
+9 NEQ 0
+0 NEQ 1
+10 NEQ 1
+9 NEQ 1
+0 NEQ 10
+1 NEQ 10
+9 NEQ 10
+0 NEQ 9
+1 NEQ 9
+10 NEQ 9
 -----------Testing for -----------
 ...plain FOR
 A
diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h
index ebc4e89..28d8579 100644
--- a/programs/cmd/wcmd.h
+++ b/programs/cmd/wcmd.h
@@ -55,7 +55,8 @@ typedef struct _CMD_LIST {
 typedef enum _CMD_IF_OPERATOR {
     CMD_IF_LSS, /* <  */
     CMD_IF_LEQ, /* <= */
-    CMD_IF_EQU  /* == */
+    CMD_IF_EQU, /* == */
+    CMD_IF_NEQ  /* != */
 } CMD_IF_OPERATOR;
 
 void WCMD_assoc (const WCHAR *, BOOL);
-- 
1.7.7




More information about the wine-patches mailing list