mirror of
https://github.com/reactos/reactos.git
synced 2025-04-28 17:38:11 +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% */
|
/* %CMDEXTVERSION% */
|
||||||
else if (_tcsicmp(varName, _T("CMDEXTVERSION")) == 0)
|
else if (_tcsicmp(varName, _T("CMDEXTVERSION")) == 0)
|
||||||
{
|
{
|
||||||
/* Set version number to 2 */
|
/* Set version number to CMDEXTVERSION */
|
||||||
_itot(2, ret, 10);
|
_itot(CMDEXTVERSION, ret, 10);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
/* %ERRORLEVEL% */
|
/* %ERRORLEVEL% */
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
#include "cmdver.h"
|
#include "cmdver.h"
|
||||||
#include "cmddbg.h"
|
#include "cmddbg.h"
|
||||||
|
|
||||||
|
/* Version of the Command Extensions */
|
||||||
|
#define CMDEXTVERSION 2
|
||||||
|
|
||||||
#define BREAK_BATCHFILE 1
|
#define BREAK_BATCHFILE 1
|
||||||
#define BREAK_OUTOFBATCH 2 /* aka. BREAK_ENDOFBATCHFILES */
|
#define BREAK_OUTOFBATCH 2 /* aka. BREAK_ENDOFBATCHFILES */
|
||||||
#define BREAK_INPUT 3
|
#define BREAK_INPUT 3
|
||||||
|
@ -233,10 +236,20 @@ INT CommandHistory(LPTSTR param);
|
||||||
|
|
||||||
/* Prototypes for IF.C */
|
/* Prototypes for IF.C */
|
||||||
#define IFFLAG_NEGATE 1 /* NOT */
|
#define IFFLAG_NEGATE 1 /* NOT */
|
||||||
#define IFFLAG_IGNORECASE 2 /* /I */
|
#define IFFLAG_IGNORECASE 2 /* /I - Extended */
|
||||||
enum { IF_CMDEXTVERSION, IF_DEFINED, IF_ERRORLEVEL, IF_EXIST,
|
enum {
|
||||||
|
/** Unary operators **/
|
||||||
|
/* Standard */
|
||||||
|
IF_ERRORLEVEL, IF_EXIST,
|
||||||
|
/* Extended */
|
||||||
|
IF_CMDEXTVERSION, IF_DEFINED,
|
||||||
|
|
||||||
|
/** Binary operators **/
|
||||||
|
/* Standard */
|
||||||
IF_STRINGEQ, /* == */
|
IF_STRINGEQ, /* == */
|
||||||
IF_EQU, IF_GTR, IF_GEQ, IF_LSS, IF_LEQ, IF_NEQ };
|
/* Extended */
|
||||||
|
IF_EQU, IF_NEQ, IF_LSS, IF_LEQ, IF_GTR, IF_GEQ
|
||||||
|
};
|
||||||
INT ExecuteIf(struct _PARSED_COMMAND *Cmd);
|
INT ExecuteIf(struct _PARSED_COMMAND *Cmd);
|
||||||
|
|
||||||
/* Prototypes for INTERNAL.C */
|
/* Prototypes for INTERNAL.C */
|
||||||
|
|
|
@ -82,7 +82,7 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Cmd->If.Operator == IF_CMDEXTVERSION)
|
if (bEnableExtensions && (Cmd->If.Operator == IF_CMDEXTVERSION))
|
||||||
{
|
{
|
||||||
/* IF CMDEXTVERSION n: check if Command Extensions version
|
/* IF CMDEXTVERSION n: check if Command Extensions version
|
||||||
* is greater or equal to n */
|
* is greater or equal to n */
|
||||||
|
@ -93,9 +93,9 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
|
||||||
cmd_free(Right);
|
cmd_free(Right);
|
||||||
return 1;
|
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 */
|
/* IF DEFINED var: check if environment variable exists */
|
||||||
result = (GetEnvVarOrSpecial(Right) != NULL);
|
result = (GetEnvVarOrSpecial(Right) != NULL);
|
||||||
|
@ -167,7 +167,7 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
|
||||||
/* IF str1 == str2 */
|
/* IF str1 == str2 */
|
||||||
result = (StringCmp(Left, Right) == 0);
|
result = (StringCmp(Left, Right) == 0);
|
||||||
}
|
}
|
||||||
else
|
else if (bEnableExtensions)
|
||||||
{
|
{
|
||||||
result = GenericCmp(StringCmp, Left, Right);
|
result = GenericCmp(StringCmp, Left, Right);
|
||||||
switch (Cmd->If.Operator)
|
switch (Cmd->If.Operator)
|
||||||
|
|
|
@ -24,19 +24,26 @@ static const TCHAR RedirString[][3] = { _T("<"), _T(">"), _T(">>") };
|
||||||
|
|
||||||
static const TCHAR *const IfOperatorString[] =
|
static const TCHAR *const IfOperatorString[] =
|
||||||
{
|
{
|
||||||
_T("cmdextversion"),
|
/* Standard */
|
||||||
_T("defined"),
|
|
||||||
_T("errorlevel"),
|
_T("errorlevel"),
|
||||||
_T("exist"),
|
_T("exist"),
|
||||||
#define IF_MAX_UNARY IF_EXIST
|
|
||||||
|
/* Extended */
|
||||||
|
_T("cmdextversion"),
|
||||||
|
_T("defined"),
|
||||||
|
#define IF_MAX_UNARY IF_DEFINED
|
||||||
|
|
||||||
|
/* Standard */
|
||||||
_T("=="),
|
_T("=="),
|
||||||
|
|
||||||
|
/* Extended */
|
||||||
_T("equ"),
|
_T("equ"),
|
||||||
_T("gtr"),
|
_T("neq"),
|
||||||
_T("geq"),
|
|
||||||
_T("lss"),
|
_T("lss"),
|
||||||
_T("leq"),
|
_T("leq"),
|
||||||
_T("neq"),
|
_T("gtr"),
|
||||||
#define IF_MAX_COMPARISON IF_NEQ
|
_T("geq"),
|
||||||
|
#define IF_MAX_COMPARISON IF_GEQ
|
||||||
};
|
};
|
||||||
|
|
||||||
static BOOL IsSeparator(TCHAR Char)
|
static BOOL IsSeparator(TCHAR Char)
|
||||||
|
@ -389,7 +396,7 @@ static PARSED_COMMAND *ParseIf(void)
|
||||||
memset(Cmd, 0, sizeof(PARSED_COMMAND));
|
memset(Cmd, 0, sizeof(PARSED_COMMAND));
|
||||||
Cmd->Type = C_IF;
|
Cmd->Type = C_IF;
|
||||||
|
|
||||||
if (_tcsicmp(CurrentToken, _T("/I")) == 0)
|
if (bEnableExtensions && (_tcsicmp(CurrentToken, _T("/I")) == 0))
|
||||||
{
|
{
|
||||||
Cmd->If.Flags |= IFFLAG_IGNORECASE;
|
Cmd->If.Flags |= IFFLAG_IGNORECASE;
|
||||||
ParseToken(0, STANDARD_SEPS);
|
ParseToken(0, STANDARD_SEPS);
|
||||||
|
@ -406,6 +413,10 @@ static PARSED_COMMAND *ParseIf(void)
|
||||||
/* Check for unary operators */
|
/* Check for unary operators */
|
||||||
for (; Cmd->If.Operator <= IF_MAX_UNARY; Cmd->If.Operator++)
|
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 (_tcsicmp(CurrentToken, IfOperatorString[Cmd->If.Operator]) == 0)
|
||||||
{
|
{
|
||||||
if (ParseToken(0, STANDARD_SEPS) != TOK_NORMAL)
|
if (ParseToken(0, STANDARD_SEPS) != TOK_NORMAL)
|
||||||
|
@ -427,8 +438,13 @@ static PARSED_COMMAND *ParseIf(void)
|
||||||
goto condition_done;
|
goto condition_done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cmd->If.Operator == IF_MAX_UNARY + 1;
|
||||||
for (; Cmd->If.Operator <= IF_MAX_COMPARISON; Cmd->If.Operator++)
|
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 (_tcsicmp(CurrentToken, IfOperatorString[Cmd->If.Operator]) == 0)
|
||||||
{
|
{
|
||||||
if (ParseToken(0, STANDARD_SEPS) != TOK_NORMAL)
|
if (ParseToken(0, STANDARD_SEPS) != TOK_NORMAL)
|
||||||
|
|
Loading…
Reference in a new issue