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.
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
)
193 if (num
.QuadPart
== 0)
202 while (num
.QuadPart
> 0)
204 if ((((c
+ 1) % (nNumberGroups
+ 1)) == 0) && (bPutSeperator
))
205 temp
[30 - c
++] = cThousandSeparator
;
206 temp
[30 - c
++] = (TCHAR
)(num
.QuadPart
% 10) + _T('0');
212 for (n
= 0; n
<= c
; n
++)
213 des
[n
] = temp
[31 - c
+ n
];
220 * is character a delimeter when used on first word?
223 static BOOL
IsDelimiter (TCHAR c
)
225 return (c
== _T('/') || c
== _T('=') || c
== _T('\0') || _istspace (c
));
229 * Is a process a console process?
231 static BOOL
IsConsoleProcess(HANDLE Process
)
234 PROCESS_BASIC_INFORMATION Info
;
238 if (NULL
== NtQueryInformationProcessPtr
|| NULL
== NtReadVirtualMemoryPtr
)
243 Status
= NtQueryInformationProcessPtr (
244 Process
, ProcessBasicInformation
,
245 &Info
, sizeof(PROCESS_BASIC_INFORMATION
), NULL
);
246 if (! NT_SUCCESS(Status
))
249 DebugPrintf (_T("NtQueryInformationProcess failed with status %08x\n"), Status
);
253 Status
= NtReadVirtualMemoryPtr (
254 Process
, Info
.PebBaseAddress
, &ProcessPeb
,
255 sizeof(PEB
), &BytesRead
);
256 if (! NT_SUCCESS(Status
) || sizeof(PEB
) != BytesRead
)
259 DebugPrintf (_T("Couldn't read virt mem status %08x bytes read %lu\n"), Status
, BytesRead
);
264 return IMAGE_SUBSYSTEM_WINDOWS_CUI
== ProcessPeb
.ImageSubSystem
;
270 #define SHELLEXECUTETEXT "ShellExecuteW"
272 #define SHELLEXECUTETEXT "ShellExecuteA"
275 typedef HINSTANCE (WINAPI
*MYEX
)(
279 LPCTSTR lpParameters
,
286 static BOOL
RunFile(LPTSTR filename
)
293 DebugPrintf (_T("RunFile(%s)\n"), filename
);
295 hShell32
= LoadLibrary(_T("SHELL32.DLL"));
299 DebugPrintf (_T("RunFile: couldn't load SHELL32.DLL!\n"));
304 hShExt
= (MYEX
)(FARPROC
)GetProcAddress(hShell32
, SHELLEXECUTETEXT
);
308 DebugPrintf (_T("RunFile: couldn't find ShellExecuteA/W in SHELL32.DLL!\n"));
310 FreeLibrary(hShell32
);
315 DebugPrintf (_T("RunFile: ShellExecuteA/W is at %x\n"), hShExt
);
318 ret
= (hShExt
)(NULL
, _T("open"), filename
, NULL
, NULL
, SW_SHOWNORMAL
);
321 DebugPrintf (_T("RunFile: ShellExecuteA/W returned %d\n"), (DWORD
)ret
);
324 FreeLibrary(hShell32
);
325 return (((DWORD
)ret
) > 32);
331 * This command (in first) was not found in the command table
333 * Full - whole command line
334 * First - first word on command line
335 * Rest - rest of command line
339 Execute (LPTSTR Full
, LPTSTR First
, LPTSTR Rest
)
341 TCHAR
*szFullName
=NULL
;
346 TCHAR szWindowTitle
[MAX_PATH
];
347 DWORD dwExitCode
= 0;
350 DebugPrintf (_T("Execute: \'%s\' \'%s\'\n"), first
, rest
);
353 /* we need biger buffer that First, Rest, Full are already
354 need rewrite some code to use realloc when it need instead
355 of add 512bytes extra */
357 first
= malloc ( (_tcslen(First
) + 512) * sizeof(TCHAR
));
360 error_out_of_memory();
365 rest
= malloc ( (_tcslen(Rest
) + 512) * sizeof(TCHAR
));
369 error_out_of_memory();
374 full
= malloc ( (_tcslen(Full
) + 512) * sizeof(TCHAR
));
379 error_out_of_memory();
384 szFullName
= malloc ( (_tcslen(Full
) + 512) * sizeof(TCHAR
));
390 error_out_of_memory();
396 /* Though it was already parsed once, we have a different set of rules
397 for parsing before we pass to CreateProccess */
398 if(!_tcschr(Full
,_T('\"')))
400 _tcscpy(first
,First
);
407 BOOL bInside
= FALSE
;
412 /* find the end of the command and start of the args */
413 for(i
= 0; i
< _tcslen(first
); i
++)
415 if(!_tcsncmp(&first
[i
], _T("\""), 1))
417 if(!_tcsncmp(&first
[i
], _T(" "), 1) && !bInside
)
419 _tcscpy(rest
,&first
[i
]);
426 /* remove any slashes */
427 while(i
< _tcslen(first
))
429 if(first
[i
] == _T('\"'))
430 memmove(&first
[i
],&first
[i
+ 1], _tcslen(&first
[i
]) * sizeof(TCHAR
));
434 /* Drop quotes around it just in case there is a space */
435 _tcscpy(full
,_T("\""));
437 _tcscat(full
,_T("\" "));
441 /* check for a drive change */
442 if ((_istalpha (first
[0])) && (!_tcscmp (first
+ 1, _T(":"))))
445 if (!SetCurrentDirectory(first
))
446 /* Guess they changed disc or something, handle that gracefully and get to root */
453 working
= SetCurrentDirectory(str
);
456 if (!working
) ConErrResPuts (STRING_FREE_ERROR1
);
466 /* get the PATH environment variable and parse it */
467 /* search the PATH environment variable for the binary */
468 if (!SearchForExecutable (first
, szFullName
))
470 error_bad_command ();
480 GetConsoleTitle (szWindowTitle
, MAX_PATH
);
482 /* check if this is a .BAT or .CMD file */
483 dot
= _tcsrchr (szFullName
, _T('.'));
484 if (dot
&& (!_tcsicmp (dot
, _T(".bat")) || !_tcsicmp (dot
, _T(".cmd"))))
487 DebugPrintf (_T("[BATCH: %s %s]\n"), szFullName
, rest
);
489 Batch (szFullName
, first
, rest
);
493 /* exec the program */
494 PROCESS_INFORMATION prci
;
498 DebugPrintf (_T("[EXEC: %s %s]\n"), full
, rest
);
500 /* build command line for CreateProcess() */
502 /* fill startup info */
503 memset (&stui
, 0, sizeof (STARTUPINFO
));
504 stui
.cb
= sizeof (STARTUPINFO
);
505 stui
.dwFlags
= STARTF_USESHOWWINDOW
;
506 stui
.wShowWindow
= SW_SHOWDEFAULT
;
508 // return console to standard mode
509 SetConsoleMode (GetStdHandle(STD_INPUT_HANDLE
),
510 ENABLE_LINE_INPUT
| ENABLE_PROCESSED_INPUT
| ENABLE_ECHO_INPUT
);
512 if (CreateProcess (szFullName
,
517 0, /* CREATE_NEW_PROCESS_GROUP */
524 if (IsConsoleProcess(prci
.hProcess
))
526 /* FIXME: Protect this with critical section */
527 bChildProcessRunning
= TRUE
;
528 dwChildProcessId
= prci
.dwProcessId
;
530 WaitForSingleObject (prci
.hProcess
, INFINITE
);
532 /* FIXME: Protect this with critical section */
533 bChildProcessRunning
= FALSE
;
535 GetExitCodeProcess (prci
.hProcess
, &dwExitCode
);
536 nErrorLevel
= (INT
)dwExitCode
;
542 CloseHandle (prci
.hThread
);
543 CloseHandle (prci
.hProcess
);
548 DebugPrintf (_T("[ShellExecute: %s]\n"), full
);
550 // See if we can run this with ShellExecute() ie myfile.xls
554 DebugPrintf (_T("[ShellExecute failed!: %s]\n"), full
);
556 error_bad_command ();
564 // restore console mode
566 GetStdHandle( STD_INPUT_HANDLE
),
567 ENABLE_PROCESSED_INPUT
);
570 /* Get code page if it has been change */
571 InputCodePage
= GetConsoleCP();
572 OutputCodePage
= GetConsoleOutputCP();
573 SetConsoleTitle (szWindowTitle
);
583 * look through the internal commands and determine whether or not this
584 * command is one of them. If it is, call the command. If not, call
585 * execute to run it as an external program.
587 * line - the command line of the program to run
592 DoCommand (LPTSTR line
)
594 TCHAR
*com
= NULL
; /* the first word in the command */
597 LPTSTR rest
; /* pointer to the rest of the command line */
602 DebugPrintf (_T("DoCommand: (\'%s\')\n"), line
);
605 com
= malloc( (_tcslen(line
) +512)*sizeof(TCHAR
) );
608 error_out_of_memory();
613 /* Skip over initial white space */
614 while (_istspace (*line
))
620 /* Anything to do ? */
623 if (*rest
== _T('"'))
625 /* treat quoted words specially */
629 while(*rest
!= _T('\0') && *rest
!= _T('"'))
630 *cp
++ = _totlower (*rest
++);
631 if (*rest
== _T('"'))
636 while (!IsDelimiter (*rest
))
637 *cp
++ = _totlower (*rest
++);
641 /* Terminate first word */
644 /* Do not limit commands to MAX_PATH */
646 if(_tcslen(com) > MAX_PATH)
654 /* Skip over whitespace to rest of line, exclude 'echo' command */
655 if (_tcsicmp (com
, _T("echo")))
657 while (_istspace (*rest
))
661 /* Scan internal command table */
662 for (cmdptr
= cmds
;; cmdptr
++)
664 /* If end of table execute ext cmd */
665 if (cmdptr
->name
== NULL
)
667 Execute (line
, com
, rest
);
671 if (!_tcscmp (com
, cmdptr
->name
))
673 cmdptr
->func (com
, rest
);
677 /* The following code handles the case of commands like CD which
678 * are recognised even when the command name and parameter are
679 * not space separated.
685 /* Get length of command name */
686 cl
= _tcslen (cmdptr
->name
);
688 if ((cmdptr
->flags
& CMD_SPECIAL
) &&
689 (!_tcsncmp (cmdptr
->name
, com
, cl
)) &&
690 (_tcschr (_T("\\.-"), *(com
+ cl
))))
692 /* OK its one of the specials...*/
694 /* Terminate first word properly */
697 /* Call with new rest */
698 cmdptr
->func (com
, cstart
+ cl
);
708 * process the command line and execute the appropriate functions
709 * full input/output redirection and piping are supported
712 VOID
ParseCommandLine (LPTSTR cmd
)
714 TCHAR szMsg
[RC_STRING_MAX_SIZE
];
715 TCHAR cmdline
[CMDLINE_LENGTH
];
717 #ifdef FEATURE_REDIRECTION
718 TCHAR in
[CMDLINE_LENGTH
] = _T("");
719 TCHAR out
[CMDLINE_LENGTH
] = _T("");
720 TCHAR err
[CMDLINE_LENGTH
] = _T("");
721 TCHAR szTempPath
[MAX_PATH
] = _T(".\\");
722 TCHAR szFileName
[2][MAX_PATH
] = {_T(""), _T("")};
723 HANDLE hFile
[2] = {INVALID_HANDLE_VALUE
, INVALID_HANDLE_VALUE
};
729 BOOL bNewBatch
= TRUE
;
733 #endif /* FEATURE_REDIRECTION */
735 _tcscpy (cmdline
, cmd
);
739 DebugPrintf (_T("ParseCommandLine: (\'%s\')\n"), s
);
742 #ifdef FEATURE_ALIASES
743 /* expand all aliases */
744 ExpandAlias (s
, CMDLINE_LENGTH
);
745 #endif /* FEATURE_ALIAS */
747 #ifdef FEATURE_REDIRECTION
748 /* find the temp path to store temporary files */
749 Length
= GetTempPath (MAX_PATH
, szTempPath
);
750 if (Length
> 0 && Length
< MAX_PATH
)
752 Attributes
= GetFileAttributes(szTempPath
);
753 if (Attributes
== 0xffffffff ||
754 !(Attributes
& FILE_ATTRIBUTE_DIRECTORY
))
759 if (Length
== 0 || Length
>= MAX_PATH
)
761 _tcscpy(szTempPath
, _T(".\\"));
763 if (szTempPath
[_tcslen (szTempPath
) - 1] != _T('\\'))
764 _tcscat (szTempPath
, _T("\\"));
766 /* get the redirections from the command line */
767 num
= GetRedirection (s
, in
, out
, err
, &nRedirFlags
);
769 /* more efficient, but do we really need to do this? */
770 for (t
= in
; _istspace (*t
); t
++)
774 for (t
= out
; _istspace (*t
); t
++)
778 for (t
= err
; _istspace (*t
); t
++)
782 if(bc
&& !_tcslen (in
) && _tcslen (bc
->In
))
784 if(bc
&& !out
[0] && _tcslen(bc
->Out
))
786 nRedirFlags
|= OUTPUT_APPEND
;
787 _tcscpy(out
, bc
->Out
);
789 if(bc
&& !_tcslen (err
) && _tcslen (bc
->Err
))
791 nRedirFlags
|= ERROR_APPEND
;
792 _tcscpy(err
, bc
->Err
);
796 /* Set up the initial conditions ... */
797 /* preserve STDIN, STDOUT and STDERR handles */
798 hOldConIn
= GetStdHandle (STD_INPUT_HANDLE
);
799 hOldConOut
= GetStdHandle (STD_OUTPUT_HANDLE
);
800 hOldConErr
= GetStdHandle (STD_ERROR_HANDLE
);
806 SECURITY_ATTRIBUTES sa
= {sizeof(SECURITY_ATTRIBUTES
), NULL
, TRUE
};
808 /* we need make sure the LastError msg is zero before calling CreateFile */
811 /* Set up pipe for the standard input handler */
812 hFile
= CreateFile (in
, GENERIC_READ
, FILE_SHARE_READ
, &sa
, OPEN_EXISTING
,
813 FILE_ATTRIBUTE_NORMAL
, NULL
);
814 if (hFile
== INVALID_HANDLE_VALUE
)
816 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR1
, szMsg
, RC_STRING_MAX_SIZE
);
817 ConErrPrintf(szMsg
, in
);
821 if (!SetStdHandle (STD_INPUT_HANDLE
, hFile
))
823 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR1
, szMsg
, RC_STRING_MAX_SIZE
);
824 ConErrPrintf(szMsg
, in
);
828 DebugPrintf (_T("Input redirected from: %s\n"), in
);
832 /* Now do all but the last pipe command */
833 *szFileName
[0] = _T('\0');
834 hFile
[0] = INVALID_HANDLE_VALUE
;
838 SECURITY_ATTRIBUTES sa
= {sizeof(SECURITY_ATTRIBUTES
), NULL
, TRUE
};
840 /* Create unique temporary file name */
841 GetTempFileName (szTempPath
, _T("CMD"), 0, szFileName
[1]);
843 /* we need make sure the LastError msg is zero before calling CreateFile */
846 /* Set current stdout to temporary file */
847 hFile
[1] = CreateFile (szFileName
[1], GENERIC_WRITE
, 0, &sa
,
848 TRUNCATE_EXISTING
, FILE_ATTRIBUTE_TEMPORARY
, NULL
);
850 if (hFile
[1] == INVALID_HANDLE_VALUE
)
852 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR2
, szMsg
, RC_STRING_MAX_SIZE
);
857 SetStdHandle (STD_OUTPUT_HANDLE
, hFile
[1]);
861 /* close stdout file */
862 SetStdHandle (STD_OUTPUT_HANDLE
, hOldConOut
);
863 if ((hFile
[1] != INVALID_HANDLE_VALUE
) && (hFile
[1] != hOldConOut
))
865 CloseHandle (hFile
[1]);
866 hFile
[1] = INVALID_HANDLE_VALUE
;
869 /* close old stdin file */
870 SetStdHandle (STD_INPUT_HANDLE
, hOldConIn
);
871 if ((hFile
[0] != INVALID_HANDLE_VALUE
) && (hFile
[0] != hOldConIn
))
873 /* delete old stdin file, if it is a real file */
874 CloseHandle (hFile
[0]);
875 hFile
[0] = INVALID_HANDLE_VALUE
;
876 DeleteFile (szFileName
[0]);
877 *szFileName
[0] = _T('\0');
880 /* copy stdout file name to stdin file name */
881 _tcscpy (szFileName
[0], szFileName
[1]);
882 *szFileName
[1] = _T('\0');
884 /* we need make sure the LastError msg is zero before calling CreateFile */
887 /* open new stdin file */
888 hFile
[0] = CreateFile (szFileName
[0], GENERIC_READ
, 0, &sa
,
889 OPEN_EXISTING
, FILE_ATTRIBUTE_TEMPORARY
, NULL
);
890 SetStdHandle (STD_INPUT_HANDLE
, hFile
[0]);
892 s
= s
+ _tcslen (s
) + 1;
895 /* Now set up the end conditions... */
896 /* redirect STDOUT */
899 /* Final output to here */
901 SECURITY_ATTRIBUTES sa
= {sizeof(SECURITY_ATTRIBUTES
), NULL
, TRUE
};
903 /* we need make sure the LastError msg is zero before calling CreateFile */
906 hFile
= CreateFile (out
, GENERIC_WRITE
, FILE_SHARE_WRITE
| FILE_SHARE_READ
| FILE_SHARE_DELETE
, &sa
,
907 (nRedirFlags
& OUTPUT_APPEND
) ? OPEN_ALWAYS
: CREATE_ALWAYS
,
908 FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_WRITE_THROUGH
, NULL
);
910 if (hFile
== INVALID_HANDLE_VALUE
)
912 INT size
= _tcslen(out
)-1;
914 if (out
[size
] != _T(':'))
916 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR3
, szMsg
, RC_STRING_MAX_SIZE
);
917 ConErrPrintf(szMsg
, out
);
922 hFile
= CreateFile (out
, GENERIC_WRITE
, FILE_SHARE_WRITE
| FILE_SHARE_READ
| FILE_SHARE_DELETE
, &sa
,
923 (nRedirFlags
& OUTPUT_APPEND
) ? OPEN_ALWAYS
: CREATE_ALWAYS
,
924 FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_WRITE_THROUGH
, NULL
);
926 if (hFile
== INVALID_HANDLE_VALUE
)
928 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR3
, szMsg
, RC_STRING_MAX_SIZE
);
929 ConErrPrintf(szMsg
, out
);
935 if (!SetStdHandle (STD_OUTPUT_HANDLE
, hFile
))
937 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR3
, szMsg
, RC_STRING_MAX_SIZE
);
938 ConErrPrintf(szMsg
, out
);
942 if (nRedirFlags
& OUTPUT_APPEND
)
946 if (GetFileType (hFile
) == FILE_TYPE_DISK
)
947 SetFilePointer (hFile
, 0, &lHighPos
, FILE_END
);
950 DebugPrintf (_T("Output redirected to: %s\n"), out
);
953 else if (hOldConOut
!= INVALID_HANDLE_VALUE
)
955 /* Restore original stdout */
956 HANDLE hOut
= GetStdHandle (STD_OUTPUT_HANDLE
);
957 SetStdHandle (STD_OUTPUT_HANDLE
, hOldConOut
);
958 if (hOldConOut
!= hOut
)
960 hOldConOut
= INVALID_HANDLE_VALUE
;
963 /* redirect STDERR */
966 /* Final output to here */
968 SECURITY_ATTRIBUTES sa
= {sizeof(SECURITY_ATTRIBUTES
), NULL
, TRUE
};
970 if (!_tcscmp (err
, out
))
973 DebugPrintf (_T("Stdout and stderr will use the same file!!\n"));
975 DuplicateHandle (GetCurrentProcess (),
976 GetStdHandle (STD_OUTPUT_HANDLE
),
977 GetCurrentProcess (),
978 &hFile
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
982 hFile
= CreateFile (err
,
984 FILE_SHARE_WRITE
| FILE_SHARE_READ
| FILE_SHARE_DELETE
,
986 (nRedirFlags
& ERROR_APPEND
) ? OPEN_ALWAYS
: CREATE_ALWAYS
,
987 FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_WRITE_THROUGH
,
989 if (hFile
== INVALID_HANDLE_VALUE
)
991 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR3
, szMsg
, RC_STRING_MAX_SIZE
);
992 ConErrPrintf(szMsg
, err
);
997 if (!SetStdHandle (STD_ERROR_HANDLE
, hFile
))
999 LoadString(CMD_ModuleHandle
, STRING_CMD_ERROR3
, szMsg
, RC_STRING_MAX_SIZE
);
1000 ConErrPrintf(szMsg
, err
);
1004 if (nRedirFlags
& ERROR_APPEND
)
1008 if (GetFileType (hFile
) == FILE_TYPE_DISK
)
1009 SetFilePointer (hFile
, 0, &lHighPos
, FILE_END
);
1012 DebugPrintf (_T("Error redirected to: %s\n"), err
);
1015 else if (hOldConErr
!= INVALID_HANDLE_VALUE
)
1017 /* Restore original stderr */
1018 HANDLE hErr
= GetStdHandle (STD_ERROR_HANDLE
);
1019 SetStdHandle (STD_ERROR_HANDLE
, hOldConErr
);
1020 if (hOldConErr
!= hErr
)
1022 hOldConErr
= INVALID_HANDLE_VALUE
;
1029 /* process final command */
1032 #ifdef FEATURE_REDIRECTION
1034 AddBatchRedirection(in
, out
, err
);
1035 /* close old stdin file */
1036 #if 0 /* buggy implementation */
1037 SetStdHandle (STD_INPUT_HANDLE
, hOldConIn
);
1038 if ((hFile
[0] != INVALID_HANDLE_VALUE
) &&
1039 (hFile
[0] != hOldConIn
))
1041 /* delete old stdin file, if it is a real file */
1042 CloseHandle (hFile
[0]);
1043 hFile
[0] = INVALID_HANDLE_VALUE
;
1044 DeleteFile (szFileName
[0]);
1045 *szFileName
[0] = _T('\0');
1048 /* Restore original STDIN */
1049 if (hOldConIn
!= INVALID_HANDLE_VALUE
)
1051 HANDLE hIn
= GetStdHandle (STD_INPUT_HANDLE
);
1052 SetStdHandle (STD_INPUT_HANDLE
, hOldConIn
);
1053 if (hOldConIn
!= hIn
)
1055 hOldConIn
= INVALID_HANDLE_VALUE
;
1060 DebugPrintf (_T("Can't restore STDIN! Is invalid!!\n"), out
);
1063 #endif /* buggy implementation */
1066 if (hOldConIn
!= INVALID_HANDLE_VALUE
)
1068 HANDLE hIn
= GetStdHandle (STD_INPUT_HANDLE
);
1069 SetStdHandle (STD_INPUT_HANDLE
, hOldConIn
);
1070 if (hIn
== INVALID_HANDLE_VALUE
)
1073 DebugPrintf (_T("Previous STDIN is invalid!!\n"));
1078 if (GetFileType (hIn
) == FILE_TYPE_DISK
)
1080 if (hFile
[0] == hIn
)
1082 CloseHandle (hFile
[0]);
1083 hFile
[0] = INVALID_HANDLE_VALUE
;
1084 DeleteFile (szFileName
[0]);
1085 *szFileName
[0] = _T('\0');
1090 DebugPrintf (_T("hFile[0] and hIn dont match!!!\n"));
1098 /* Restore original STDOUT */
1099 if (hOldConOut
!= INVALID_HANDLE_VALUE
)
1101 HANDLE hOut
= GetStdHandle (STD_OUTPUT_HANDLE
);
1102 SetStdHandle (STD_OUTPUT_HANDLE
, hOldConOut
);
1103 if (hOldConOut
!= hOut
)
1105 hOldConOut
= INVALID_HANDLE_VALUE
;
1108 /* Restore original STDERR */
1109 if (hOldConErr
!= INVALID_HANDLE_VALUE
)
1111 HANDLE hErr
= GetStdHandle (STD_ERROR_HANDLE
);
1112 SetStdHandle (STD_ERROR_HANDLE
, hOldConErr
);
1113 if (hOldConErr
!= hErr
)
1115 hOldConErr
= INVALID_HANDLE_VALUE
;
1117 #endif /* FEATURE_REDIRECTION */
1121 GrowIfNecessary ( UINT needed
, LPTSTR
* ret
, UINT
* retlen
)
1123 if ( *ret
&& needed
< *retlen
)
1128 *ret
= (LPTSTR
)malloc ( *retlen
* sizeof(TCHAR
) );
1130 SetLastError ( ERROR_OUTOFMEMORY
);
1131 return *ret
!= NULL
;
1135 GetEnvVarOrSpecial ( LPCTSTR varName
)
1137 static LPTSTR ret
= NULL
;
1138 static UINT retlen
= 0;
1141 size
= GetEnvironmentVariable ( varName
, ret
, retlen
);
1142 if ( size
> retlen
)
1144 if ( !GrowIfNecessary ( size
, &ret
, &retlen
) )
1146 size
= GetEnvironmentVariable ( varName
, ret
, retlen
);
1151 /* env var doesn't exist, look for a "special" one */
1153 if (_tcsicmp(varName
,_T("cd")) ==0)
1155 size
= GetCurrentDirectory ( retlen
, ret
);
1156 if ( size
> retlen
)
1158 if ( !GrowIfNecessary ( size
, &ret
, &retlen
) )
1160 size
= GetCurrentDirectory ( retlen
, ret
);
1167 else if (_tcsicmp(varName
,_T("time")) ==0)
1170 if ( !GrowIfNecessary ( MAX_PATH
, &ret
, &retlen
) )
1173 _sntprintf ( ret
, retlen
, _T("%02d%c%02d%c%02d%c%02d"),
1174 t
.wHour
, cTimeSeparator
, t
.wMinute
, cTimeSeparator
,
1175 t
.wSecond
, cDecimalSeparator
, t
.wMilliseconds
/ 10);
1179 else if (_tcsicmp(varName
,_T("date")) ==0)
1182 if ( !GrowIfNecessary ( GetDateFormat(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, NULL
, NULL
, NULL
, 0), &ret
, &retlen
) )
1185 size
= GetDateFormat(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, NULL
, NULL
, ret
, retlen
);
1193 else if (_tcsicmp(varName
,_T("random")) ==0)
1195 if ( !GrowIfNecessary ( MAX_PATH
, &ret
, &retlen
) )
1197 /* Get random number */
1198 _itot(rand(),ret
,10);
1203 else if (_tcsicmp(varName
,_T("cmdcmdline")) ==0)
1205 return GetCommandLine();
1208 /* %CMDEXTVERSION% */
1209 else if (_tcsicmp(varName
,_T("cmdextversion")) ==0)
1211 if ( !GrowIfNecessary ( MAX_PATH
, &ret
, &retlen
) )
1213 /* Set version number to 2 */
1219 else if (_tcsicmp(varName
,_T("errorlevel")) ==0)
1221 if ( !GrowIfNecessary ( MAX_PATH
, &ret
, &retlen
) )
1223 _itot(nErrorLevel
,ret
,10);
1227 GrowIfNecessary(_tcslen(varName
) + 2, &ret
, &retlen
);
1228 _stprintf(ret
,_T("%%%s%%"),varName
);
1229 return ret
; /* not found - return orginal string */
1233 GetParsedEnvVar ( LPCTSTR varName
, UINT
* varNameLen
, BOOL ModeSetA
)
1235 static LPTSTR ret
= NULL
;
1236 static UINT retlen
= 0;
1243 if ( *varName
++ != '%' )
1257 if ((tmp
= FindArg (*varName
- _T('0'))))
1263 if ( !GrowIfNecessary ( _tcslen(tmp
)+1, &ret
, &retlen
) )
1265 _tcscpy ( ret
, tmp
);
1268 if ( !GrowIfNecessary ( 3, &ret
, &retlen
) )
1281 // No batch file to see here, move along
1283 if ( !GrowIfNecessary ( 3, &ret
, &retlen
) )
1294 // Copy over the raw params(not including the batch file name
1296 if ( !GrowIfNecessary ( _tcslen(bc
->raw_params
)+1, &ret
, &retlen
) )
1300 _tcscpy ( ret
, bc
->raw_params
);
1304 if ( !GrowIfNecessary ( 2, &ret
, &retlen
) )
1313 /* TODO FIXME 10 is only max size for 32-bit */
1314 if ( !GrowIfNecessary ( 11, &ret
, &retlen
) )
1316 _sntprintf ( ret
, retlen
, _T("%u"), nErrorLevel
);
1324 /* HACK for set/a */
1325 if ( !GrowIfNecessary ( 2, &ret
, &retlen
) )
1333 p
= _tcschr ( varName
, _T('%') );
1336 SetLastError ( ERROR_INVALID_PARAMETER
);
1341 *varNameLen
= size
+ 2;
1342 p
= alloca ( (size
+1) * sizeof(TCHAR
) );
1343 memmove ( p
, varName
, size
* sizeof(TCHAR
) );
1346 return GetEnvVarOrSpecial ( varName
);
1351 * do the prompt/input/process loop
1356 ProcessInput (BOOL bFlag
)
1358 TCHAR commandline
[CMDLINE_LENGTH
];
1359 TCHAR readline
[CMDLINE_LENGTH
];
1369 /* if no batch input then... */
1370 if (!(ip
= ReadBatchLine (&bEchoThisLine
)))
1375 ReadCommand (readline
, CMDLINE_LENGTH
);
1377 bEchoThisLine
= FALSE
;
1385 /* skip leading blanks */
1386 while ( _istspace(*ip
) )
1393 if ( *ip
== _T('%') )
1396 LPCTSTR envVal
= GetParsedEnvVar ( ip
, &envNameLen
, bModeSetA
);
1400 cp
= _stpcpy ( cp
, envVal
);
1404 if (_istcntrl (*ip
))
1408 /* HACK HACK HACK check whether bModeSetA needs to be toggled */
1411 tmp
+= _tcsspn(tmp
,_T(" \t"));
1412 /* first we find and skip and pre-redirections... */
1414 ( _tcschr(_T("<>"),*tmp
)
1415 || !_tcsncmp(tmp
,_T("1>"),2)
1416 || !_tcsncmp(tmp
,_T("2>"),2) ))
1418 if ( _istdigit(*tmp
) )
1422 tmp
+= _tcsspn(tmp
,_T(" \t"));
1423 if ( *tmp
== _T('\"') )
1425 tmp
= _tcschr(tmp
+1,_T('\"'));
1430 tmp
= _tcspbrk(tmp
,_T(" \t"));
1432 tmp
+= _tcsspn(tmp
,_T(" \t"));
1434 /* we should now be pointing to the actual command
1435 * (if there is one yet)*/
1438 /* if we're currently substituting ( which is default )
1439 * check to see if we've parsed out a set/a. if so, we
1440 * need to disable substitution until we come across a
1444 /* look for set /a */
1445 if ( !_tcsnicmp(tmp
,_T("set"),3) )
1448 tmp
+= _tcsspn(tmp
,_T(" \t"));
1449 if ( !_tcsnicmp(tmp
,_T("/a"),2) )
1453 /* if we're not currently substituting, it means we're
1454 * already inside a set /a. now we need to look for
1455 * a redirection in order to turn redirection back on */
1458 /* look for redirector of some kind after the command */
1459 while ( (tmp
= _tcspbrk ( tmp
, _T("^<>|") )) )
1461 if ( *tmp
== _T('^') )
1463 if ( _tcschr(_T("<>|&"), *++tmp
) && *tmp
)
1478 /* strip trailing spaces */
1479 while ((--cp
>= commandline
) && _istspace (*cp
));
1481 *(cp
+ 1) = _T('\0');
1484 /* Echo batch file line */
1488 ConOutPuts (commandline
);
1491 if (!CheckCtrlBreak(BREAK_INPUT
) && *commandline
)
1493 ParseCommandLine (commandline
);
1494 if (bEcho
&& !bIgnoreEcho
&& (!bIsBatch
|| bEchoThisLine
))
1496 bIgnoreEcho
= FALSE
;
1499 while (!bCanExit
|| !bExit
);
1506 * control-break handler.
1508 BOOL WINAPI
BreakHandler (DWORD dwCtrlType
)
1513 static BOOL SelfGenerated
= FALSE
;
1515 if ((dwCtrlType
!= CTRL_C_EVENT
) &&
1516 (dwCtrlType
!= CTRL_BREAK_EVENT
))
1524 SelfGenerated
= FALSE
;
1529 if (bChildProcessRunning
== TRUE
)
1531 SelfGenerated
= TRUE
;
1532 GenerateConsoleCtrlEvent (dwCtrlType
, 0);
1537 rec
.EventType
= KEY_EVENT
;
1538 rec
.Event
.KeyEvent
.bKeyDown
= TRUE
;
1539 rec
.Event
.KeyEvent
.wRepeatCount
= 1;
1540 rec
.Event
.KeyEvent
.wVirtualKeyCode
= _T('C');
1541 rec
.Event
.KeyEvent
.wVirtualScanCode
= _T('C') - 35;
1542 rec
.Event
.KeyEvent
.uChar
.AsciiChar
= _T('C');
1543 rec
.Event
.KeyEvent
.uChar
.UnicodeChar
= _T('C');
1544 rec
.Event
.KeyEvent
.dwControlKeyState
= RIGHT_CTRL_PRESSED
;
1553 /* FIXME: Handle batch files */
1555 //ConOutPrintf(_T("^C"));
1562 VOID
AddBreakHandler (VOID
)
1564 SetConsoleCtrlHandler ((PHANDLER_ROUTINE
)BreakHandler
, TRUE
);
1568 VOID
RemoveBreakHandler (VOID
)
1570 SetConsoleCtrlHandler ((PHANDLER_ROUTINE
)BreakHandler
, FALSE
);
1575 * show commands and options that are available.
1582 /* print command list */
1583 ConOutResPuts(STRING_CMD_HELP1
);
1586 /* print feature list */
1587 ConOutResPuts(STRING_CMD_HELP2
);
1589 #ifdef FEATURE_ALIASES
1590 ConOutResPuts(STRING_CMD_HELP3
);
1592 #ifdef FEATURE_HISTORY
1593 ConOutResPuts(STRING_CMD_HELP4
);
1595 #ifdef FEATURE_UNIX_FILENAME_COMPLETION
1596 ConOutResPuts(STRING_CMD_HELP5
);
1598 #ifdef FEATURE_DIRECTORY_STACK
1599 ConOutResPuts(STRING_CMD_HELP6
);
1601 #ifdef FEATURE_REDIRECTION
1602 ConOutResPuts(STRING_CMD_HELP7
);
1604 ConOutChar(_T('\n'));
1609 * set up global initializations and process parameters
1611 * argc - number of parameters to command.com
1612 * argv - command-line parameters
1616 Initialize (int argc
, TCHAR
* argv
[])
1618 TCHAR commandline
[CMDLINE_LENGTH
];
1619 TCHAR ModuleName
[_MAX_PATH
+ 1];
1624 //TCHAR *ptr, *cmdLine;
1626 /* get version information */
1627 osvi
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
1628 GetVersionEx (&osvi
);
1630 /* Some people like to run ReactOS cmd.exe on Win98, it helps in the
1631 * build process. So don't link implicitly against ntdll.dll, load it
1632 * dynamically instead */
1634 if (osvi
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
1636 /* ntdll is always present on NT */
1637 NtDllModule
= GetModuleHandle(TEXT("ntdll.dll"));
1641 /* not all 9x versions have a ntdll.dll, try to load it */
1642 NtDllModule
= LoadLibrary(TEXT("ntdll.dll"));
1645 if (NtDllModule
!= NULL
)
1647 NtQueryInformationProcessPtr
= (NtQueryInformationProcessProc
)GetProcAddress(NtDllModule
, "NtQueryInformationProcess");
1648 NtReadVirtualMemoryPtr
= (NtReadVirtualMemoryProc
)GetProcAddress(NtDllModule
, "NtReadVirtualMemory");
1653 DebugPrintf (_T("[command args:\n"));
1654 for (i
= 0; i
< argc
; i
++)
1656 DebugPrintf (_T("%d. %s\n"), i
, argv
[i
]);
1658 DebugPrintf (_T("]\n"));
1663 /* get default input and output console handles */
1664 hOut
= GetStdHandle (STD_OUTPUT_HANDLE
);
1665 hIn
= GetStdHandle (STD_INPUT_HANDLE
);
1667 /* Set EnvironmentVariable PROMPT if it does not exists any env value.
1668 for you can change the EnvirommentVariable for prompt before cmd start
1669 this patch are not 100% right, if it does not exists a PROMPT value cmd should use
1670 $P$G as defualt not set EnvirommentVariable PROMPT to $P$G if it does not exists */
1671 if (GetEnvironmentVariable(_T("PROMPT"),lpBuffer
, sizeof(lpBuffer
) / sizeof(lpBuffer
[0])) == 0)
1672 SetEnvironmentVariable (_T("PROMPT"), _T("$P$G"));
1675 if (argc
>= 2 && !_tcsncmp (argv
[1], _T("/?"), 2))
1677 ConOutResPaging(TRUE
,STRING_CMD_HELP8
);
1680 SetConsoleMode (hIn
, ENABLE_PROCESSED_INPUT
);
1682 #ifdef INCLUDE_CMD_CHDIR
1686 #ifdef FATURE_ALIASES
1692 for (i
= 1; i
< argc
; i
++)
1694 if (!_tcsicmp (argv
[i
], _T("/p")))
1696 if (!IsExistingFile (_T("\\autoexec.bat")))
1698 #ifdef INCLUDE_CMD_DATE
1699 cmd_date (_T(""), _T(""));
1701 #ifdef INCLUDE_CMD_TIME
1702 cmd_time (_T(""), _T(""));
1707 ParseCommandLine (_T("\\autoexec.bat"));
1711 else if (!_tcsicmp (argv
[i
], _T("/c")))
1713 /* This just runs a program and exits */
1717 _tcscpy (commandline
, argv
[i
]);
1720 _tcscat (commandline
, _T(" "));
1721 _tcscat (commandline
, argv
[i
]);
1724 ParseCommandLine(commandline
);
1725 ExitProcess (ProcessInput (TRUE
));
1732 else if (!_tcsicmp (argv
[i
], _T("/k")))
1734 /* This just runs a program and remains */
1738 _tcscpy (commandline
, _T("\""));
1739 _tcscat (commandline
, argv
[i
]);
1740 _tcscat (commandline
, _T("\""));
1743 _tcscat (commandline
, _T(" "));
1744 _tcscat (commandline
, argv
[i
]);
1746 ParseCommandLine(commandline
);
1749 #ifdef INCLUDE_CMD_COLOR
1750 else if (!_tcsnicmp (argv
[i
], _T("/t:"), 3))
1752 /* process /t (color) argument */
1753 wDefColor
= (WORD
)_tcstoul (&argv
[i
][3], NULL
, 16);
1755 SetScreenColor (wColor
, TRUE
);
1761 /* run cmdstart.bat */
1762 if (IsExistingFile (_T("cmdstart.bat")))
1764 ParseCommandLine (_T("cmdstart.bat"));
1766 else if (IsExistingFile (_T("\\cmdstart.bat")))
1768 ParseCommandLine (_T("\\cmdstart.bat"));
1771 #ifdef FEATURE_DIR_STACK
1772 /* initialize directory stack */
1773 InitDirectoryStack ();
1777 #ifdef FEATURE_HISTORY
1778 /*initialize history*/
1782 /* Set COMSPEC environment variable */
1783 if (0 != GetModuleFileName (NULL
, ModuleName
, _MAX_PATH
+ 1))
1785 ModuleName
[_MAX_PATH
] = _T('\0');
1786 SetEnvironmentVariable (_T("COMSPEC"), ModuleName
);
1789 /* add ctrl break handler */
1794 static VOID
Cleanup (int argc
, TCHAR
*argv
[])
1796 /* run cmdexit.bat */
1797 if (IsExistingFile (_T("cmdexit.bat")))
1799 ConErrResPuts(STRING_CMD_ERROR5
);
1801 ParseCommandLine (_T("cmdexit.bat"));
1803 else if (IsExistingFile (_T("\\cmdexit.bat")))
1805 ConErrResPuts (STRING_CMD_ERROR5
);
1806 ParseCommandLine (_T("\\cmdexit.bat"));
1809 #ifdef FEATURE_ALIASES
1813 #ifdef FEATURE_DIECTORY_STACK
1814 /* destroy directory stack */
1815 DestroyDirectoryStack ();
1818 #ifdef INCLUDE_CMD_CHDIR
1822 #ifdef FEATURE_HISTORY
1827 /* remove ctrl break handler */
1828 RemoveBreakHandler ();
1829 SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE
),
1830 ENABLE_LINE_INPUT
| ENABLE_PROCESSED_INPUT
| ENABLE_ECHO_INPUT
);
1832 if (NtDllModule
!= NULL
)
1834 FreeLibrary(NtDllModule
);
1844 int _main (int argc
, char *argv
[])
1847 TCHAR startPath
[MAX_PATH
];
1848 CONSOLE_SCREEN_BUFFER_INFO Info
;
1853 argv
= CommandLineToArgvW(GetCommandLineW(), &argc
);
1856 GetCurrentDirectory(MAX_PATH
,startPath
);
1863 hConsole
= CreateFile(_T("CONOUT$"), GENERIC_READ
|GENERIC_WRITE
,
1864 FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
,
1865 OPEN_EXISTING
, 0, NULL
);
1866 if (GetConsoleScreenBufferInfo(hConsole
, &Info
) == FALSE
)
1868 ConErrFormatMessage(GetLastError());
1871 wColor
= Info
.wAttributes
;
1874 InputCodePage
= GetConsoleCP();
1875 OutputCodePage
= GetConsoleOutputCP();
1876 CMD_ModuleHandle
= GetModuleHandle(NULL
);
1878 /* check switches on command-line */
1879 Initialize(argc
, argv
);
1881 /* call prompt routine */
1882 nExitCode
= ProcessInput(FALSE
);
1884 /* do the cleanup */
1885 Cleanup(argc
, argv
);