Implement escape char in console. "^"
authorBrandon Turner <turnerb7@msu.edu>
Thu, 25 Aug 2005 20:05:07 +0000 (20:05 +0000)
committerBrandon Turner <turnerb7@msu.edu>
Thu, 25 Aug 2005 20:05:07 +0000 (20:05 +0000)
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
reactos/subsys/system/cmd/echo.c
reactos/subsys/system/cmd/redir.c

index c2930c2..8f4446f 100644 (file)
@@ -1027,7 +1027,7 @@ ProcessInput (BOOL bFlag)
                cp = commandline;
                while (*ip)
                {
                cp = commandline;
                while (*ip)
                {
-                       if (*ip == _T('%'))
+         if (*ip == _T('%'))
                        {
                                switch (*++ip)
                                {
                        {
                                switch (*++ip)
                                {
@@ -1077,7 +1077,6 @@ ProcessInput (BOOL bFlag)
                            GetCurrentDirectory (MAX_PATH, szPath);
                 cp = _stpcpy (cp, szPath);                 
               }
                            GetCurrentDirectory (MAX_PATH, szPath);
                 cp = _stpcpy (cp, szPath);                 
               }
-
               /* %TIME% */
               else if (_tcsicmp(ip,_T("time")) ==0)
               {
               /* %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; 
                 evar = malloc ( 512 * sizeof(TCHAR));
                 if (evar==NULL) 
                     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)
                 {
                     evar = realloc(evar,size * sizeof(TCHAR) );
                 if (size > 512)
                 {
                     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);
               }
index 989a811..c4081f2 100644 (file)
@@ -33,6 +33,7 @@
 INT CommandEcho (LPTSTR cmd, LPTSTR param)
 {
        TCHAR szMsg[RC_STRING_MAX_SIZE];
 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);
 
 #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)
                else if (_tcsicmp (param, D_ON) == 0)
                        bEcho = TRUE;
                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
                {
                        LoadString(CMD_ModuleHandle, STRING_ECHO_HELP5, szMsg, RC_STRING_MAX_SIZE);
                else
                {
                        LoadString(CMD_ModuleHandle, STRING_ECHO_HELP5, szMsg, RC_STRING_MAX_SIZE);
index 0a8c66b..436297e 100644 (file)
@@ -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)
        {
        /* 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 */
                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)
        {
        sp = s;
        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;