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

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


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

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index f928ca0..383208f 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1486,6 +1486,7 @@ static CMD_IF_OPERATOR *match_if_operator(const WCHAR *operator)
     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 geqW[] = {'g','e','q','\0'};
     CMD_IF_OPERATOR *result = NULL;
 
     if (!operator) return NULL;
@@ -1500,6 +1501,8 @@ static CMD_IF_OPERATOR *match_if_operator(const WCHAR *operator)
         *result = CMD_IF_EQU;
     else if (!lstrcmpiW(operator, neqW))
         *result = CMD_IF_NEQ;
+    else if (!lstrcmpiW(operator, geqW))
+        *result = CMD_IF_GEQ;
     else {
         HeapFree(GetProcessHeap(), 0, result);
         result = NULL;
@@ -1631,6 +1634,13 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList)
           test = caseInsensitive ? (lstrcmpiW(leftOperand, rightOperand) != 0)
                                  : (lstrcmpW (leftOperand, rightOperand) != 0);
         break;
+      case CMD_IF_GEQ:
+        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 4815b03..04facb6 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -642,6 +642,11 @@ 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
+for %%i in (%STR_PARMS%) do call :GEQtest %%i A
+for %%i in (%STR_PARMS%) do call :GEQtest %%i B
+for %%i in (%STR_PARMS%) do call :GEQtest %%i AB
+for %%i in (%STR_PARMS%) do call :GEQtest %%i BA
+for %%i in (%STR_PARMS%) do call :GEQtest %%i AA
 echo ...... for numbers ......
 if -1 LSS 1 (echo negative numbers handled)
 if not -1 LSS -10 (echo negative numbers handled)
@@ -671,6 +676,10 @@ 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
+for %%i in (%INT_PARMS%) do call :GEQtest %%i 0
+for %%i in (%INT_PARMS%) do call :GEQtest %%i 1
+for %%i in (%INT_PARMS%) do call :GEQtest %%i 10
+for %%i in (%INT_PARMS%) do call :GEQtest %%i 9
 goto :endIfCompOpsSubroutines
 
 rem IF subroutines helpers
@@ -686,6 +695,9 @@ goto :eof
 :NEQtest
 if %1 NEQ %2 echo %1 NEQ %2
 goto :eof
+:GEQtest
+if %1 GEQ %2 echo %1 GEQ %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 ad5083f..5685d67 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -469,6 +469,21 @@ A NEQ AA
 B NEQ AA
 AB NEQ AA
 BA NEQ AA
+A GEQ A
+B GEQ A
+AB GEQ A
+BA GEQ A
+AA GEQ A
+B GEQ B
+BA GEQ B
+B GEQ AB
+AB GEQ AB
+BA GEQ AB
+BA GEQ BA
+B GEQ AA
+AB GEQ AA
+BA GEQ AA
+AA GEQ AA
 ...... for numbers ......
 negative numbers handled
 negative numbers handled
@@ -513,6 +528,16 @@ string/hexa compare ok
 0 NEQ 9
 1 NEQ 9
 10 NEQ 9
+0 GEQ 0
+1 GEQ 0
+10 GEQ 0
+9 GEQ 0
+1 GEQ 1
+10 GEQ 1
+9 GEQ 1
+10 GEQ 10
+10 GEQ 9
+9 GEQ 9
 -----------Testing for -----------
 ...plain FOR
 A
diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h
index 28d8579..46df811 100644
--- a/programs/cmd/wcmd.h
+++ b/programs/cmd/wcmd.h
@@ -56,7 +56,8 @@ typedef enum _CMD_IF_OPERATOR {
     CMD_IF_LSS, /* <  */
     CMD_IF_LEQ, /* <= */
     CMD_IF_EQU, /* == */
-    CMD_IF_NEQ  /* != */
+    CMD_IF_NEQ, /* != */
+    CMD_IF_GEQ  /* >= */
 } CMD_IF_OPERATOR;
 
 void WCMD_assoc (const WCHAR *, BOOL);
-- 
1.7.7




More information about the wine-patches mailing list