2 * CMD.C - command-line interface.
7 * 17 Jun 1994 (Tim Norman)
10 * 08 Aug 1995 (Matt Rains)
11 * I have cleaned up the source code. changes now bring this source
12 * into guidelines for recommended programming practice.
14 * A added the the standard FreeDOS GNU licence test to the
15 * initialize() function.
17 * Started to replace puts() with printf(). this will help
18 * standardize output. please follow my lead.
20 * I have added some constants to help making changes easier.
22 * 15 Dec 1995 (Tim Norman)
23 * major rewrite of the code to make it more efficient and add
24 * redirection support (finally!)
26 * 06 Jan 1996 (Tim Norman)
27 * finished adding redirection support! Changed to use our own
28 * exec code (MUCH thanks to Svante Frey!!)
30 * 29 Jan 1996 (Tim Norman)
31 * added support for CHDIR, RMDIR, MKDIR, and ERASE, as per
32 * suggestion of Steffan Kaiser
34 * changed "file not found" error message to "bad command or
35 * filename" thanks to Dustin Norman for noticing that confusing
38 * changed the format to call internal commands (again) so that if
39 * they want to split their commands, they can do it themselves
40 * (none of the internal functions so far need that much power, anyway)
42 * 27 Aug 1996 (Tim Norman)
43 * added in support for Oliver Mueller's ALIAS command
45 * 14 Jun 1997 (Steffan Kaiser)
46 * added ctrl-break handling and error level
48 * 16 Jun 1998 (Rob Lake)
49 * Runs command.com if /P is specified in command line. Command.com
50 * also stays permanent. If /C is in the command line, starts the
51 * program next in the line.
53 * 21 Jun 1998 (Rob Lake)
54 * Fixed up /C so that arguments for the program
56 * 08-Jul-1998 (John P. Price)
57 * Now sets COMSPEC environment variable
58 * misc clean up and optimization
59 * added date and time commands
60 * changed to using spawnl instead of exec. exec does not copy the
61 * environment to the child process!
63 * 14 Jul 1998 (Hans B Pufal)
64 * Reorganised source to be more efficient and to more closely
65 * follow MS-DOS conventions. (eg %..% environment variable
66 * replacement works form command line as well as batch file.
68 * New organisation also properly support nested batch files.
70 * New command table structure is half way towards providing a
71 * system in which COMMAND will find out what internal commands
74 * 24 Jul 1998 (Hans B Pufal) [HBP_003]
75 * Fixed return value when called with /C option
77 * 27 Jul 1998 John P. Price
78 * added config.h include
80 * 28 Jul 1998 John P. Price
81 * added showcmds function to show commands and options available
83 * 07-Aug-1998 (John P Price <linux-guru@gcfl.net>)
84 * Fixed carrage return output to better match MSDOS with echo
85 * on or off. (marked with "JPP 19980708")
87 * 07-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
88 * First ReactOS release.
89 * Extended length of commandline buffers to 512.
91 * 13-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
92 * Added COMSPEC environment variable.
93 * Added "/t" support (color) on cmd command line.
95 * 07-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
96 * Added help text ("cmd /?").
98 * 25-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
99 * Unicode and redirection safe!
100 * Fixed redirections and piping.
101 * Piping is based on temporary files, but basic support
102 * for anonymous pipes already exists.
104 * 27-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
105 * Replaced spawnl() by CreateProcess().
107 * 22-Oct-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
108 * Added break handler.
110 * 15-Dec-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
111 * Fixed current directory
113 * 28-Dec-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
114 * Restore window title after program/batch execution
116 * 03-Feb-2001 (Eric Kohl <ekohl@rz-online.de>)
117 * Workaround because argc[0] is NULL under ReactOS
119 * 23-Feb-2001 (Carl Nettelblad <cnettel@hem.passagen.se>)
120 * %envvar% replacement conflicted with for.
122 * 30-Apr-2004 (Filip Navara <xnavara@volny.cz>)
123 * Make MakeSureDirectoryPathExistsEx unicode safe.
125 * 28-Mai-2004 (Hartmut Birr)
126 * Removed MakeSureDirectoryPathExistsEx.
127 * Use the current directory if GetTempPath fails.
129 * 12-Jul-2004 (Jens Collin <jens.collin@lakhei.com>)
130 * Added ShellExecute call when all else fails to be able to "launch" any file.
132 * 02-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
133 * Remove all hardcode string to En.rc
135 * 06-May-2005 (Klemens Friedl <frik85@gmail.com>)
136 * Add 'help' command (list all commands plus description)
138 * 06-jul-2005 (Magnus Olsen <magnus@greatlord.com>)
139 * translate '%errorlevel%' to the internal value.
140 * Add proper memmory alloc ProcessInput, the error
141 * handling for memmory handling need to be improve
146 #include "resource.h"
149 #define NT_SUCCESS(StatCode) ((NTSTATUS)(StatCode) >= 0)
152 typedef NTSTATUS (WINAPI
*NtQueryInformationProcessProc
)(HANDLE
, PROCESSINFOCLASS
,
153 PVOID
, ULONG
, PULONG
);
154 typedef NTSTATUS (WINAPI
*NtReadVirtualMemoryProc
)(HANDLE
, PVOID
, PVOID
, ULONG
, PULONG
);
156 BOOL bExit
= FALSE
; /* indicates EXIT was typed */
157 BOOL bCanExit
= TRUE
; /* indicates if this shell is exitable */
158 BOOL bCtrlBreak
= FALSE
; /* Ctrl-Break or Ctrl-C hit */
159 BOOL bIgnoreEcho
= FALSE
; /* Ignore 'newline' before 'cls' */
160 INT nErrorLevel
= 0; /* Errorlevel of last launched external program */
161 BOOL bChildProcessRunning
= FALSE
;
162 DWORD dwChildProcessId
= 0;
167 HANDLE CMD_ModuleHandle
;
170 static NtQueryInformationProcessProc NtQueryInformationProcessPtr
= NULL
;
171 static NtReadVirtualMemoryProc NtReadVirtualMemoryPtr
= NULL
;
173 #ifdef INCLUDE_CMD_COLOR
174 WORD wColor
; /* current color */
175 WORD wDefColor
; /* default color */
181 * insert commas into a number
184 ConvertULargeInteger (ULARGE_INTEGER num
, LPTSTR des
, INT len
, BOOL bPutSeperator
)
190 if (num
.QuadPart
== 0)
199 while (num
.QuadPart
> 0)
201 if ((((c
+ 1) % (nNumberGroups
+ 1)) == 0) && (bPutSeperator
))
202 temp
[30 - c
++] = cThousandSeparator
;
203 temp
[30 - c
++] = (TCHAR
)(num
.QuadPart
% 10) + _T('0');
207 for (n
= 0; n
<= c
; n
++)
208 des
[n
] = temp
[31 - c
+ n
];
215 * is character a delimeter when used on first word?
218 static BOOL
IsDelimiter (TCHAR c
)
220 return (c
== _T('/') || c
== _T('=') || c
== _T('\0') || _istspace (c
));
224 * Is a process a console process?
226 static BOOL
IsConsoleProcess(HANDLE Process
)
229 PROCESS_BASIC_INFORMATION Info
;
233 if (NULL
== NtQueryInformationProcessPtr
|| NULL
== NtReadVirtualMemoryPtr
)
238 Status
= NtQueryInformationProcessPtr (
239 Process
, ProcessBasicInformation
,
240 &Info
, sizeof(PROCESS_BASIC_INFORMATION
), NULL
);
241 if (! NT_SUCCESS(Status
))
244 DebugPrintf (_T("NtQueryInformationProcess failed with status %08x\n"), Status
);
248 Status
= NtReadVirtualMemoryPtr (
249 Process
, Info
.PebBaseAddress
, &ProcessPeb
,
250 sizeof(PEB
), &BytesRead
);
251 if (! NT_SUCCESS(Status
) || sizeof(PEB
) != BytesRead
)
254 DebugPrintf (_T("Couldn't read virt mem status %08x bytes read %lu\n"), Status
, BytesRead
);
259 return IMAGE_SUBSYSTEM_WINDOWS_CUI
== ProcessPeb
.ImageSubSystem
;
265 #define SHELLEXECUTETEXT "ShellExecuteW"
267 #define SHELLEXECUTETEXT "ShellExecuteA"
270 typedef HINSTANCE (WINAPI
*MYEX
)(
274 LPCTSTR lpParameters
,
281 static BOOL
RunFile(LPTSTR filename
)
288 DebugPrintf (_T("RunFile(%s)\n"), filename
);
290 hShell32
= LoadLibrary(_T("SHELL32.DLL"));
294 DebugPrintf (_T("RunFile: couldn't load SHELL32.DLL!\n"));
299 hShExt
= (MYEX
)(FARPROC
)GetProcAddress(hShell32
, SHELLEXECUTETEXT
);
303 DebugPrintf (_T("RunFile: couldn't find ShellExecuteA/W in SHELL32.DLL!\n"));
305 FreeLibrary(hShell32
);
310 DebugPrintf (_T("RunFile: ShellExecuteA/W is at %x\n"), hShExt
);
313 ret
= (hShExt
)(NULL
, _T("open"), filename
, NULL
, NULL
, SW_SHOWNORMAL
);
316 DebugPrintf (_T("RunFile: ShellExecuteA/W returned %d\n"), (DWORD
)ret
);
319 FreeLibrary(hShell32
);
320 return (((DWORD
)ret
) > 32);
326 * This command (in first) was not found in the command table
328 * Full - whole command line
329 * First - first word on command line
330 * Rest - rest of command line
334 Execute (LPTSTR Full
, LPTSTR First
, LPTSTR Rest
)
336 TCHAR
*szFullName
=NULL
;
341 TCHAR szWindowTitle
[MAX_PATH
];
342 DWORD dwExitCode
= 0;
345 DebugPrintf (_T("Execute: \'%s\' \'%s\'\n"), first
, rest
);
348 /* we need biger buffer that First, Rest, Full are already
349 need rewrite some code to use realloc when it need instead
350 of add 512bytes extra */
352 first
= malloc ( (_tcslen(First
) + 512) * sizeof(TCHAR
));
355 error_out_of_memory();
360 rest
= malloc ( (_tcslen(Rest
) + 512) * sizeof(TCHAR
));
364 error_out_of_memory();
369 full
= malloc ( (_tcslen(Full
) + 512) * sizeof(TCHAR
));
374 error_out_of_memory();
379 szFullName
= malloc ( (_tcslen(Full
) + 512) * sizeof(TCHAR
));
385 error_out_of_memory();
391 /* Though it was already parsed once, we have a different set of rules
392 for parsing before we pass to CreateProccess */
393 if(!_tcschr(Full
,_T('\"')))
395 _tcscpy(first
,First
);
402 BOOL bInside
= FALSE
;
407 /* find the end of the command and start of the args */
408 for(i
= 0; i
< _tcslen(first
); i
++)
410 if(!_tcsncmp(&first
[i
], _T("\""), 1))
412 if(!_tcsncmp(&first
[i
], _T(" "), 1) && !bInside
)
414 _tcscpy(rest
,&first
[i
]);
421 /* remove any slashes */
422 while(i
< _tcslen(first
))
424 if(first
[i
] == _T('\"'))
425 memmove(&first
[i
],&first
[i
+ 1], _tcslen(&first
[i
]) * sizeof(TCHAR
));
429 /* Drop quotes around it just in case there is a space */
430 _tcscpy(full
,_T("\""));
432 _tcscat(full
,_T("\" "));
436 /* check for a drive change */
437 if ((_istalpha (first
[0])) && (!_tcscmp (first
+ 1, _T(":"))))
440 if (!SetCurrentDirectory(first
))
441 /* Guess they changed disc or something, handle that gracefully and get to root */
448 working
= SetCurrentDirectory(str
);
451 if (!working
) ConErrResPuts (STRING_FREE_ERROR1
);
461 /* get the PATH environment variable and parse it */
462 /* search the PATH environment variable for the binary */
463 if (!SearchForExecutable (first
, szFullName
))
465 error_bad_command ();
475 GetConsoleTitle (szWindowTitle
, MAX_PATH
);
477 /* check if this is a .BAT or .CMD file */
478 dot
= _tcsrchr (szFullName
, _T('.'));
479 if (dot
&& (!_tcsicmp (dot
, _T(".bat")) || !_tcsicmp (dot
, _T(".cmd"))))
482 DebugPrintf (_T("[BATCH: %s %s]\n"), szFullName
, rest
);
484 Batch (szFullName
, first
, rest
);
488 /* exec the program */
489 PROCESS_INFORMATION prci
;
493 DebugPrintf (_T("[EXEC: %s %s]\n"), full
, rest
);
495 /* build command line for CreateProcess() */
497 /* fill startup info */
498 memset (&stui
, 0, sizeof (STARTUPINFO
));
499 stui
.cb
= sizeof (STARTUPINFO
);
500 stui
.dwFlags
= STARTF_USESHOWWINDOW
;
501 stui
.wShowWindow
= SW_SHOWDEFAULT
;
503 // return console to standard mode
504 SetConsoleMode (GetStdHandle(STD_INPUT_HANDLE
),
505 ENABLE_LINE_INPUT
| ENABLE_PROCESSED_INPUT
| ENABLE_ECHO_INPUT
);
507 if (CreateProcess (szFullName
,
512 0, /* CREATE_NEW_PROCESS_GROUP */
519 if (IsConsoleProcess(prci
.hProcess
))
521 /* FIXME: Protect this with critical section */
522 bChildProcessRunning
= TRUE
;
523 dwChildProcessId
= prci
.dwProcessId
;
525 WaitForSingleObject (prci
.hProcess
, INFINITE
);
527 /* FIXME: Protect this with critical section */
528 bChildProcessRunning
= FALSE
;
530 GetExitCodeProcess (prci
.hProcess
, &dwExitCode
);
531 nErrorLevel
= (INT
)dwExitCode
;
537 CloseHandle (prci
.hThread
);
538 CloseHandle (prci
.hProcess
);
543 DebugPrintf (_T("[ShellExecute: %s]\n"), full
);
545 // See if we can run this with ShellExecute() ie myfile.xls
549 DebugPrintf (_T("[ShellExecute failed!: %s]\n"), full
);
551 error_bad_command ();
559 // restore console mode
561 GetStdHandle( STD_INPUT_HANDLE
),
562 ENABLE_PROCESSED_INPUT
);
565 /* Get code page if it has been change */
566 InputCodePage
= GetConsoleCP();
567 OutputCodePage
= GetConsoleOutputCP();
568 SetConsoleTitle (szWindowTitle
);
578 * look through the internal commands and determine whether or not this
579 * command is one of them. If it is, call the command. If not, call
580 * execute to run it as an external program.
582 * line - the command line of the program to run
587 DoCommand (LPTSTR line
)
589 TCHAR
*com
= NULL
; /* the first word in the command */
592 LPTSTR rest
; /* pointer to the rest of the command line */
597 DebugPrintf (_T("DoCommand: (\'%s\')\n"), line
);
600 com
= malloc( (_tcslen(line
) +512)*sizeof(TCHAR
) );
603 error_out_of_memory();
608 /* Skip over initial white space */
609 while (_istspace (*line
))
615 /* Anything to do ? */
618 if (*rest
== _T('"'))
620 /* treat quoted words specially */
624 while(*rest
!= _T('\0') && *rest
!= _T('"'))
625 *cp
++ = _totlower (*rest
++);
626 if (*rest
== _T('"'))
631 while (!IsDelimiter (*rest
))
632 *cp
++ = _totlower (*rest
++);
636 /* Terminate first word */
639 /* Do not limit commands to MAX_PATH */
641 if(_tcslen(com) > MAX_PATH)
649 /* Skip over whitespace to rest of line, exclude 'echo' command */
650 if (_tcsicmp (com
, _T("echo")))
652 while (_istspace (*rest
))
656 /* Scan internal command table */
657 for (cmdptr
= cmds
;; cmdptr
++)
659 /* If end of table execute ext cmd */
660 if (cmdptr
->name
== NULL
)
662 Execute (line
, com
, rest
);
666 if (!_tcscmp (com
, cmdptr
->name
))
668 cmdptr
->func (com
, rest
);
672 /* The following code handles the case of commands like CD which
673 * are recognised even when the command name and parameter are
674 * not space separated.
680 /* Get length of command name */
681 cl
= _tcslen (cmdptr
->name
);
683 if ((cmdptr
->flags
& CMD_SPECIAL
) &&
684 (!_tcsncmp (cmdptr
->name
, com
, cl
)) &&
685 (_tcschr (_T("\\.-"), *(com
+ cl
))))
687 /* OK its one of the specials...*/
689 /* Terminate first word properly */
692 /* Call with new rest */
693 cmdptr
->func (com
, cstart
+ cl
);
703 * process the command line and execute the appropriate functions
704 * full input/output redirection and piping are supported
707 VOID
ParseCommandLine (LPTSTR cmd
)
709 TCHAR szMsg
[RC_STRING_MAX_SIZE
];
710 TCHAR cmdline
[CMDLINE_LENGTH
];
712 #ifdef FEATURE_REDIRECTION
713 TCHAR in
[CMDLINE_LENGTH
] = _T("");
714 TCHAR out
[CMDLINE_LENGTH
] = _T("");
715 TCHAR err
[CMDLINE_LENGTH
] = _T("");
716 TCHAR szTempPath
[MAX_PATH
] = _T(".\\");
717 TCHAR szFileName
[2][MAX_PATH
] = {_T(""), _T("")};
718 HANDLE hFile
[2] = {INVALID_HANDLE_VALUE
, INVALID_HANDLE_VALUE
};
724 BOOL bNewBatch
= TRUE
;
728 #endif /* FEATURE_REDIRECTION */
730 _tcscpy (cmdline
, cmd
);
734 DebugPrintf (_T("ParseCommandLine: (\'%s\')\n"), s
);
737 #ifdef FEATURE_ALIASES
738 /* expand all aliases */
739 ExpandAlias (s
, CMDLINE_LENGTH
);
740 #endif /* FEATURE_ALIAS */
742 #ifdef FEATURE_REDIRECTION
743 /* find the temp path to store temporary files */
744 Length
= GetTempPath (MAX_PATH
, szTempPath
);
745 if (Length
> 0 && Length
< MAX_PATH
)
747 Attributes
= GetFileAttributes(szTempPath
);
748 if (Attributes
== 0xffffffff ||
749 !(Attributes
& FILE_ATTRIBUTE_DIRECTORY
))
754 if (Length
== 0 || Length
>= MAX_PATH
)
756 _tcscpy(szTempPath
, _T(".\\"));
758 if (szTempPath
[_tcslen (szTempPath
) - 1] != _T('\\'))
759 _tcscat (szTempPath
, _T("\\"));
761 /* get the redirections from the command line */
762 num
= GetRedirection (s
, in
, out
, err
, &nRedirFlags
);
764 /* more efficient, but do we really need to do this? */
765 for (t
= in
; _istspace (*t
); t
++)
769 for (t
= out
; _istspace (*t
); t
++)
773 for (t
= err
; _istspace (*t
); t
++)
777 if(bc
&& !_tcslen (in
) && _tcslen (bc
->In
))
779 if(bc
&& !out
[0] && _tcslen(bc
->Out
))
781 nRedirFlags
|= OUTPUT_APPEND
;
782 _tcscpy(out
, bc
->Out
);
784 if(bc
&& !_tcslen (err
) && _tcslen (bc
->Err
))
786 nRedirFlags
|= ERROR_APPEND
;
787 _tcscpy(err
, bc
->Err
);
791 /* Set up the initial conditions ... */
792 /* preserve STDIN, STDOUT and STDERR handles */
793 hOldConIn
= GetStdHandle (STD_INPUT_HANDLE
);
794 hOldConOut
= GetStdHandle (STD_OUTPUT_HANDLE
);
795 hOldConErr
= GetStdHandle (STD_ERROR_HANDLE
);
801 SECURITY_ATTRIBUTES sa
= {sizeof(SECURITY_ATTRIBUTES
), NULL
, TRUE
};
803 /* we need make sure the LastError msg is zero before calling CreateFile */
806 /* Set up pipe for the standard input handler */
807 hFile
= CreateFile (in
, GENERIC_READ
, FILE_SHARE_READ
, &sa
, OPEN_EXISTING
,
808 FILE_ATTRIBUTE_NORMAL
, NULL
);
809 if (hFile
== INVALID_HANDLE_VALUE
)
811 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR1
, szMsg
, RC_STRING_MAX_SIZE
);
812 ConErrPrintf(szMsg
, in
);
816 if (!SetStdHandle (STD_INPUT_HANDLE
, hFile
))
818 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR1
, szMsg
, RC_STRING_MAX_SIZE
);
819 ConErrPrintf(szMsg
, in
);
823 DebugPrintf (_T("Input redirected from: %s\n"), in
);
827 /* Now do all but the last pipe command */
828 *szFileName
[0] = _T('\0');
829 hFile
[0] = INVALID_HANDLE_VALUE
;
833 SECURITY_ATTRIBUTES sa
= {sizeof(SECURITY_ATTRIBUTES
), NULL
, TRUE
};
835 /* Create unique temporary file name */
836 GetTempFileName (szTempPath
, _T("CMD"), 0, szFileName
[1]);
838 /* we need make sure the LastError msg is zero before calling CreateFile */
841 /* Set current stdout to temporary file */
842 hFile
[1] = CreateFile (szFileName
[1], GENERIC_WRITE
, 0, &sa
,
843 TRUNCATE_EXISTING
, FILE_ATTRIBUTE_TEMPORARY
, NULL
);
845 if (hFile
[1] == INVALID_HANDLE_VALUE
)
847 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR2
, szMsg
, RC_STRING_MAX_SIZE
);
852 SetStdHandle (STD_OUTPUT_HANDLE
, hFile
[1]);
856 /* close stdout file */
857 SetStdHandle (STD_OUTPUT_HANDLE
, hOldConOut
);
858 if ((hFile
[1] != INVALID_HANDLE_VALUE
) && (hFile
[1] != hOldConOut
))
860 CloseHandle (hFile
[1]);
861 hFile
[1] = INVALID_HANDLE_VALUE
;
864 /* close old stdin file */
865 SetStdHandle (STD_INPUT_HANDLE
, hOldConIn
);
866 if ((hFile
[0] != INVALID_HANDLE_VALUE
) && (hFile
[0] != hOldConIn
))
868 /* delete old stdin file, if it is a real file */
869 CloseHandle (hFile
[0]);
870 hFile
[0] = INVALID_HANDLE_VALUE
;
871 DeleteFile (szFileName
[0]);
872 *szFileName
[0] = _T('\0');
875 /* copy stdout file name to stdin file name */
876 _tcscpy (szFileName
[0], szFileName
[1]);
877 *szFileName
[1] = _T('\0');
879 /* we need make sure the LastError msg is zero before calling CreateFile */
882 /* open new stdin file */
883 hFile
[0] = CreateFile (szFileName
[0], GENERIC_READ
, 0, &sa
,
884 OPEN_EXISTING
, FILE_ATTRIBUTE_TEMPORARY
, NULL
);
885 SetStdHandle (STD_INPUT_HANDLE
, hFile
[0]);
887 s
= s
+ _tcslen (s
) + 1;
890 /* Now set up the end conditions... */
891 /* redirect STDOUT */
894 /* Final output to here */
896 SECURITY_ATTRIBUTES sa
= {sizeof(SECURITY_ATTRIBUTES
), NULL
, TRUE
};
898 /* we need make sure the LastError msg is zero before calling CreateFile */
901 hFile
= CreateFile (out
, GENERIC_WRITE
, FILE_SHARE_WRITE
| FILE_SHARE_READ
| FILE_SHARE_DELETE
, &sa
,
902 (nRedirFlags
& OUTPUT_APPEND
) ? OPEN_ALWAYS
: CREATE_ALWAYS
,
903 FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_WRITE_THROUGH
, NULL
);
905 if (hFile
== INVALID_HANDLE_VALUE
)
907 INT size
= _tcslen(out
)-1;
909 if (out
[size
] != _T(':'))
911 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR3
, szMsg
, RC_STRING_MAX_SIZE
);
912 ConErrPrintf(szMsg
, out
);
917 hFile
= CreateFile (out
, GENERIC_WRITE
, FILE_SHARE_WRITE
| FILE_SHARE_READ
| FILE_SHARE_DELETE
, &sa
,
918 (nRedirFlags
& OUTPUT_APPEND
) ? OPEN_ALWAYS
: CREATE_ALWAYS
,
919 FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_WRITE_THROUGH
, NULL
);
921 if (hFile
== INVALID_HANDLE_VALUE
)
923 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR3
, szMsg
, RC_STRING_MAX_SIZE
);
924 ConErrPrintf(szMsg
, out
);
930 if (!SetStdHandle (STD_OUTPUT_HANDLE
, hFile
))
932 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR3
, szMsg
, RC_STRING_MAX_SIZE
);
933 ConErrPrintf(szMsg
, out
);
937 if (nRedirFlags
& OUTPUT_APPEND
)
941 if (GetFileType (hFile
) == FILE_TYPE_DISK
)
942 SetFilePointer (hFile
, 0, &lHighPos
, FILE_END
);
945 DebugPrintf (_T("Output redirected to: %s\n"), out
);
948 else if (hOldConOut
!= INVALID_HANDLE_VALUE
)
950 /* Restore original stdout */
951 HANDLE hOut
= GetStdHandle (STD_OUTPUT_HANDLE
);
952 SetStdHandle (STD_OUTPUT_HANDLE
, hOldConOut
);
953 if (hOldConOut
!= hOut
)
955 hOldConOut
= INVALID_HANDLE_VALUE
;
958 /* redirect STDERR */
961 /* Final output to here */
963 SECURITY_ATTRIBUTES sa
= {sizeof(SECURITY_ATTRIBUTES
), NULL
, TRUE
};
965 if (!_tcscmp (err
, out
))
968 DebugPrintf (_T("Stdout and stderr will use the same file!!\n"));
970 DuplicateHandle (GetCurrentProcess (),
971 GetStdHandle (STD_OUTPUT_HANDLE
),
972 GetCurrentProcess (),
973 &hFile
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
977 hFile
= CreateFile (err
,
979 FILE_SHARE_WRITE
| FILE_SHARE_READ
| FILE_SHARE_DELETE
,
981 (nRedirFlags
& ERROR_APPEND
) ? OPEN_ALWAYS
: CREATE_ALWAYS
,
982 FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_WRITE_THROUGH
,
984 if (hFile
== INVALID_HANDLE_VALUE
)
986 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR3
, szMsg
, RC_STRING_MAX_SIZE
);
987 ConErrPrintf(szMsg
, err
);
992 if (!SetStdHandle (STD_ERROR_HANDLE
, hFile
))
994 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR3
, szMsg
, RC_STRING_MAX_SIZE
);
995 ConErrPrintf(szMsg
, err
);
999 if (nRedirFlags
& ERROR_APPEND
)
1003 if (GetFileType (hFile
) == FILE_TYPE_DISK
)
1004 SetFilePointer (hFile
, 0, &lHighPos
, FILE_END
);
1007 DebugPrintf (_T("Error redirected to: %s\n"), err
);
1010 else if (hOldConErr
!= INVALID_HANDLE_VALUE
)
1012 /* Restore original stderr */
1013 HANDLE hErr
= GetStdHandle (STD_ERROR_HANDLE
);
1014 SetStdHandle (STD_ERROR_HANDLE
, hOldConErr
);
1015 if (hOldConErr
!= hErr
)
1017 hOldConErr
= INVALID_HANDLE_VALUE
;
1024 /* process final command */
1027 #ifdef FEATURE_REDIRECTION
1029 AddBatchRedirection(in
, out
, err
);
1030 /* close old stdin file */
1031 #if 0 /* buggy implementation */
1032 SetStdHandle (STD_INPUT_HANDLE
, hOldConIn
);
1033 if ((hFile
[0] != INVALID_HANDLE_VALUE
) &&
1034 (hFile
[0] != hOldConIn
))
1036 /* delete old stdin file, if it is a real file */
1037 CloseHandle (hFile
[0]);
1038 hFile
[0] = INVALID_HANDLE_VALUE
;
1039 DeleteFile (szFileName
[0]);
1040 *szFileName
[0] = _T('\0');
1043 /* Restore original STDIN */
1044 if (hOldConIn
!= INVALID_HANDLE_VALUE
)
1046 HANDLE hIn
= GetStdHandle (STD_INPUT_HANDLE
);
1047 SetStdHandle (STD_INPUT_HANDLE
, hOldConIn
);
1048 if (hOldConIn
!= hIn
)
1050 hOldConIn
= INVALID_HANDLE_VALUE
;
1055 DebugPrintf (_T("Can't restore STDIN! Is invalid!!\n"), out
);
1058 #endif /* buggy implementation */
1061 if (hOldConIn
!= INVALID_HANDLE_VALUE
)
1063 HANDLE hIn
= GetStdHandle (STD_INPUT_HANDLE
);
1064 SetStdHandle (STD_INPUT_HANDLE
, hOldConIn
);
1065 if (hIn
== INVALID_HANDLE_VALUE
)
1068 DebugPrintf (_T("Previous STDIN is invalid!!\n"));
1073 if (GetFileType (hIn
) == FILE_TYPE_DISK
)
1075 if (hFile
[0] == hIn
)
1077 CloseHandle (hFile
[0]);
1078 hFile
[0] = INVALID_HANDLE_VALUE
;
1079 DeleteFile (szFileName
[0]);
1080 *szFileName
[0] = _T('\0');
1085 DebugPrintf (_T("hFile[0] and hIn dont match!!!\n"));
1093 /* Restore original STDOUT */
1094 if (hOldConOut
!= INVALID_HANDLE_VALUE
)
1096 HANDLE hOut
= GetStdHandle (STD_OUTPUT_HANDLE
);
1097 SetStdHandle (STD_OUTPUT_HANDLE
, hOldConOut
);
1098 if (hOldConOut
!= hOut
)
1100 hOldConOut
= INVALID_HANDLE_VALUE
;
1103 /* Restore original STDERR */
1104 if (hOldConErr
!= INVALID_HANDLE_VALUE
)
1106 HANDLE hErr
= GetStdHandle (STD_ERROR_HANDLE
);
1107 SetStdHandle (STD_ERROR_HANDLE
, hOldConErr
);
1108 if (hOldConErr
!= hErr
)
1110 hOldConErr
= INVALID_HANDLE_VALUE
;
1112 #endif /* FEATURE_REDIRECTION */
1116 GrowIfNecessary ( UINT needed
, LPTSTR
* ret
, UINT
* retlen
)
1118 if ( *ret
&& needed
< *retlen
)
1123 *ret
= (LPTSTR
)malloc ( *retlen
* sizeof(TCHAR
) );
1125 SetLastError ( ERROR_OUTOFMEMORY
);
1126 return *ret
!= NULL
;
1130 GetEnvVarOrSpecial ( LPCTSTR varName
)
1132 static LPTSTR ret
= NULL
;
1133 static UINT retlen
= 0;
1136 size
= GetEnvironmentVariable ( varName
, ret
, retlen
);
1137 if ( size
> retlen
)
1139 if ( !GrowIfNecessary ( size
, &ret
, &retlen
) )
1141 size
= GetEnvironmentVariable ( varName
, ret
, retlen
);
1146 /* env var doesn't exist, look for a "special" one */
1148 if (_tcsicmp(varName
,_T("cd")) ==0)
1150 size
= GetCurrentDirectory ( retlen
, ret
);
1151 if ( size
> retlen
)
1153 if ( !GrowIfNecessary ( size
, &ret
, &retlen
) )
1155 size
= GetCurrentDirectory ( retlen
, ret
);
1162 else if (_tcsicmp(varName
,_T("time")) ==0)
1165 if ( !GrowIfNecessary ( MAX_PATH
, &ret
, &retlen
) )
1168 _sntprintf ( ret
, retlen
, _T("%02d%c%02d%c%02d%c%02d"),
1169 t
.wHour
, cTimeSeparator
, t
.wMinute
, cTimeSeparator
,
1170 t
.wSecond
, cDecimalSeparator
, t
.wMilliseconds
);
1174 else if (_tcsicmp(varName
,_T("date")) ==0)
1178 if ( !GrowIfNecessary ( MAX_PATH
, &ret
, &retlen
) )
1180 size
= GetDateFormat(LOCALE_USER_DEFAULT
, 0, NULL
, _T("ddd"), ret
, retlen
);
1181 /* TODO FIXME - test whether GetDateFormat() can return a value indicating the buffer wasn't big enough */
1184 tmp
= ret
+ _tcslen(ret
);
1186 size
= GetDateFormat(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, NULL
, NULL
, tmp
, retlen
-(tmp
-ret
));
1187 /* TODO FIXME - test whether GetDateFormat() can return a value indicating the buffer wasn't big enough */
1194 else if (_tcsicmp(varName
,_T("random")) ==0)
1196 if ( !GrowIfNecessary ( MAX_PATH
, &ret
, &retlen
) )
1198 /* Get random number */
1199 _itot(rand(),ret
,10);
1204 else if (_tcsicmp(varName
,_T("cmdcmdline")) ==0)
1206 return GetCommandLine();
1209 /* %CMDEXTVERSION% */
1210 else if (_tcsicmp(varName
,_T("cmdextversion")) ==0)
1212 if ( !GrowIfNecessary ( MAX_PATH
, &ret
, &retlen
) )
1214 /* Set version number to 2 */
1220 else if (_tcsicmp(varName
,_T("errorlevel")) ==0)
1222 if ( !GrowIfNecessary ( MAX_PATH
, &ret
, &retlen
) )
1224 _itot(nErrorLevel
,ret
,10);
1228 GrowIfNecessary(_tcslen(varName
) + 2, &ret
, &retlen
);
1229 _stprintf(ret
,_T("%%%s%%"),varName
);
1230 return ret
; /* not found - return orginal string */
1234 GetParsedEnvVar ( LPCTSTR varName
, UINT
* varNameLen
, BOOL ModeSetA
)
1236 static LPTSTR ret
= NULL
;
1237 static UINT retlen
= 0;
1244 if ( *varName
++ != '%' )
1258 if ((tmp
= FindArg (*varName
- _T('0'))))
1264 if ( !GrowIfNecessary ( _tcslen(tmp
)+1, &ret
, &retlen
) )
1266 _tcscpy ( ret
, tmp
);
1269 if ( !GrowIfNecessary ( 3, &ret
, &retlen
) )
1279 if ( !GrowIfNecessary ( 2, &ret
, &retlen
) )
1288 /* TODO FIXME 10 is only max size for 32-bit */
1289 if ( !GrowIfNecessary ( 11, &ret
, &retlen
) )
1291 _sntprintf ( ret
, retlen
, _T("%u"), nErrorLevel
);
1299 /* HACK for set/a */
1300 if ( !GrowIfNecessary ( 2, &ret
, &retlen
) )
1308 p
= _tcschr ( varName
, _T('%') );
1311 SetLastError ( ERROR_INVALID_PARAMETER
);
1316 *varNameLen
= size
+ 2;
1317 p
= alloca ( (size
+1) * sizeof(TCHAR
) );
1318 memmove ( p
, varName
, size
* sizeof(TCHAR
) );
1321 return GetEnvVarOrSpecial ( varName
);
1326 * do the prompt/input/process loop
1331 ProcessInput (BOOL bFlag
)
1333 TCHAR commandline
[CMDLINE_LENGTH
];
1334 TCHAR readline
[CMDLINE_LENGTH
];
1344 /* if no batch input then... */
1345 if (!(ip
= ReadBatchLine (&bEchoThisLine
)))
1350 ReadCommand (readline
, CMDLINE_LENGTH
);
1352 bEchoThisLine
= FALSE
;
1360 /* skip leading blanks */
1361 while ( _istspace(*ip
) )
1368 if ( *ip
== _T('%') )
1371 LPCTSTR envVal
= GetParsedEnvVar ( ip
, &envNameLen
, bModeSetA
);
1375 cp
= _stpcpy ( cp
, envVal
);
1379 if (_istcntrl (*ip
))
1383 /* HACK HACK HACK check whether bModeSetA needs to be toggled */
1386 tmp
+= _tcsspn(tmp
,_T(" \t"));
1387 /* first we find and skip and pre-redirections... */
1388 while ( _tcschr(_T("<>"),*tmp
)
1389 || !_tcsncmp(tmp
,_T("1>"),2)
1390 || !_tcsncmp(tmp
,_T("2>"),2) )
1392 if ( _istdigit(*tmp
) )
1396 tmp
+= _tcsspn(tmp
,_T(" \t"));
1397 if ( *tmp
== _T('\"') )
1399 tmp
= _tcschr(tmp
+1,_T('\"'));
1404 tmp
= _tcspbrk(tmp
,_T(" \t"));
1405 tmp
+= _tcsspn(tmp
,_T(" \t"));
1407 /* we should now be pointing to the actual command
1408 * (if there is one yet)*/
1411 /* if we're currently substituting ( which is default )
1412 * check to see if we've parsed out a set/a. if so, we
1413 * need to disable substitution until we come across a
1417 /* look for set /a */
1418 if ( !_tcsnicmp(tmp
,_T("set"),3) )
1421 tmp
+= _tcsspn(tmp
,_T(" \t"));
1422 if ( !_tcsnicmp(tmp
,_T("/a"),2) )
1426 /* if we're not currently substituting, it means we're
1427 * already inside a set /a. now we need to look for
1428 * a redirection in order to turn redirection back on */
1431 /* look for redirector of some kind after the command */
1432 while ( (tmp
= _tcspbrk ( tmp
, _T("^<>|") )) )
1434 if ( *tmp
== _T('^') )
1436 if ( _tcschr(_T("<>|&"), *++tmp
) && *tmp
)
1451 /* strip trailing spaces */
1452 while ((--cp
>= commandline
) && _istspace (*cp
));
1454 *(cp
+ 1) = _T('\0');
1457 /* Echo batch file line */
1461 ConOutPuts (commandline
);
1464 if (!CheckCtrlBreak(BREAK_INPUT
) && *commandline
)
1466 ParseCommandLine (commandline
);
1467 if (bEcho
&& !bIgnoreEcho
&& (!bIsBatch
|| bEchoThisLine
))
1469 bIgnoreEcho
= FALSE
;
1472 while (!bCanExit
|| !bExit
);
1479 * control-break handler.
1481 BOOL WINAPI
BreakHandler (DWORD dwCtrlType
)
1486 static BOOL SelfGenerated
= FALSE
;
1488 if ((dwCtrlType
!= CTRL_C_EVENT
) &&
1489 (dwCtrlType
!= CTRL_BREAK_EVENT
))
1497 SelfGenerated
= FALSE
;
1502 if (bChildProcessRunning
== TRUE
)
1504 SelfGenerated
= TRUE
;
1505 GenerateConsoleCtrlEvent (dwCtrlType
, 0);
1510 rec
.EventType
= KEY_EVENT
;
1511 rec
.Event
.KeyEvent
.bKeyDown
= TRUE
;
1512 rec
.Event
.KeyEvent
.wRepeatCount
= 1;
1513 rec
.Event
.KeyEvent
.wVirtualKeyCode
= _T('C');
1514 rec
.Event
.KeyEvent
.wVirtualScanCode
= _T('C') - 35;
1515 rec
.Event
.KeyEvent
.uChar
.AsciiChar
= _T('C');
1516 rec
.Event
.KeyEvent
.uChar
.UnicodeChar
= _T('C');
1517 rec
.Event
.KeyEvent
.dwControlKeyState
= RIGHT_CTRL_PRESSED
;
1526 /* FIXME: Handle batch files */
1528 //ConOutPrintf(_T("^C"));
1535 VOID
AddBreakHandler (VOID
)
1537 SetConsoleCtrlHandler ((PHANDLER_ROUTINE
)BreakHandler
, TRUE
);
1541 VOID
RemoveBreakHandler (VOID
)
1543 SetConsoleCtrlHandler ((PHANDLER_ROUTINE
)BreakHandler
, FALSE
);
1548 * show commands and options that are available.
1555 /* print command list */
1556 ConOutResPuts(STRING_CMD_HELP1
);
1559 /* print feature list */
1560 ConOutResPuts(STRING_CMD_HELP2
);
1562 #ifdef FEATURE_ALIASES
1563 ConOutResPuts(STRING_CMD_HELP3
);
1565 #ifdef FEATURE_HISTORY
1566 ConOutResPuts(STRING_CMD_HELP4
);
1568 #ifdef FEATURE_UNIX_FILENAME_COMPLETION
1569 ConOutResPuts(STRING_CMD_HELP5
);
1571 #ifdef FEATURE_DIRECTORY_STACK
1572 ConOutResPuts(STRING_CMD_HELP6
);
1574 #ifdef FEATURE_REDIRECTION
1575 ConOutResPuts(STRING_CMD_HELP7
);
1577 ConOutChar(_T('\n'));
1582 * set up global initializations and process parameters
1584 * argc - number of parameters to command.com
1585 * argv - command-line parameters
1589 Initialize (int argc
, TCHAR
* argv
[])
1591 TCHAR commandline
[CMDLINE_LENGTH
];
1592 TCHAR ModuleName
[_MAX_PATH
+ 1];
1597 //TCHAR *ptr, *cmdLine;
1599 /* get version information */
1600 osvi
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
1601 GetVersionEx (&osvi
);
1603 /* Some people like to run ReactOS cmd.exe on Win98, it helps in the
1604 * build process. So don't link implicitly against ntdll.dll, load it
1605 * dynamically instead */
1607 if (osvi
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
1609 /* ntdll is always present on NT */
1610 NtDllModule
= GetModuleHandle(TEXT("ntdll.dll"));
1614 /* not all 9x versions have a ntdll.dll, try to load it */
1615 NtDllModule
= LoadLibrary(TEXT("ntdll.dll"));
1618 if (NtDllModule
!= NULL
)
1620 NtQueryInformationProcessPtr
= (NtQueryInformationProcessProc
)GetProcAddress(NtDllModule
, "NtQueryInformationProcess");
1621 NtReadVirtualMemoryPtr
= (NtReadVirtualMemoryProc
)GetProcAddress(NtDllModule
, "NtReadVirtualMemory");
1626 DebugPrintf (_T("[command args:\n"));
1627 for (i
= 0; i
< argc
; i
++)
1629 DebugPrintf (_T("%d. %s\n"), i
, argv
[i
]);
1631 DebugPrintf (_T("]\n"));
1636 /* get default input and output console handles */
1637 hOut
= GetStdHandle (STD_OUTPUT_HANDLE
);
1638 hIn
= GetStdHandle (STD_INPUT_HANDLE
);
1640 /* Set EnvironmentVariable PROMPT if it does not exists any env value.
1641 for you can change the EnvirommentVariable for prompt before cmd start
1642 this patch are not 100% right, if it does not exists a PROMPT value cmd should use
1643 $P$G as defualt not set EnvirommentVariable PROMPT to $P$G if it does not exists */
1644 if (GetEnvironmentVariable(_T("PROMPT"),lpBuffer
, sizeof(lpBuffer
) / sizeof(lpBuffer
[0])) == 0)
1645 SetEnvironmentVariable (_T("PROMPT"), _T("$P$G"));
1648 if (argc
>= 2 && !_tcsncmp (argv
[1], _T("/?"), 2))
1650 ConOutResPaging(TRUE
,STRING_CMD_HELP8
);
1653 SetConsoleMode (hIn
, ENABLE_PROCESSED_INPUT
);
1655 #ifdef INCLUDE_CMD_CHDIR
1659 #ifdef FATURE_ALIASES
1665 for (i
= 1; i
< argc
; i
++)
1667 if (!_tcsicmp (argv
[i
], _T("/p")))
1669 if (!IsExistingFile (_T("\\autoexec.bat")))
1671 #ifdef INCLUDE_CMD_DATE
1672 cmd_date (_T(""), _T(""));
1674 #ifdef INCLUDE_CMD_TIME
1675 cmd_time (_T(""), _T(""));
1680 ParseCommandLine (_T("\\autoexec.bat"));
1684 else if (!_tcsicmp (argv
[i
], _T("/c")))
1686 /* This just runs a program and exits */
1690 _tcscpy (commandline
, argv
[i
]);
1693 _tcscat (commandline
, _T(" "));
1694 _tcscat (commandline
, argv
[i
]);
1697 ParseCommandLine(commandline
);
1698 ExitProcess (ProcessInput (TRUE
));
1705 else if (!_tcsicmp (argv
[i
], _T("/k")))
1707 /* This just runs a program and remains */
1711 _tcscpy (commandline
, _T("\""));
1712 _tcscat (commandline
, argv
[i
]);
1713 _tcscat (commandline
, _T("\""));
1716 _tcscat (commandline
, _T(" "));
1717 _tcscat (commandline
, argv
[i
]);
1719 ParseCommandLine(commandline
);
1722 #ifdef INCLUDE_CMD_COLOR
1723 else if (!_tcsnicmp (argv
[i
], _T("/t:"), 3))
1725 /* process /t (color) argument */
1726 wDefColor
= (WORD
)_tcstoul (&argv
[i
][3], NULL
, 16);
1728 SetScreenColor (wColor
, TRUE
);
1734 /* run cmdstart.bat */
1735 if (IsExistingFile (_T("cmdstart.bat")))
1737 ParseCommandLine (_T("cmdstart.bat"));
1739 else if (IsExistingFile (_T("\\cmdstart.bat")))
1741 ParseCommandLine (_T("\\cmdstart.bat"));
1744 #ifdef FEATURE_DIR_STACK
1745 /* initialize directory stack */
1746 InitDirectoryStack ();
1750 #ifdef FEATURE_HISTORY
1751 /*initialize history*/
1755 /* Set COMSPEC environment variable */
1756 if (0 != GetModuleFileName (NULL
, ModuleName
, _MAX_PATH
+ 1))
1758 ModuleName
[_MAX_PATH
] = _T('\0');
1759 SetEnvironmentVariable (_T("COMSPEC"), ModuleName
);
1762 /* add ctrl break handler */
1767 static VOID
Cleanup (int argc
, TCHAR
*argv
[])
1769 /* run cmdexit.bat */
1770 if (IsExistingFile (_T("cmdexit.bat")))
1772 ConErrResPuts(STRING_CMD_ERROR5
);
1774 ParseCommandLine (_T("cmdexit.bat"));
1776 else if (IsExistingFile (_T("\\cmdexit.bat")))
1778 ConErrResPuts (STRING_CMD_ERROR5
);
1779 ParseCommandLine (_T("\\cmdexit.bat"));
1782 #ifdef FEATURE_ALIASES
1786 #ifdef FEATURE_DIECTORY_STACK
1787 /* destroy directory stack */
1788 DestroyDirectoryStack ();
1791 #ifdef INCLUDE_CMD_CHDIR
1795 #ifdef FEATURE_HISTORY
1800 /* remove ctrl break handler */
1801 RemoveBreakHandler ();
1802 SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE
),
1803 ENABLE_LINE_INPUT
| ENABLE_PROCESSED_INPUT
| ENABLE_ECHO_INPUT
);
1805 if (NtDllModule
!= NULL
)
1807 FreeLibrary(NtDllModule
);
1817 int _main (int argc
, char *argv
[])
1820 TCHAR startPath
[MAX_PATH
];
1821 CONSOLE_SCREEN_BUFFER_INFO Info
;
1826 argv
= CommandLineToArgvW(GetCommandLineW(), &argc
);
1829 GetCurrentDirectory(MAX_PATH
,startPath
);
1836 hConsole
= CreateFile(_T("CONOUT$"), GENERIC_READ
|GENERIC_WRITE
,
1837 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
,
1838 OPEN_EXISTING
, 0, NULL
);
1839 if (GetConsoleScreenBufferInfo(hConsole
, &Info
) == FALSE
)
1841 ConErrFormatMessage(GetLastError());
1844 wColor
= Info
.wAttributes
;
1847 InputCodePage
= GetConsoleCP();
1848 OutputCodePage
= GetConsoleOutputCP();
1849 CMD_ModuleHandle
= GetModuleHandle(NULL
);
1851 /* check switches on command-line */
1852 Initialize(argc
, argv
);
1854 /* call prompt routine */
1855 nExitCode
= ProcessInput(FALSE
);
1857 /* do the cleanup */
1858 Cleanup(argc
, argv
);