mirror of
https://github.com/reactos/reactos.git
synced 2025-02-22 08:25:03 +00:00
CMD: implemented IF [NOT] DEFINED variable command
CMD: fixed IF NOT EXIST file command svn path=/trunk/; revision=1628
This commit is contained in:
parent
f827a8f124
commit
349ae0c799
2 changed files with 44 additions and 4 deletions
|
@ -21,6 +21,9 @@
|
||||||
*
|
*
|
||||||
* 01-Sep-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
* 01-Sep-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
|
||||||
* Fixed help text.
|
* Fixed help text.
|
||||||
|
*
|
||||||
|
* 17-Feb-2001 (ea)
|
||||||
|
* IF DEFINED variable command
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -37,7 +40,6 @@
|
||||||
#define X_EXEC 1
|
#define X_EXEC 1
|
||||||
#define X_EMPTY 0x80
|
#define X_EMPTY 0x80
|
||||||
|
|
||||||
|
|
||||||
INT cmd_if (LPTSTR cmd, LPTSTR param)
|
INT cmd_if (LPTSTR cmd, LPTSTR param)
|
||||||
{
|
{
|
||||||
INT x_flag = 0; /* when set cause 'then' clause to be executed */
|
INT x_flag = 0; /* when set cause 'then' clause to be executed */
|
||||||
|
@ -54,6 +56,7 @@ INT cmd_if (LPTSTR cmd, LPTSTR param)
|
||||||
" IF [NOT] ERRORLEVEL number command\n"
|
" IF [NOT] ERRORLEVEL number command\n"
|
||||||
" IF [NOT] string1==string2 command\n"
|
" IF [NOT] string1==string2 command\n"
|
||||||
" IF [NOT] EXIST filename command\n"
|
" IF [NOT] EXIST filename command\n"
|
||||||
|
" IF [NOT] DEFINED variable command\n"
|
||||||
"\n"
|
"\n"
|
||||||
"NOT Specifies that CMD should carry out the command only if\n"
|
"NOT Specifies that CMD should carry out the command only if\n"
|
||||||
" the condition is false\n"
|
" the condition is false\n"
|
||||||
|
@ -62,7 +65,9 @@ INT cmd_if (LPTSTR cmd, LPTSTR param)
|
||||||
"command Specifies the command to carry out if the condition is met.\n"
|
"command Specifies the command to carry out if the condition is met.\n"
|
||||||
"string1==string2 Specifies a true condition if the specified text strings\n"
|
"string1==string2 Specifies a true condition if the specified text strings\n"
|
||||||
" match.\n"
|
" match.\n"
|
||||||
"EXIST filename Specifies a true condition if the specified filename exists."));
|
"EXIST filename Specifies a true condition if the specified filename exists.\n"
|
||||||
|
"DEFINED variable Specifies a true condition if the specified variable is\n"
|
||||||
|
" defined."));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,9 +98,42 @@ INT cmd_if (LPTSTR cmd, LPTSTR param)
|
||||||
|
|
||||||
*pp++ = _T('\0');
|
*pp++ = _T('\0');
|
||||||
hFind = FindFirstFile (param, &f);
|
hFind = FindFirstFile (param, &f);
|
||||||
x_flag ^= (hFind != INVALID_HANDLE_VALUE) ? 0 : X_EXEC;
|
x_flag ^= (hFind == INVALID_HANDLE_VALUE) ? 0 : X_EXEC;
|
||||||
if (hFind != INVALID_HANDLE_VALUE)
|
if (hFind != INVALID_HANDLE_VALUE)
|
||||||
|
{
|
||||||
FindClose (hFind);
|
FindClose (hFind);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check for 'defined' form */
|
||||||
|
else if (!_tcsnicmp (param, _T("defined"), 7) && _istspace (*(param + 7)))
|
||||||
|
{
|
||||||
|
TCHAR Value [1];
|
||||||
|
INT ValueSize = 0;
|
||||||
|
|
||||||
|
param += 7;
|
||||||
|
/* IF [NOT] DEFINED var COMMAND */
|
||||||
|
/* ^ */
|
||||||
|
while (_istspace (*param))
|
||||||
|
param++;
|
||||||
|
/* IF [NOT] DEFINED var COMMAND */
|
||||||
|
/* ^ */
|
||||||
|
pp = param;
|
||||||
|
while (*pp && !_istspace (*pp))
|
||||||
|
pp++;
|
||||||
|
/* IF [NOT] DEFINED var COMMAND */
|
||||||
|
/* ^ */
|
||||||
|
if (*pp)
|
||||||
|
{
|
||||||
|
*pp++ = _T('\0');
|
||||||
|
ValueSize = GetEnvironmentVariable(param, Value, sizeof Value);
|
||||||
|
x_flag ^= (0 == ValueSize)
|
||||||
|
? 0
|
||||||
|
: X_EXEC;
|
||||||
|
x_flag |= X_EMPTY;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -166,7 +204,9 @@ INT cmd_if (LPTSTR cmd, LPTSTR param)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x_flag & X_EXEC)
|
if (x_flag & X_EXEC)
|
||||||
|
{
|
||||||
ParseCommandLine (pp);
|
ParseCommandLine (pp);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ INT cmd_ver (LPTSTR cmd, LPTSTR param)
|
||||||
SHELLVER "\n"
|
SHELLVER "\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Copyright (C) 1994-1998 Tim Norman and others."));
|
"Copyright (C) 1994-1998 Tim Norman and others."));
|
||||||
ConOutPuts (_T("Copyright (C) 1998-2000 Eric Kohl and others."));
|
ConOutPuts (_T("Copyright (C) 1998-2001 Eric Kohl and others."));
|
||||||
|
|
||||||
/* Basic copyright notice */
|
/* Basic copyright notice */
|
||||||
if (param[0] == _T('\0'))
|
if (param[0] == _T('\0'))
|
||||||
|
|
Loading…
Reference in a new issue