From c7b88afc3f8d7ec55ab5d6fc76e13bc29d1406d6 Mon Sep 17 00:00:00 2001 From: Brandon Turner Date: Thu, 25 Aug 2005 20:05:07 +0000 Subject: [PATCH] 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 --- reactos/subsys/system/cmd/cmd.c | 16 +++++++++++++--- reactos/subsys/system/cmd/echo.c | 14 ++++++++++++++ reactos/subsys/system/cmd/redir.c | 14 +++++++++++++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/reactos/subsys/system/cmd/cmd.c b/reactos/subsys/system/cmd/cmd.c index c2930c22339..8f4446ff166 100644 --- a/reactos/subsys/system/cmd/cmd.c +++ b/reactos/subsys/system/cmd/cmd.c @@ -1027,7 +1027,7 @@ ProcessInput (BOOL bFlag) cp = commandline; while (*ip) { - if (*ip == _T('%')) + if (*ip == _T('%')) { switch (*++ip) { @@ -1077,7 +1077,6 @@ ProcessInput (BOOL bFlag) GetCurrentDirectory (MAX_PATH, szPath); cp = _stpcpy (cp, szPath); } - /* %TIME% */ else if (_tcsicmp(ip,_T("time")) ==0) { @@ -1146,8 +1145,18 @@ ProcessInput (BOOL bFlag) evar = malloc ( 512 * sizeof(TCHAR)); if (evar==NULL) return 1; - + SetLastError(0); 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) { evar = realloc(evar,size * sizeof(TCHAR) ); @@ -1162,6 +1171,7 @@ ProcessInput (BOOL bFlag) { cp = _stpcpy (cp, evar); } + } free(evar); } diff --git a/reactos/subsys/system/cmd/echo.c b/reactos/subsys/system/cmd/echo.c index 989a8110640..c4081f27cde 100644 --- a/reactos/subsys/system/cmd/echo.c +++ b/reactos/subsys/system/cmd/echo.c @@ -33,6 +33,7 @@ INT CommandEcho (LPTSTR cmd, LPTSTR param) { TCHAR szMsg[RC_STRING_MAX_SIZE]; + INT i = 0; #ifdef _DEBUG 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) bEcho = TRUE; else if (*param) + { + while(i < _tcslen(param)) + { + if(param[i] == _T('^')) + { + memmove(¶m[i],¶m[i + 1], _tcslen(¶m[i]) * sizeof(TCHAR)); + //skip past the char being escaped + i++; + } + else + i++; + } ConOutPuts (param); + } else { LoadString(CMD_ModuleHandle, STRING_ECHO_HELP5, szMsg, RC_STRING_MAX_SIZE); diff --git a/reactos/subsys/system/cmd/redir.c b/reactos/subsys/system/cmd/redir.c index 0a8c66b5afc..436297e825d 100644 --- a/reactos/subsys/system/cmd/redir.c +++ b/reactos/subsys/system/cmd/redir.c @@ -78,6 +78,12 @@ INT GetRedirection (LPTSTR s, LPTSTR ifn, LPTSTR ofn, LPTSTR efn, LPINT lpnFlags /* find and remove all the redirections first */ while (*sp) { + if (*sp == _T('^')) + { + *dp++ = *sp++; + *dp++ = *sp++; + continue; + } if ((*sp == _T('"')) || (*sp == _T('\''))) { /* No redirects inside quotes */ @@ -242,7 +248,13 @@ INT GetRedirection (LPTSTR s, LPTSTR ifn, LPTSTR ofn, LPTSTR efn, LPINT lpnFlags sp = s; while (*sp) { - if ((*sp == _T('"')) || (*sp == _T('\''))) + if (*sp == _T('^')) + { + *sp++; + *sp++; + continue; + } + else if ((*sp == _T('"')) || (*sp == _T('\''))) { TCHAR qc = *sp;