Author: cwittich
Date: Sun Jan 20 17:29:18 2008
New Revision: 31903
URL:
http://svn.reactos.org/svn/reactos?rev=31903&view=rev
Log:
support blocks ( ... )
support parsing of env vars like %TIMERAW:~0,2%
there is still room for improvement...
Modified:
trunk/reactos/base/shell/cmd/batch.c
trunk/reactos/base/shell/cmd/batch.h
trunk/reactos/base/shell/cmd/cmd.c
trunk/reactos/base/shell/cmd/if.c
Modified: trunk/reactos/base/shell/cmd/batch.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/batch.c?rev…
==============================================================================
--- trunk/reactos/base/shell/cmd/batch.c (original)
+++ trunk/reactos/base/shell/cmd/batch.c Sun Jan 20 17:29:18 2008
@@ -272,6 +272,7 @@
SetFilePointer (bc->hBatchFile, 0, NULL, FILE_BEGIN);
bc->bEcho = bEcho; /* Preserve echo across batch calls */
bc->shiftlevel = 0;
+ bc->bCmdBlock = FALSE;
bc->ffind = NULL;
bc->forvar = _T('\0');
@@ -453,6 +454,18 @@
*++ip = _T('\0');
+ /* cmd block over multiple lines (..) */
+ if (bc->bCmdBlock)
+ {
+ if (*first == _T(')'))
+ {
+ bc->bCmdBlock = FALSE;
+ continue;
+ }
+ if (!bc->bExecuteBlock)
+ continue;
+ }
+
/* ignore labels and empty lines */
if (*first == _T(':') || *first == 0)
continue;
Modified: trunk/reactos/base/shell/cmd/batch.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/batch.h?rev…
==============================================================================
--- trunk/reactos/base/shell/cmd/batch.h (original)
+++ trunk/reactos/base/shell/cmd/batch.h Sun Jan 20 17:29:18 2008
@@ -23,6 +23,8 @@
TCHAR Out[MAX_PATH];
TCHAR Err[MAX_PATH];
TCHAR forvar;
+ BOOL bCmdBlock;
+ BOOL bExecuteBlock;
} BATCH_CONTEXT, *LPBATCH_CONTEXT;
Modified: trunk/reactos/base/shell/cmd/cmd.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.c?rev=3…
==============================================================================
--- trunk/reactos/base/shell/cmd/cmd.c (original)
+++ trunk/reactos/base/shell/cmd/cmd.c Sun Jan 20 17:29:18 2008
@@ -1140,20 +1140,49 @@
static LPTSTR ret = NULL;
static UINT retlen = 0;
UINT size;
-
- size = GetEnvironmentVariable ( varName, ret, retlen );
+ TCHAR varNameFixed[MAX_PATH];
+ TCHAR ReturnValue[MAX_PATH];
+ LPTSTR position;
+ LPTSTR Token;
+ SIZE_T i = 0;
+ INT StringPart[1] = {0};
+
+ position = _tcsstr(varName, _T(":~"));
+ if (position)
+ _tcsncpy(varNameFixed, varName, (int) (position - varName));
+ else
+ _tcscpy(varNameFixed, varName);
+
+ size = GetEnvironmentVariable ( varNameFixed, ret, retlen );
if ( size > retlen )
{
if ( !GrowIfNecessary ( size, &ret, &retlen ) )
return NULL;
- size = GetEnvironmentVariable ( varName, ret, retlen );
+ size = GetEnvironmentVariable ( varNameFixed, ret, retlen );
}
if ( size )
- return ret;
+ {
+ if (position)
+ {
+ position += 2;
+ Token = _tcstok(position, _T(","));
+ while ((Token != NULL) && (i < 2))
+ {
+ StringPart[i] = _ttoi(Token);
+ i++;
+ Token = _tcstok (NULL, _T(","));
+ }
+ _tcsncpy(ReturnValue, ret + (1 - StringPart[0]), StringPart[1]);
+ _tcscpy(ret, ReturnValue);
+ return ret;
+ }
+ else
+ return ret;
+ }
/* env var doesn't exist, look for a "special" one */
/* %CD% */
- if (_tcsicmp(varName,_T("cd")) ==0)
+ if (_tcsicmp(varNameFixed,_T("cd")) ==0)
{
size = GetCurrentDirectory ( retlen, ret );
if ( size > retlen )
@@ -1167,7 +1196,7 @@
return ret;
}
/* %TIME% */
- else if (_tcsicmp(varName,_T("time")) ==0)
+ else if (_tcsicmp(varNameFixed,_T("time")) ==0)
{
SYSTEMTIME t;
if ( !GrowIfNecessary ( MAX_PATH, &ret, &retlen ) )
@@ -1179,7 +1208,7 @@
return ret;
}
/* %DATE% */
- else if (_tcsicmp(varName,_T("date")) ==0)
+ else if (_tcsicmp(varNameFixed,_T("date")) ==0)
{
if ( !GrowIfNecessary ( GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL,
NULL, 0), &ret, &retlen ) )
@@ -1193,7 +1222,7 @@
}
/* %RANDOM% */
- else if (_tcsicmp(varName,_T("random")) ==0)
+ else if (_tcsicmp(varNameFixed,_T("random")) ==0)
{
if ( !GrowIfNecessary ( MAX_PATH, &ret, &retlen ) )
return NULL;
@@ -1203,13 +1232,13 @@
}
/* %CMDCMDLINE% */
- else if (_tcsicmp(varName,_T("cmdcmdline")) ==0)
+ else if (_tcsicmp(varNameFixed,_T("cmdcmdline")) ==0)
{
return GetCommandLine();
}
/* %CMDEXTVERSION% */
- else if (_tcsicmp(varName,_T("cmdextversion")) ==0)
+ else if (_tcsicmp(varNameFixed,_T("cmdextversion")) ==0)
{
if ( !GrowIfNecessary ( MAX_PATH, &ret, &retlen ) )
return NULL;
@@ -1219,7 +1248,7 @@
}
/* %ERRORLEVEL% */
- else if (_tcsicmp(varName,_T("errorlevel")) ==0)
+ else if (_tcsicmp(varNameFixed,_T("errorlevel")) ==0)
{
if ( !GrowIfNecessary ( MAX_PATH, &ret, &retlen ) )
return NULL;
@@ -1227,8 +1256,8 @@
return ret;
}
- GrowIfNecessary(_tcslen(varName) + 3, &ret, &retlen);
- _stprintf(ret,_T("%%%s%%"),varName);
+ GrowIfNecessary(_tcslen(varNameFixed) + 3, &ret, &retlen);
+ _stprintf(ret,_T("%%%s%%"),varNameFixed);
return ret; /* not found - return orginal string */
}
Modified: trunk/reactos/base/shell/cmd/if.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/if.c?rev=31…
==============================================================================
--- trunk/reactos/base/shell/cmd/if.c (original)
+++ trunk/reactos/base/shell/cmd/if.c Sun Jan 20 17:29:18 2008
@@ -181,6 +181,18 @@
x_flag ^= X_EXEC;
pp += p1len;
+ while (_istspace (*pp)) /* skip spaces */
+ pp++;
+
+ if (*pp == _T('('))
+ {
+ if (bc)
+ {
+ bc->bCmdBlock = TRUE;
+ bc->bExecuteBlock = x_flag & X_EXEC;
+ }
+ }
+
if ( x_flag )
{
x_flag |= X_EMPTY;