Don't strip trailing spaces from the command line
[reactos.git] / reactos / base / shell / cmd / cmd.c
index f326a9d..3b310b1 100644 (file)
@@ -790,7 +790,6 @@ VOID ParseCommandLine (LPTSTR cmd)
                _tcscpy(err, bc->Err);
        }
 
-
        /* Set up the initial conditions ... */
        /* preserve STDIN, STDOUT and STDERR handles */
        hOldConIn  = GetStdHandle (STD_INPUT_HANDLE);
@@ -811,18 +810,9 @@ VOID ParseCommandLine (LPTSTR cmd)
                                    FILE_ATTRIBUTE_NORMAL, NULL);
                if (hFile == INVALID_HANDLE_VALUE)
                {
-                       if (bc)
-                       {
-                               /* will fail for windows gui apps */
-                               num = 0;
-                               bc->hBatchFile = INVALID_HANDLE_VALUE;
-                       }
-                       else
-                       {
-                               LoadString(CMD_ModuleHandle, STRING_CMD_ERROR1, szMsg, RC_STRING_MAX_SIZE);
-                               ConErrPrintf(szMsg, in);
-                               return;
-                       }
+                       LoadString(CMD_ModuleHandle, STRING_CMD_ERROR1, szMsg, RC_STRING_MAX_SIZE);
+                       ConErrPrintf(szMsg, in);
+                       return;
                }
 
                if (!SetStdHandle (STD_INPUT_HANDLE, hFile))
@@ -901,7 +891,7 @@ VOID ParseCommandLine (LPTSTR cmd)
 
        /* Now set up the end conditions... */
        /* redirect STDOUT */
-       if ((bc) && (bc->hBatchFile != INVALID_HANDLE_VALUE) && (out[0]))
+       if (out[0])
        {
                /* Final output to here */
                HANDLE hFile;
@@ -968,7 +958,7 @@ VOID ParseCommandLine (LPTSTR cmd)
        }
 
        /* redirect STDERR */
-       if ((bc) && (bc->hBatchFile != INVALID_HANDLE_VALUE) && (err[0]))
+       if (err[0])
        {
                /* Final output to here */
                HANDLE hFile;
@@ -1285,12 +1275,19 @@ GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA )
        static UINT retlen = 0;
        LPTSTR p, tmp;
        UINT size;
+       TCHAR c;
 
        if ( varNameLen )
                *varNameLen = 0;
        SetLastError(0);
-       if ( *varName++ != '%' )
+       c = *varName;
+
+       if ( (*varName != '!') && (*varName++ != '%') )
                return NULL;
+
+       if (c == _T('!'))
+               varName++;
+
        switch ( *varName )
        {
        case _T('~'):
@@ -1298,13 +1295,9 @@ GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA )
                if (_tcsncicmp(varName, _T("dp0"), 3) == 0)
                {
                        if ( varNameLen )
-                               *varNameLen = 4;
-                       varName += 2;
-                       if ( !GrowIfNecessary ( MAX_PATH, &ret, &retlen ) )
-                               return NULL;
-                       GetCurrentDirectory(MAX_PATH, ret);
+                               *varNameLen = 5;
+                       return bc->BatchFilePath;
                }
-               return ret;
        case _T('0'):
        case _T('1'):
        case _T('2'):
@@ -1391,7 +1384,7 @@ GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA )
                        *varNameLen = 1;
                return ret;
        }
-       p = _tcschr ( varName, _T('%') );
+       p = _tcschr ( varName, c );
        if ( !p )
        {
                SetLastError ( ERROR_INVALID_PARAMETER );
@@ -1451,7 +1444,7 @@ ProcessInput (BOOL bFlag)
                bModeSetA = FALSE;
                while (*ip)
                {
-                       if ( *ip == _T('%') )
+                       if ( (*ip == _T('%')) || (*ip == _T('!')) )
                        {
                                UINT envNameLen;
                                LPCTSTR envVal = GetParsedEnvVar ( ip, &envNameLen, bModeSetA );
@@ -1462,7 +1455,7 @@ ProcessInput (BOOL bFlag)
                                }
                        }
 
-                       if (_istcntrl (*ip))
+                       if (*ip != _T('\0') && (_istcntrl (*ip)))
                                *ip = _T(' ');
                        *cp++ = *ip++;
 
@@ -1536,11 +1529,6 @@ ProcessInput (BOOL bFlag)
 
                *cp = _T('\0');
 
-               /* strip trailing spaces */
-               while ((--cp >= commandline) && _istspace (*cp));
-
-               *(cp + 1) = _T('\0');
-
                /* JPP 19980807 */
                /* Echo batch file line */
                if (bEchoThisLine)
@@ -1771,10 +1759,6 @@ Initialize (int argc, const TCHAR* argv[])
        InitLastPath ();
 #endif
 
-#ifdef FATURE_ALIASES
-       InitializeAlias ();
-#endif
-
        if (argc >= 2)
        {
                for (i = 1; i < argc; i++)
@@ -1852,7 +1836,7 @@ Initialize (int argc, const TCHAR* argv[])
             _T(KERNEL_RELEASE_STR),
             _T(KERNEL_VERSION_BUILD_STR));
 
-           ConOutPuts (_T("(C) Copyright 1998-" COPYRIGHT_YEAR " ReactOS Team.\n"));
+           ConOutPuts (_T("(C) Copyright 1998-") _T(COPYRIGHT_YEAR) _T(" ReactOS Team.\n"));
     }
 
     ExecuteAutoRunFile ();
@@ -1895,10 +1879,6 @@ static VOID Cleanup (int argc, const TCHAR *argv[])
                ParseCommandLine (_T("\\cmdexit.bat"));
        }
 
-#ifdef FEATURE_ALIASES
-       DestroyAlias ();
-#endif
-
 #ifdef FEATURE_DIECTORY_STACK
        /* destroy directory stack */
        DestroyDirectoryStack ();