Don't print a CR, if the command line is from a batch file and starts with a '@'.
[reactos.git] / reactos / subsys / system / cmd / cmd.c
index 1c6966f..bc7c05e 100644 (file)
@@ -423,15 +423,12 @@ Execute (LPTSTR Full, LPTSTR First, LPTSTR Rest)
        /* search the PATH environment variable for the binary */
        if (!SearchForExecutable (first, szFullName))
        {
-               if (!SearchForExecutable (full, szFullName))
-               {
                        error_bad_command ();
                        free (first);
                        free (rest);
                        free (full);
                        free (szFullName);
                        return;
-               }
 
        }
 
@@ -1285,6 +1282,7 @@ ProcessInput (BOOL bFlag)
        LPCTSTR tmp;
        BOOL bEchoThisLine;
        BOOL bModeSetA;
+        BOOL bIsBatch;
 
        do
        {
@@ -1297,7 +1295,12 @@ ProcessInput (BOOL bFlag)
                        ReadCommand (readline, CMDLINE_LENGTH);
                        ip = readline;
                        bEchoThisLine = FALSE;
+                        bIsBatch = FALSE;
                }
+                else
+                {
+                        bIsBatch = TRUE;
+                }
 
                /* skip leading blanks */
                while ( _istspace(*ip) )
@@ -1406,7 +1409,7 @@ ProcessInput (BOOL bFlag)
                if (*commandline)
                {
                        ParseCommandLine (commandline);
-                       if (bEcho && !bIgnoreEcho)
+                       if (bEcho && !bIgnoreEcho && (!bIsBatch || bEchoThisLine))
                                ConOutChar ('\n');
                        bIgnoreEcho = FALSE;
                }
@@ -1552,7 +1555,7 @@ Initialize (int argc, TCHAR* argv[])
           for you can change the EnvirommentVariable for prompt before cmd start
           this patch are not 100% right, if it does not exists a PROMPT value cmd should use
           $P$G as defualt not set EnvirommentVariable PROMPT to $P$G if it does not exists */
-       if (GetEnvironmentVariable(_T("PROMPT"),lpBuffer, 2 * sizeof(TCHAR)) == 0)
+       if (GetEnvironmentVariable(_T("PROMPT"),lpBuffer, sizeof(lpBuffer) / sizeof(lpBuffer[0])) == 0)
            SetEnvironmentVariable (_T("PROMPT"), _T("$P$G"));
 
 
@@ -1619,13 +1622,14 @@ Initialize (int argc, TCHAR* argv[])
                                ++i;
                                if (i < argc)
                                {
-                                       _tcscpy (commandline, argv[i]);
+                                       _tcscpy (commandline, _T("\""));
+                                       _tcscat (commandline, argv[i]);
+                                       _tcscat (commandline, _T("\""));
                                        while (++i < argc)
                                        {
                                                _tcscat (commandline, _T(" "));
                                                _tcscat (commandline, argv[i]);
                                        }
-
                                        ParseCommandLine(commandline);
                                }
                        }
@@ -1650,24 +1654,6 @@ Initialize (int argc, TCHAR* argv[])
        {
                ParseCommandLine (_T("\\cmdstart.bat"));
        }
-#ifndef __REACTOS__
-       else
-       {
-               /* try to run cmdstart.bat from install dir */
-               LPTSTR p;
-
-               _tcscpy (commandline, argv[0]);
-               p = _tcsrchr (commandline, _T('\\')) + 1;
-               _tcscpy (p, _T("cmdstart.bat"));
-
-               if (IsExistingFile (_T("commandline")))
-               {
-                       LoadString(CMD_ModuleHandle, STRING_CMD_ERROR4, szMsg, RC_STRING_MAX_SIZE);
-                       ConErrPrintf(szMsg, commandline);
-                       ParseCommandLine (commandline);
-               }
-       }
-#endif
 
 #ifdef FEATURE_DIR_STACK
        /* initialize directory stack */
@@ -1694,10 +1680,6 @@ Initialize (int argc, TCHAR* argv[])
 
 static VOID Cleanup (int argc, TCHAR *argv[])
 {
-#ifndef __REACTOS__
-       TCHAR szMsg[RC_STRING_MAX_SIZE];
-#endif
-
        /* run cmdexit.bat */
        if (IsExistingFile (_T("cmdexit.bat")))
        {
@@ -1710,25 +1692,6 @@ static VOID Cleanup (int argc, TCHAR *argv[])
                ConErrResPuts (STRING_CMD_ERROR5);
                ParseCommandLine (_T("\\cmdexit.bat"));
        }
-#ifndef __REACTOS__
-       else
-       {
-               /* try to run cmdexit.bat from install dir */
-               TCHAR commandline[CMDLINE_LENGTH];
-               LPTSTR p;
-
-               _tcscpy (commandline, argv[0]);
-               p = _tcsrchr (commandline, _T('\\')) + 1;
-               _tcscpy (p, _T("cmdexit.bat"));
-
-               if (IsExistingFile (_T("commandline")))
-               {
-                       LoadString(CMD_ModuleHandle, STRING_CMD_ERROR4, szMsg, RC_STRING_MAX_SIZE);
-                       ConErrPrintf(szMsg, commandline);
-                       ParseCommandLine (commandline);
-               }
-       }
-#endif
 
 #ifdef FEATURE_ALIASES
        DestroyAlias ();
@@ -1759,53 +1722,6 @@ static VOID Cleanup (int argc, TCHAR *argv[])
        }
 }
 
-#ifdef __REACTOS__
-#ifdef _UNICODE
-PWCHAR * _CommandLineToArgvW(PWCHAR lpCmdLine, int *pNumArgs)
-{
-       PWCHAR * argvw = NULL;
-       PWCHAR ptr = lpCmdLine;
-       PWCHAR str;
-       int len;
-       int NumArgs;
-
-       NumArgs = 0;
-
-       while(lpCmdLine && *lpCmdLine)
-       {
-               while (iswspace(*lpCmdLine)) lpCmdLine++;
-               if (*lpCmdLine)
-               {
-                       if ((NumArgs % 10)==0)
-                       {
-                               PWCHAR * old_argvw = argvw;
-                               argvw = malloc((NumArgs + 10) * sizeof(PWCHAR));
-                               memcpy(argvw, old_argvw, NumArgs * sizeof(PWCHAR));
-                               free(old_argvw);
-                       }
-                       ptr = wcschr(lpCmdLine, L' ');
-                       if (ptr)
-                       {
-                               len = ptr - lpCmdLine;
-                       }
-                       else
-                       {
-                               len = wcslen(lpCmdLine);
-                       }
-                       str = malloc((len + 1) * sizeof(WCHAR));
-                       memcpy(str, lpCmdLine, len * sizeof(WCHAR));
-                       str[len] = 0;
-                       argvw[NumArgs]=str;
-                       NumArgs++;
-                       lpCmdLine = ptr;
-               }
-       }
-       *pNumArgs = NumArgs;
-       return argvw;
-}
-#endif
-#endif
-
 /*
  * main function
  */
@@ -1821,11 +1737,7 @@ int _main (int argc, char *argv[])
 #ifdef _UNICODE
        PWCHAR * argv;
        int argc=0;
-#ifdef __REACTOS__
-       argv = _CommandLineToArgvW(GetCommandLineW(), &argc);
-#else
        argv = CommandLineToArgvW(GetCommandLineW(), &argc);
-#endif
 #endif
 
        GetCurrentDirectory(MAX_PATH,startPath);