[2/6] cmd: Add support for LEQ comparison operator in if statements (try 3) (resend)
Frédéric Delanoy
frederic.delanoy at gmail.com
Sat Oct 22 07:52:14 CDT 2011
---
programs/cmd/builtins.c | 9 ++++++++
programs/cmd/tests/test_builtins.cmd | 20 +++++++++++++++++++
programs/cmd/tests/test_builtins.cmd.exp | 31 ++++++++++++++++++++++++++++++
3 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 0b77095..e096c04 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -1503,6 +1503,7 @@ static int evaluate_if_extended_operator(WCHAR *leftOperand, WCHAR *operator, WC
long int leftOperand_int, rightOperand_int;
BOOL int_operands;
static const WCHAR lssW[] = {'l','s','s','\0'};
+ static const WCHAR leqW[] = {'l','e','q','\0'};
/* Check if we have plain integers (in decimal, octal or hexadecimal notation) */
leftOperand_int = strtolW(leftOperand, &endptr_leftOp, 0);
@@ -1518,6 +1519,14 @@ static int evaluate_if_extended_operator(WCHAR *leftOperand, WCHAR *operator, WC
: (lstrcmpW (leftOperand, rightOperand) < 0);
}
+ if (!lstrcmpiW(operator, leqW)) {
+ 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 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
--
1.7.7
More information about the wine-patches
mailing list