Implement escape char in console. "^"

cmd.c - when the env isnt found, dont zero out the params
redir.c - skip over all ^ when looking for redir/pipe
echo.c - when printing out, treat ^ correctly.

svn path=/trunk/; revision=17545
This commit is contained in:
Brandon Turner 2005-08-25 20:05:07 +00:00
parent 011639b626
commit c7b88afc3f
3 changed files with 40 additions and 4 deletions

View file

@ -1077,7 +1077,6 @@ ProcessInput (BOOL bFlag)
GetCurrentDirectory (MAX_PATH, szPath); GetCurrentDirectory (MAX_PATH, szPath);
cp = _stpcpy (cp, szPath); cp = _stpcpy (cp, szPath);
} }
/* %TIME% */ /* %TIME% */
else if (_tcsicmp(ip,_T("time")) ==0) else if (_tcsicmp(ip,_T("time")) ==0)
{ {
@ -1146,8 +1145,18 @@ ProcessInput (BOOL bFlag)
evar = malloc ( 512 * sizeof(TCHAR)); evar = malloc ( 512 * sizeof(TCHAR));
if (evar==NULL) if (evar==NULL)
return 1; return 1;
SetLastError(0);
size = GetEnvironmentVariable (ip, evar, 512); size = GetEnvironmentVariable (ip, evar, 512);
if(GetLastError() == ERROR_ENVVAR_NOT_FOUND)
{
/* if no env var is found you must
continue with what was input*/
cp = _stpcpy (cp, _T("%"));
cp = _stpcpy (cp, ip);
cp = _stpcpy (cp, _T("%"));
}
else
{
if (size > 512) if (size > 512)
{ {
evar = realloc(evar,size * sizeof(TCHAR) ); evar = realloc(evar,size * sizeof(TCHAR) );
@ -1162,6 +1171,7 @@ ProcessInput (BOOL bFlag)
{ {
cp = _stpcpy (cp, evar); cp = _stpcpy (cp, evar);
} }
}
free(evar); free(evar);
} }

View file

@ -33,6 +33,7 @@
INT CommandEcho (LPTSTR cmd, LPTSTR param) INT CommandEcho (LPTSTR cmd, LPTSTR param)
{ {
TCHAR szMsg[RC_STRING_MAX_SIZE]; TCHAR szMsg[RC_STRING_MAX_SIZE];
INT i = 0;
#ifdef _DEBUG #ifdef _DEBUG
DebugPrintf (_T("CommandEcho '%s' : '%s'\n"), cmd, param); DebugPrintf (_T("CommandEcho '%s' : '%s'\n"), cmd, param);
@ -58,7 +59,20 @@ INT CommandEcho (LPTSTR cmd, LPTSTR param)
else if (_tcsicmp (param, D_ON) == 0) else if (_tcsicmp (param, D_ON) == 0)
bEcho = TRUE; bEcho = TRUE;
else if (*param) else if (*param)
{
while(i < _tcslen(param))
{
if(param[i] == _T('^'))
{
memmove(&param[i],&param[i + 1], _tcslen(&param[i]) * sizeof(TCHAR));
//skip past the char being escaped
i++;
}
else
i++;
}
ConOutPuts (param); ConOutPuts (param);
}
else else
{ {
LoadString(CMD_ModuleHandle, STRING_ECHO_HELP5, szMsg, RC_STRING_MAX_SIZE); LoadString(CMD_ModuleHandle, STRING_ECHO_HELP5, szMsg, RC_STRING_MAX_SIZE);

View file

@ -78,6 +78,12 @@ INT GetRedirection (LPTSTR s, LPTSTR ifn, LPTSTR ofn, LPTSTR efn, LPINT lpnFlags
/* find and remove all the redirections first */ /* find and remove all the redirections first */
while (*sp) while (*sp)
{ {
if (*sp == _T('^'))
{
*dp++ = *sp++;
*dp++ = *sp++;
continue;
}
if ((*sp == _T('"')) || (*sp == _T('\''))) if ((*sp == _T('"')) || (*sp == _T('\'')))
{ {
/* No redirects inside quotes */ /* No redirects inside quotes */
@ -242,7 +248,13 @@ INT GetRedirection (LPTSTR s, LPTSTR ifn, LPTSTR ofn, LPTSTR efn, LPINT lpnFlags
sp = s; sp = s;
while (*sp) while (*sp)
{ {
if ((*sp == _T('"')) || (*sp == _T('\''))) if (*sp == _T('^'))
{
*sp++;
*sp++;
continue;
}
else if ((*sp == _T('"')) || (*sp == _T('\'')))
{ {
TCHAR qc = *sp; TCHAR qc = *sp;