https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fedc68aea842c11d45e15…
commit fedc68aea842c11d45e158394a7eae1b8e7cab1b
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Jul 12 21:41:07 2020 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Wed Aug 19 20:36:11 2020 +0200
[CMD] IF: Some functionality is available only when extensions are enabled.
This functionality is: case insensitivity comparisons (/I);
CMDEXTVERSION and DEFINED unary operators; EQU, NEQ, LSS, LEQ, GTR, GEQ
generic string comparators.
---
base/shell/cmd/cmd.c | 4 ++--
base/shell/cmd/cmd.h | 23 ++++++++++++++++++-----
base/shell/cmd/if.c | 8 ++++----
base/shell/cmd/parser.c | 32 ++++++++++++++++++++++++--------
4 files changed, 48 insertions(+), 19 deletions(-)
diff --git a/base/shell/cmd/cmd.c b/base/shell/cmd/cmd.c
index 4bbffa9faf1..3a57c04ef33 100644
--- a/base/shell/cmd/cmd.c
+++ b/base/shell/cmd/cmd.c
@@ -934,8 +934,8 @@ GetEnvVarOrSpecial(LPCTSTR varName)
/* %CMDEXTVERSION% */
else if (_tcsicmp(varName, _T("CMDEXTVERSION")) == 0)
{
- /* Set version number to 2 */
- _itot(2, ret, 10);
+ /* Set version number to CMDEXTVERSION */
+ _itot(CMDEXTVERSION, ret, 10);
return ret;
}
/* %ERRORLEVEL% */
diff --git a/base/shell/cmd/cmd.h b/base/shell/cmd/cmd.h
index d7bce5c139e..c7a9f4db8b8 100644
--- a/base/shell/cmd/cmd.h
+++ b/base/shell/cmd/cmd.h
@@ -28,6 +28,9 @@
#include "cmdver.h"
#include "cmddbg.h"
+/* Version of the Command Extensions */
+#define CMDEXTVERSION 2
+
#define BREAK_BATCHFILE 1
#define BREAK_OUTOFBATCH 2 /* aka. BREAK_ENDOFBATCHFILES */
#define BREAK_INPUT 3
@@ -232,11 +235,21 @@ INT CommandHistory(LPTSTR param);
#endif
/* Prototypes for IF.C */
-#define IFFLAG_NEGATE 1 /* NOT */
-#define IFFLAG_IGNORECASE 2 /* /I */
-enum { IF_CMDEXTVERSION, IF_DEFINED, IF_ERRORLEVEL, IF_EXIST,
- IF_STRINGEQ, /* == */
- IF_EQU, IF_GTR, IF_GEQ, IF_LSS, IF_LEQ, IF_NEQ };
+#define IFFLAG_NEGATE 1 /* NOT */
+#define IFFLAG_IGNORECASE 2 /* /I - Extended */
+enum {
+ /** Unary operators **/
+ /* Standard */
+ IF_ERRORLEVEL, IF_EXIST,
+ /* Extended */
+ IF_CMDEXTVERSION, IF_DEFINED,
+
+ /** Binary operators **/
+ /* Standard */
+ IF_STRINGEQ, /* == */
+ /* Extended */
+ IF_EQU, IF_NEQ, IF_LSS, IF_LEQ, IF_GTR, IF_GEQ
+};
INT ExecuteIf(struct _PARSED_COMMAND *Cmd);
/* Prototypes for INTERNAL.C */
diff --git a/base/shell/cmd/if.c b/base/shell/cmd/if.c
index c7882ad2fec..e74298ad612 100644
--- a/base/shell/cmd/if.c
+++ b/base/shell/cmd/if.c
@@ -82,7 +82,7 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
return 1;
}
- if (Cmd->If.Operator == IF_CMDEXTVERSION)
+ if (bEnableExtensions && (Cmd->If.Operator == IF_CMDEXTVERSION))
{
/* IF CMDEXTVERSION n: check if Command Extensions version
* is greater or equal to n */
@@ -93,9 +93,9 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
cmd_free(Right);
return 1;
}
- result = (2 >= n);
+ result = (CMDEXTVERSION >= n);
}
- else if (Cmd->If.Operator == IF_DEFINED)
+ else if (bEnableExtensions && (Cmd->If.Operator == IF_DEFINED))
{
/* IF DEFINED var: check if environment variable exists */
result = (GetEnvVarOrSpecial(Right) != NULL);
@@ -167,7 +167,7 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
/* IF str1 == str2 */
result = (StringCmp(Left, Right) == 0);
}
- else
+ else if (bEnableExtensions)
{
result = GenericCmp(StringCmp, Left, Right);
switch (Cmd->If.Operator)
diff --git a/base/shell/cmd/parser.c b/base/shell/cmd/parser.c
index 20310c77830..21bfd2504a9 100644
--- a/base/shell/cmd/parser.c
+++ b/base/shell/cmd/parser.c
@@ -24,19 +24,26 @@ static const TCHAR RedirString[][3] = { _T("<"),
_T(">"), _T(">>") };
static const TCHAR *const IfOperatorString[] =
{
- _T("cmdextversion"),
- _T("defined"),
+ /* Standard */
_T("errorlevel"),
_T("exist"),
-#define IF_MAX_UNARY IF_EXIST
+
+ /* Extended */
+ _T("cmdextversion"),
+ _T("defined"),
+#define IF_MAX_UNARY IF_DEFINED
+
+ /* Standard */
_T("=="),
+
+ /* Extended */
_T("equ"),
- _T("gtr"),
- _T("geq"),
+ _T("neq"),
_T("lss"),
_T("leq"),
- _T("neq"),
-#define IF_MAX_COMPARISON IF_NEQ
+ _T("gtr"),
+ _T("geq"),
+#define IF_MAX_COMPARISON IF_GEQ
};
static BOOL IsSeparator(TCHAR Char)
@@ -389,7 +396,7 @@ static PARSED_COMMAND *ParseIf(void)
memset(Cmd, 0, sizeof(PARSED_COMMAND));
Cmd->Type = C_IF;
- if (_tcsicmp(CurrentToken, _T("/I")) == 0)
+ if (bEnableExtensions && (_tcsicmp(CurrentToken, _T("/I")) == 0))
{
Cmd->If.Flags |= IFFLAG_IGNORECASE;
ParseToken(0, STANDARD_SEPS);
@@ -406,6 +413,10 @@ static PARSED_COMMAND *ParseIf(void)
/* Check for unary operators */
for (; Cmd->If.Operator <= IF_MAX_UNARY; Cmd->If.Operator++)
{
+ /* Skip the extended operators if the extensions are disabled */
+ if (!bEnableExtensions && (Cmd->If.Operator >= IF_CMDEXTVERSION))
+ continue;
+
if (_tcsicmp(CurrentToken, IfOperatorString[Cmd->If.Operator]) == 0)
{
if (ParseToken(0, STANDARD_SEPS) != TOK_NORMAL)
@@ -427,8 +438,13 @@ static PARSED_COMMAND *ParseIf(void)
goto condition_done;
}
+ // Cmd->If.Operator == IF_MAX_UNARY + 1;
for (; Cmd->If.Operator <= IF_MAX_COMPARISON; Cmd->If.Operator++)
{
+ /* Skip the extended operators if the extensions are disabled */
+ if (!bEnableExtensions && (Cmd->If.Operator >= IF_EQU)) //
(Cmd->If.Operator > IF_STRINGEQ)
+ continue;
+
if (_tcsicmp(CurrentToken, IfOperatorString[Cmd->If.Operator]) == 0)
{
if (ParseToken(0, STANDARD_SEPS) != TOK_NORMAL)