[2/6] cmd: Add support for LEQ comparison operator in if statements (try 2)
Frédéric Delanoy
frederic.delanoy at gmail.com
Sun Oct 16 17:03:10 CDT 2011
---
programs/cmd/builtins.c | 10 +++++++++
programs/cmd/tests/test_builtins.cmd | 20 +++++++++++++++++++
programs/cmd/tests/test_builtins.cmd.exp | 31 ++++++++++++++++++++++++++++++
programs/cmd/wcmd.h | 3 +-
4 files changed, 63 insertions(+), 1 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index ffaea4c..faffbf8 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1483,6 +1483,7 @@ void WCMD_popd (void) {
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'};
CMD_IF_OPERATOR *result = NULL;
if (!operator) return NULL;
@@ -1491,6 +1492,8 @@ static CMD_IF_OPERATOR *match_if_operator(const WCHAR *operator)
if (!lstrcmpiW(operator, lssW))
*result = CMD_IF_LSS;
+ else if (!lstrcmpiW(operator, leqW))
+ *result = CMD_IF_LEQ;
else {
HeapFree(GetProcessHeap(), 0, result);
result = NULL;
@@ -1601,6 +1604,13 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList)
test = caseInsensitive ? (lstrcmpiW(leftOperand, rightOperand) < 0)
: (lstrcmpW (leftOperand, rightOperand) < 0);
break;
+ case CMD_IF_LEQ:
+ 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 1244fb4..0aaeaa0 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -618,6 +618,19 @@ if a LSS B (echo a LSS B) else echo NT4
if /I a LSS B echo a LSS B insensitive
if A LSS b echo A LSS b
if /I A LSS b echo A LSS b insensitive
+for %%i in (%STR_PARMS%) do call :LEQtest %%i A
+for %%i in (%STR_PARMS%) do call :LEQtest %%i B
+for %%i in (%STR_PARMS%) do call :LEQtest %%i AB
+for %%i in (%STR_PARMS%) do call :LEQtest %%i BA
+for %%i in (%STR_PARMS%) do call :LEQtest %%i AA
+if b LEQ B (echo b LEQ B) else echo NT4
+if /I b LEQ B echo b LEQ B insensitive
+if b LEQ A echo b LEQ A
+if /I b LEQ A echo b LEQ A insensitive
+if a LEQ B (echo a LEQ B) else echo NT4
+if /I a LEQ B echo a LEQ B insensitive
+if A LEQ b echo A LEQ b
+if /I A LEQ b echo A LEQ b insensitive
echo ...... for numbers ......
if -1 LSS 1 (echo negative numbers handled)
if not -1 LSS -10 (echo negative numbers handled)
@@ -631,12 +644,19 @@ for %%i in (%INT_PARMS%) do call :LSStest %%i 0
for %%i in (%INT_PARMS%) do call :LSStest %%i 1
for %%i in (%INT_PARMS%) do call :LSStest %%i 10
for %%i in (%INT_PARMS%) do call :LSStest %%i 9
+for %%i in (%INT_PARMS%) do call :LEQtest %%i 0
+for %%i in (%INT_PARMS%) do call :LEQtest %%i 1
+for %%i in (%INT_PARMS%) do call :LEQtest %%i 10
+for %%i in (%INT_PARMS%) do call :LEQtest %%i 9
goto :endIfCompOpsSubroutines
rem IF subroutines helpers
:LSStest
if %1 LSS %2 echo %1 LSS %2
goto :eof
+:LEQtest
+if %1 LEQ %2 echo %1 LEQ %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 e78b211..f6c2224 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -422,6 +422,27 @@ a LSS B at or_broken@NT4
a LSS B insensitive
A LSS b
A LSS b insensitive
+A LEQ A
+A LEQ B
+B LEQ B
+AB LEQ B
+AA LEQ B
+A LEQ AB
+AB LEQ AB
+AA LEQ AB
+A LEQ BA
+B LEQ BA
+AB LEQ BA
+BA LEQ BA
+AA LEQ BA
+A LEQ AA
+AA LEQ AA
+b LEQ B at or_broken@NT4
+b LEQ B insensitive
+a LEQ B at or_broken@NT4
+a LEQ B insensitive
+A LEQ b
+A LEQ b insensitive
...... for numbers ......
negative numbers handled
negative numbers handled
@@ -436,6 +457,16 @@ also in negative form
9 LSS 10
0 LSS 9
1 LSS 9
+0 LEQ 0
+0 LEQ 1
+1 LEQ 1
+0 LEQ 10
+1 LEQ 10
+10 LEQ 10
+9 LEQ 10
+0 LEQ 9
+1 LEQ 9
+9 LEQ 9
-----------Testing for -----------
...plain FOR
A
diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h
index b5e3d0b..47ddadd 100644
--- a/programs/cmd/wcmd.h
+++ b/programs/cmd/wcmd.h
@@ -53,7 +53,8 @@ typedef struct _CMD_LIST {
/* Data structure to hold IF extended comparison operators */
typedef enum _CMD_IF_OPERATOR {
- CMD_IF_LSS /* < */
+ CMD_IF_LSS, /* < */
+ CMD_IF_LEQ /* <= */
} CMD_IF_OPERATOR;
void WCMD_assoc (const WCHAR *, BOOL);
--
1.7.7
More information about the wine-patches
mailing list