[4/7] cmd: Add support for NEQ comparison operator in if statements (try 2)
Frédéric Delanoy
frederic.delanoy at gmail.com
Mon Sep 12 13:47:12 CDT 2011
---
programs/cmd/builtins.c | 8 +++++++
programs/cmd/tests/test_builtins.cmd | 12 +++++++++++
programs/cmd/tests/test_builtins.cmd.exp | 32 ++++++++++++++++++++++++++++++
3 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index b8ddd15..c7ac120 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1505,6 +1505,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 parmI[] = {'/','I','\0'};
int caseInsensitive = (strstrW(quals, parmI) != NULL);
@@ -1584,6 +1585,13 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList) {
test = caseInsensitive ? (lstrcmpiW(left, right) == 0)
: (lstrcmpW (left, right) == 0);
}
+ else if (!lstrcmpiW(compOp, neqW)) {
+ if (bothInts)
+ test = (a != b);
+ else
+ test = caseInsensitive ? (lstrcmpiW(left, right) != 0)
+ : (lstrcmpW (left, right) != 0);
+ }
else {
HeapFree(GetProcessHeap(), 0, right);
HeapFree(GetProcessHeap(), 0, compOp);
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index 44095ce..24e1c9a 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 foo) else echo bar
if 11 LSS 101 (echo riri) else echo fifi
@@ -658,6 +663,10 @@ 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)
+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
@@ -670,6 +679,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 4d4260f..41147e1 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 ......
foo
riri
@@ -477,6 +497,18 @@ string/hexa compare ok
9 EQU 9
octal ok
hexa 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.6
More information about the wine-patches
mailing list