[4/7] cmd: Add support for NEQ comparison operator in if statements

Frédéric Delanoy frederic.delanoy at gmail.com
Thu Sep 1 06:02:22 CDT 2011


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

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index f4cab69..504d013 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1488,6 +1488,7 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList) {
   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'};
   static const WCHAR zeroW[]   = {'0','\0'};
   static const WCHAR parmI[]   = {'/','I','\0'};
 
@@ -1571,6 +1572,21 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList) {
     }
     WCMD_parameter (s, 1, &command);
   }
+  else if ((s = StrStrIW (p, neqW))) {
+    s += 3;
+    a = StrToIntW(condition);
+    b = StrToIntW(WCMD_parameter (s, 0, NULL));
+    if ((a != 0 || lstrcmpW(condition, zeroW) == 0) && (b != 0 || lstrcmpW(WCMD_parameter (s, 0, NULL), zeroW) == 0)) {
+        if (a != b) test = 1;
+    }
+    else if (strstrW (quals, parmI) == NULL) {
+        if (lstrcmpW (condition, WCMD_parameter (s, 0, NULL)) != 0) test = 1;
+    }
+    else {
+        if (lstrcmpiW (condition, WCMD_parameter (s, 0, NULL)) != 0) test = 1;
+    }
+    WCMD_parameter (s, 1, &command);
+  }
   else {
     WCMD_output (WCMD_LoadMessage(WCMD_SYNTAXERR));
     return;
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index c475f74..5c4d6ed 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -619,6 +619,11 @@ 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
+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 ... comparison operators for numbers
 set INT_PARMS=0 1 10 9
 for %%i in (%INT_PARMS%) do call :LSStest %%i 0
@@ -633,6 +638,10 @@ 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
+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
@@ -645,6 +654,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 de2381b..cb637d5 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -437,6 +437,26 @@ B EQU B
 AB EQU AB
 BA EQU BA
 AA EQU AA
+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
 ... comparison operators for numbers
 0 LSS 1
 0 LSS 10
@@ -458,6 +478,18 @@ AA EQU AA
 1 EQU 1
 10 EQU 10
 9 EQU 9
+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.6




More information about the wine-patches mailing list