* Replaced spawnl() by CreateProcess().
*/
-// #define WIN32_LEAN_AND_MEAN
-
#include "config.h"
#include <windows.h>
-// #include <tchar.h>
+#include <tchar.h>
#include <string.h>
#include <stdlib.h>
+#include <ctype.h>
#include "cmd.h"
#include "batch.h"
BOOL bCanExit = TRUE; /* indicates if this shell is exitable */
BOOL bCtrlBreak = FALSE; /* Ctrl-Break or Ctrl-C hit */
BOOL bIgnoreEcho = FALSE; /* Ignore 'newline' before 'cls' */
-INT errorlevel = 0; /* Errorlevel of last launched external program */
+INT nErrorLevel = 0; /* Errorlevel of last launched external program */
OSVERSIONINFO osvi;
HANDLE hIn;
HANDLE hOut;
/* get the PATH environment variable and parse it */
/* search the PATH environment variable for the binary */
- find_which (first, szFullName);
-
- if (szFullName[0] == _T('\0'))
+ if (!SearchForExecutable (first, szFullName))
{
error_bad_command ();
return;
#endif
/* build command line for CreateProcess() */
_tcscpy (szFullCmdLine, szFullName);
- _tcscat (szFullCmdLine, " ");
+ _tcscat (szFullCmdLine, _T(" "));
_tcscat (szFullCmdLine, rest);
/* fill startup info */
if (CreateProcess (NULL, szFullCmdLine, NULL, NULL, FALSE,
0, NULL, NULL, &stui, &prci))
{
+ DWORD dwExitCode;
WaitForSingleObject (prci.hProcess, INFINITE);
- GetExitCodeProcess (prci.hProcess, &errorlevel);
+ GetExitCodeProcess (prci.hProcess, &dwExitCode);
+ nErrorLevel = (INT)dwExitCode;
CloseHandle (prci.hThread);
CloseHandle (prci.hProcess);
}
cl = _tcslen (cmdptr->name);
if ((cmdptr->flags & CMD_SPECIAL) &&
- (!_tcsncmp (cmdptr->name, com, cl)) &&
- (_tcschr (_T("\\.-"), *(com + cl))))
+ (!_tcsncmp (cmdptr->name, com, cl)) &&
+ (_tcschr (_T("\\.-"), *(com + cl))))
{
/* OK its one of the specials...*/
case _T('7'):
case _T('8'):
case _T('9'):
- if (tp = FindArg (*ip - _T('0')))
+ if ((tp = FindArg (*ip - _T('0'))))
{
cp = stpcpy (cp, tp);
ip++;
break;
case _T('?'):
- cp += wsprintf (cp, _T("%u"), errorlevel);
+ cp += wsprintf (cp, _T("%u"), nErrorLevel);
ip++;
break;
default:
- if (tp = _tcschr (ip, _T('%')))
+ if ((tp = _tcschr (ip, _T('%'))))
{
char evar[512];
*tp = _T('\0');
#endif
/* get version information */
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionEx (&osvi);
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx (&osvi);
- InitLocale ();
+ InitLocale ();
/* get default input and output console handles */
hOut = GetStdHandle (STD_OUTPUT_HANDLE);
InitLastPath ();
#endif
- if (argc >= 2)
+ if (argc >= 2)
{
if (!_tcsncmp (argv[1], _T("/?"), 2))
{
ShowCommands ();
/* Set COMSPEC environment variable */
- SetEnvironmentVariable (_T("COMSPEC"), argv[0]);
+ if (argv)
+ SetEnvironmentVariable (_T("COMSPEC"), argv[0]);
/* add ctrl handler */
+#if 0
SetConsoleCtrlHandler (NULL, TRUE);
+#endif
}
#endif
/* remove ctrl handler */
-// SetConsoleCtrlHandler ((PHANDLER_ROUTINE)&BreakHandler, FALSE);
+#if 0
+ SetConsoleCtrlHandler ((PHANDLER_ROUTINE)&BreakHandler, FALSE);
+#endif
}
INT nExitCode;
AllocConsole ();
- SetFileApisToOEM ();
+#ifndef __REACTOS__
+ SetFileApisToOEM ();
+#endif
/* check switches on command-line */
Initialize (argc, argv);