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

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


---
 programs/cmd/builtins.c                  |    9 ++++++++
 programs/cmd/tests/test_builtins.cmd     |   12 +++++++++++
 programs/cmd/tests/test_builtins.cmd.exp |   32 ++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 1794d45..6c92604 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1505,6 +1505,7 @@ static int evaluate_if_extended_operator(WCHAR *leftOperand, WCHAR *operator, WC
     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'};
 
     /* Check if we have plain integers (in decimal, octal or hexadecimal notation) */
     leftOperand_int = strtolW(leftOperand, &endptr_leftOp, 0);
@@ -1536,6 +1537,14 @@ static int evaluate_if_extended_operator(WCHAR *leftOperand, WCHAR *operator, WC
                                : (lstrcmpW (leftOperand, rightOperand) == 0);
     }
 
+    if (!lstrcmpiW(operator, neqW)) {
+      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 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
-- 
1.7.7




More information about the wine-patches mailing list