mirror of
https://github.com/reactos/reactos.git
synced 2025-04-26 16:40:27 +00:00
[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.
This commit is contained in:
parent
80844dc185
commit
fedc68aea8
4 changed files with 48 additions and 19 deletions
|
@ -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% */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue