- Fixed the parameter check of the echo command.
authorHartmut Birr <osexpert@googlemail.com>
Tue, 22 Nov 2005 18:01:02 +0000 (18:01 +0000)
committerHartmut Birr <osexpert@googlemail.com>
Tue, 22 Nov 2005 18:01:02 +0000 (18:01 +0000)
- Remove the first space after the echo command.
- Do never check for parameters if the delimiter is a point.

svn path=/trunk/; revision=19467

reactos/subsys/system/cmd/echo.c

index 43ef1a6..0019c15 100644 (file)
 INT CommandEcho (LPTSTR cmd, LPTSTR param)
 {
        TCHAR szMsg[RC_STRING_MAX_SIZE];
-       UINT i = 0;
+        LPTSTR p1, p2;
 
 #ifdef _DEBUG
        DebugPrintf (_T("CommandEcho '%s' : '%s'\n"), cmd, param);
 #endif
 
-       if (!_tcsncmp (param, _T("/?"), 2))
-       {
-               ConOutResPaging(TRUE,STRING_ECHO_HELP4);
-               return 0;
-       }
-
-       if (_tcsicmp (cmd, _T("echo.")) == 0)
+        if (_tcsicmp (cmd, _T("echo.")) == 0)
        {
                if (param[0] == 0)
                        ConOutChar (_T('\n'));
                else
                        ConOutPuts (param);
        }
-       else
-       {
-               if (_tcsicmp (param, D_OFF) == 0)
-                       bEcho = FALSE;
-               else if (_tcsicmp (param, D_ON) == 0)
-                       bEcho = TRUE;
-               else if (*param)
+        else
+        {
+                /* skip the first delimiter */
+                if (_istspace(*param))
+                        param++;
+
+                /* skip all spaces for the check of '/?', 'ON' and 'OFF' */
+                p1 = param;
+                while(_istspace(*p1))
+                        p1++;
+
+               if (!_tcsncmp (p1, _T("/?"), 2))
+               {
+                       ConOutResPaging(TRUE,STRING_ECHO_HELP4);
+                       return 0;
+               }
+
+                if (_tcsnicmp (p1, D_OFF, sizeof(D_OFF)/sizeof(TCHAR) - 1) == 0)
+                {
+                        p2 = p1 + sizeof(D_OFF)/sizeof(TCHAR) - 1;
+                        while (_istspace(*p2))
+                                p2++;
+                        if (*p2 == _T('\0'))
+                        {
+                                bEcho = FALSE;
+                                return 0;
+                        }
+                }
+               else if (_tcsnicmp (p1, D_ON, sizeof(D_ON)/sizeof(TCHAR) - 1) == 0)
+                {
+                        p2 = p1 + sizeof(D_ON)/sizeof(TCHAR) - 1;
+                        while (_istspace(*p2))
+                                p2++;
+                        if (*p2 == _T('\0'))
+                        {
+                               bEcho = TRUE;
+                                return 0;
+                        }
+                }
+               if (*p1 != _T('\0'))
                {
-                       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++;
-                       }
+                        p1 = param;
+                        while (NULL != (p1 = _tcschr(p1, _T('^'))))
+                        {
+                                memmove(p1, p1 + 1, (_tcslen(p1 + 1) + 1) * sizeof(TCHAR));
+                                if (*p1)
+                                {
+                                       //skip past the char being escaped
+                                        p1++;
+                                }
+                        }
                        ConOutPuts (param);
                }
                else