cmd update:
[reactos.git] / reactos / subsys / system / cmd / cmd.c
1 /*
2 * CMD.C - command-line interface.
3 *
4 *
5 * History:
6 *
7 * 17 Jun 1994 (Tim Norman)
8 * started.
9 *
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.
13 *
14 * A added the the standard FreeDOS GNU licence test to the
15 * initialize() function.
16 *
17 * Started to replace puts() with printf(). this will help
18 * standardize output. please follow my lead.
19 *
20 * I have added some constants to help making changes easier.
21 *
22 * 15 Dec 1995 (Tim Norman)
23 * major rewrite of the code to make it more efficient and add
24 * redirection support (finally!)
25 *
26 * 06 Jan 1996 (Tim Norman)
27 * finished adding redirection support! Changed to use our own
28 * exec code (MUCH thanks to Svante Frey!!)
29 *
30 * 29 Jan 1996 (Tim Norman)
31 * added support for CHDIR, RMDIR, MKDIR, and ERASE, as per
32 * suggestion of Steffan Kaiser
33 *
34 * changed "file not found" error message to "bad command or
35 * filename" thanks to Dustin Norman for noticing that confusing
36 * message!
37 *
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)
41 *
42 * 27 Aug 1996 (Tim Norman)
43 * added in support for Oliver Mueller's ALIAS command
44 *
45 * 14 Jun 1997 (Steffan Kaiser)
46 * added ctrl-break handling and error level
47 *
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.
52 *
53 * 21 Jun 1998 (Rob Lake)
54 * Fixed up /C so that arguments for the program
55 *
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!
62 *
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.
67 *
68 * New organisation also properly support nested batch files.
69 *
70 * New command table structure is half way towards providing a
71 * system in which COMMAND will find out what internal commands
72 * are loaded
73 *
74 * 24 Jul 1998 (Hans B Pufal) [HBP_003]
75 * Fixed return value when called with /C option
76 *
77 * 27 Jul 1998 John P. Price
78 * added config.h include
79 *
80 * 28 Jul 1998 John P. Price
81 * added showcmds function to show commands and options available
82 *
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")
86 *
87 * 07-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
88 * First ReactOS release.
89 * Extended length of commandline buffers to 512.
90 *
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.
94 *
95 * 07-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
96 * Added help text ("cmd /?").
97 *
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.
103 *
104 * 27-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
105 * Replaced spawnl() by CreateProcess().
106 *
107 * 22-Oct-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
108 * Added break handler.
109 *
110 * 15-Dec-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
111 * Fixed current directory
112 *
113 * 28-Dec-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
114 * Restore window title after program/batch execution
115 *
116 * 03-Feb-2001 (Eric Kohl <ekohl@rz-online.de>)
117 * Workaround because argc[0] is NULL under ReactOS
118 *
119 * 23-Feb-2001 (Carl Nettelblad <cnettel@hem.passagen.se>)
120 * %envvar% replacement conflicted with for.
121 *
122 * 30-Apr-2004 (Filip Navara <xnavara@volny.cz>)
123 * Make MakeSureDirectoryPathExistsEx unicode safe.
124 *
125 * 28-Mai-2004 (Hartmut Birr)
126 * Removed MakeSureDirectoryPathExistsEx.
127 * Use the current directory if GetTempPath fails.
128 *
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.
131 *
132 * 02-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
133 * Remove all hardcode string to En.rc
134 *
135 * 06-May-2005 (Klemens Friedl <frik85@gmail.com>)
136 * Add 'help' command (list all commands plus description)
137 */
138
139 #include "precomp.h"
140 #include "resource.h"
141
142 #ifndef NT_SUCCESS
143 #define NT_SUCCESS(StatCode) ((NTSTATUS)(StatCode) >= 0)
144 #endif
145
146 typedef NTSTATUS (STDCALL *NtQueryInformationProcessProc)(HANDLE, PROCESSINFOCLASS,
147 PVOID, ULONG, PULONG);
148 typedef NTSTATUS (STDCALL *NtReadVirtualMemoryProc)(HANDLE, PVOID, PVOID, ULONG, PULONG);
149
150 BOOL bExit = FALSE; /* indicates EXIT was typed */
151 BOOL bCanExit = TRUE; /* indicates if this shell is exitable */
152 BOOL bCtrlBreak = FALSE; /* Ctrl-Break or Ctrl-C hit */
153 BOOL bIgnoreEcho = FALSE; /* Ignore 'newline' before 'cls' */
154 INT nErrorLevel = 0; /* Errorlevel of last launched external program */
155 BOOL bChildProcessRunning = FALSE;
156 DWORD dwChildProcessId = 0;
157 OSVERSIONINFO osvi;
158 HANDLE hIn;
159 HANDLE hOut;
160 HANDLE hConsole;
161 HANDLE CMD_ModuleHandle;
162
163 static NtQueryInformationProcessProc NtQueryInformationProcessPtr;
164 static NtReadVirtualMemoryProc NtReadVirtualMemoryPtr;
165 static BOOL NtDllChecked = FALSE;
166
167 #ifdef INCLUDE_CMD_COLOR
168 WORD wColor; /* current color */
169 WORD wDefColor; /* default color */
170 #endif
171
172 /*
173 * is character a delimeter when used on first word?
174 *
175 */
176
177 static BOOL IsDelimiter (TCHAR c)
178 {
179 return (c == _T('/') || c == _T('=') || c == _T('\0') || _istspace (c));
180 }
181
182 /*
183 * Is a process a console process?
184 */
185 static BOOL IsConsoleProcess(HANDLE Process)
186 {
187 NTSTATUS Status;
188 PROCESS_BASIC_INFORMATION Info;
189 PEB ProcessPeb;
190 ULONG BytesRead;
191 HMODULE NtDllModule;
192
193 /* Some people like to run ReactOS cmd.exe on Win98, it helps in the
194 build process. So don't link implicitly against ntdll.dll, load it
195 dynamically instead */
196 if (! NtDllChecked)
197 {
198 NtDllChecked = TRUE;
199 NtDllModule = LoadLibrary(_T("ntdll.dll"));
200 if (NULL == NtDllModule)
201 {
202 /* Probably non-WinNT system. Just wait for the commands
203 to finish. */
204 NtQueryInformationProcessPtr = NULL;
205 NtReadVirtualMemoryPtr = NULL;
206 return TRUE;
207 }
208 NtQueryInformationProcessPtr = (NtQueryInformationProcessProc)
209 GetProcAddress(NtDllModule, "NtQueryInformationProcess");
210 NtReadVirtualMemoryPtr = (NtReadVirtualMemoryProc)
211 GetProcAddress(NtDllModule, "NtReadVirtualMemory");
212 }
213
214 if (NULL == NtQueryInformationProcessPtr || NULL == NtReadVirtualMemoryPtr)
215 {
216 return TRUE;
217 }
218
219 Status = NtQueryInformationProcessPtr(Process, ProcessBasicInformation,
220 &Info, sizeof(PROCESS_BASIC_INFORMATION), NULL);
221 if (! NT_SUCCESS(Status))
222 {
223 #ifdef _DEBUG
224 DebugPrintf (_T("NtQueryInformationProcess failed with status %08x\n"), Status);
225 #endif
226 return TRUE;
227 }
228 Status = NtReadVirtualMemoryPtr(Process, Info.PebBaseAddress, &ProcessPeb,
229 sizeof(PEB), &BytesRead);
230 if (! NT_SUCCESS(Status) || sizeof(PEB) != BytesRead)
231 {
232 #ifdef _DEBUG
233 DebugPrintf (_T("Couldn't read virt mem status %08x bytes read %lu\n"), Status, BytesRead);
234 #endif
235 return TRUE;
236 }
237
238 return IMAGE_SUBSYSTEM_WINDOWS_CUI == ProcessPeb.ImageSubSystem;
239 }
240
241
242
243 #ifdef _UNICODE
244 #define SHELLEXECUTETEXT "ShellExecuteW"
245 #else
246 #define SHELLEXECUTETEXT "ShellExecuteA"
247 #endif
248
249 typedef HINSTANCE (WINAPI *MYEX)(
250 HWND hwnd,
251 LPCTSTR lpOperation,
252 LPCTSTR lpFile,
253 LPCTSTR lpParameters,
254 LPCTSTR lpDirectory,
255 INT nShowCmd
256 );
257
258
259
260 static BOOL RunFile(LPTSTR filename)
261 {
262 HMODULE hShell32;
263 MYEX hShExt;
264 HINSTANCE ret;
265
266 #ifdef _DEBUG
267 DebugPrintf (_T("RunFile(%s)\n"), filename);
268 #endif
269 hShell32 = LoadLibrary(_T("SHELL32.DLL"));
270 if (!hShell32)
271 {
272 #ifdef _DEBUG
273 DebugPrintf (_T("RunFile: couldn't load SHELL32.DLL!\n"));
274 #endif
275 return FALSE;
276 }
277
278 hShExt = (MYEX)(FARPROC)GetProcAddress(hShell32, SHELLEXECUTETEXT);
279 if (!hShExt)
280 {
281 #ifdef _DEBUG
282 DebugPrintf (_T("RunFile: couldn't find ShellExecuteA/W in SHELL32.DLL!\n"));
283 #endif
284 FreeLibrary(hShell32);
285 return FALSE;
286 }
287
288 #ifdef _DEBUG
289 DebugPrintf (_T("RunFile: ShellExecuteA/W is at %x\n"), hShExt);
290 #endif
291
292 ret = (hShExt)(NULL, _T("open"), filename, NULL, NULL, SW_SHOWNORMAL);
293
294 #ifdef _DEBUG
295 DebugPrintf (_T("RunFile: ShellExecuteA/W returned %d\n"), (DWORD)ret);
296 #endif
297
298 FreeLibrary(hShell32);
299 return (((DWORD)ret) > 32);
300 }
301
302
303
304 /*
305 * This command (in first) was not found in the command table
306 *
307 * first - first word on command line
308 * rest - rest of command line
309 */
310
311 static VOID
312 Execute (LPTSTR full, LPTSTR first, LPTSTR rest)
313 {
314 TCHAR szFullName[MAX_PATH];
315 #ifndef __REACTOS__
316 TCHAR szWindowTitle[MAX_PATH];
317 #endif
318 DWORD dwExitCode = 0;
319
320 #ifdef _DEBUG
321 DebugPrintf (_T("Execute: \'%s\' \'%s\'\n"), first, rest);
322 #endif
323
324 /* check for a drive change */
325 if ((_istalpha (first[0])) && (!_tcscmp (first + 1, _T(":"))))
326 {
327 BOOL working = TRUE;
328 if (!SetCurrentDirectory(first))
329 /* Guess they changed disc or something, handle that gracefully and get to root */
330 {
331 TCHAR str[4];
332 str[0]=first[0];
333 str[1]=_T(':');
334 str[2]=_T('\\');
335 str[3]=0;
336 working = SetCurrentDirectory(str);
337 }
338
339 if (!working) ConErrResPuts (STRING_FREE_ERROR1);
340
341 return;
342 }
343
344 /* get the PATH environment variable and parse it */
345 /* search the PATH environment variable for the binary */
346 if (!SearchForExecutable (first, szFullName))
347 {
348 error_bad_command ();
349 return;
350 }
351
352 #ifndef __REACTOS__
353 GetConsoleTitle (szWindowTitle, MAX_PATH);
354 #endif
355
356 /* check if this is a .BAT or .CMD file */
357 if (!_tcsicmp (_tcsrchr (szFullName, _T('.')), _T(".bat")) ||
358 !_tcsicmp (_tcsrchr (szFullName, _T('.')), _T(".cmd")))
359 {
360 #ifdef _DEBUG
361 DebugPrintf (_T("[BATCH: %s %s]\n"), szFullName, rest);
362 #endif
363 Batch (szFullName, first, rest);
364 }
365 else
366 {
367 /* exec the program */
368 PROCESS_INFORMATION prci;
369 STARTUPINFO stui;
370
371 #ifdef _DEBUG
372 DebugPrintf (_T("[EXEC: %s %s]\n"), full, rest);
373 #endif
374 /* build command line for CreateProcess() */
375
376 /* fill startup info */
377 memset (&stui, 0, sizeof (STARTUPINFO));
378 stui.cb = sizeof (STARTUPINFO);
379 stui.dwFlags = STARTF_USESHOWWINDOW;
380 stui.wShowWindow = SW_SHOWDEFAULT;
381
382 // return console to standard mode
383 SetConsoleMode (GetStdHandle(STD_INPUT_HANDLE),
384 ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT );
385
386 if (CreateProcess (szFullName,
387 full,
388 NULL,
389 NULL,
390 TRUE,
391 CREATE_NEW_PROCESS_GROUP,
392 NULL,
393 NULL,
394 &stui,
395 &prci))
396 {
397 if (IsConsoleProcess(prci.hProcess))
398 {
399 /* FIXME: Protect this with critical section */
400 bChildProcessRunning = TRUE;
401 dwChildProcessId = prci.dwProcessId;
402
403 WaitForSingleObject (prci.hProcess, INFINITE);
404
405 /* FIXME: Protect this with critical section */
406 bChildProcessRunning = FALSE;
407
408 GetExitCodeProcess (prci.hProcess, &dwExitCode);
409 nErrorLevel = (INT)dwExitCode;
410 }
411 CloseHandle (prci.hThread);
412 CloseHandle (prci.hProcess);
413 }
414 else
415 {
416 #ifdef _DEBUG
417 DebugPrintf (_T("[ShellExecute: %s]\n"), full);
418 #endif
419 // See if we can run this with ShellExecute() ie myfile.xls
420 if (!RunFile(full))
421 {
422 #ifdef _DEBUG
423 DebugPrintf (_T("[ShellExecute failed!: %s]\n"), full);
424 #endif
425 error_bad_command ();
426 }
427 }
428 // restore console mode
429 SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE ),
430 ENABLE_PROCESSED_INPUT );
431 }
432
433 /* Get code page if it has been change */
434 InputCodePage= GetConsoleCP();
435 OutputCodePage = GetConsoleOutputCP();
436 #ifndef __REACTOS__
437 SetConsoleTitle (szWindowTitle);
438 #endif
439 }
440
441
442 /*
443 * look through the internal commands and determine whether or not this
444 * command is one of them. If it is, call the command. If not, call
445 * execute to run it as an external program.
446 *
447 * line - the command line of the program to run
448 *
449 */
450
451 static VOID
452 DoCommand (LPTSTR line)
453 {
454 TCHAR com[CMDLINE_LENGTH]; /* the first word in the command */
455 LPTSTR cp = com;
456 LPTSTR cstart;
457 LPTSTR rest; /* pointer to the rest of the command line */
458 INT cl;
459 LPCOMMAND cmdptr;
460
461 #ifdef _DEBUG
462 DebugPrintf (_T("DoCommand: (\'%s\')\n"), line);
463 #endif /* DEBUG */
464
465 /* Skip over initial white space */
466 while (_istspace (*line))
467 line++;
468 rest = line;
469
470 cstart = rest;
471
472 /* Anything to do ? */
473 if (*rest)
474 {
475 if (*rest == _T('"'))
476 {
477 /* treat quoted words specially */
478
479 rest++;
480
481 while(*rest != _T('\0') && *rest != _T('"'))
482 *cp++ = _totlower (*rest++);
483 if (*rest == _T('"'))
484 rest++;
485 }
486 else
487 {
488 while (!IsDelimiter (*rest))
489 *cp++ = _totlower (*rest++);
490 }
491
492
493 /* Terminate first word */
494 *cp = _T('\0');
495
496 /* commands are limited to MAX_PATH */
497 if(_tcslen(com) > MAX_PATH)
498 {
499 error_bad_command();
500 return;
501 }
502
503 /* Skip over whitespace to rest of line */
504 while (_istspace (*rest))
505 rest++;
506
507 /* Scan internal command table */
508 for (cmdptr = cmds;; cmdptr++)
509 {
510 /* If end of table execute ext cmd */
511 if (cmdptr->name == NULL)
512 {
513 Execute (line, com, rest);
514 break;
515 }
516
517 if (!_tcscmp (com, cmdptr->name))
518 {
519 cmdptr->func (com, rest);
520 break;
521 }
522
523 /* The following code handles the case of commands like CD which
524 * are recognised even when the command name and parameter are
525 * not space separated.
526 *
527 * e.g dir..
528 * cd\freda
529 */
530
531 /* Get length of command name */
532 cl = _tcslen (cmdptr->name);
533
534 if ((cmdptr->flags & CMD_SPECIAL) &&
535 (!_tcsncmp (cmdptr->name, com, cl)) &&
536 (_tcschr (_T("\\.-"), *(com + cl))))
537 {
538 /* OK its one of the specials...*/
539
540 /* Terminate first word properly */
541 com[cl] = _T('\0');
542
543 /* Call with new rest */
544 cmdptr->func (com, cstart + cl);
545 break;
546 }
547 }
548 }
549 }
550
551
552 /*
553 * process the command line and execute the appropriate functions
554 * full input/output redirection and piping are supported
555 */
556
557 VOID ParseCommandLine (LPTSTR cmd)
558 {
559 TCHAR szMsg[RC_STRING_MAX_SIZE];
560 TCHAR cmdline[CMDLINE_LENGTH];
561 LPTSTR s;
562 #ifdef FEATURE_REDIRECTION
563 TCHAR in[CMDLINE_LENGTH] = _T("");
564 TCHAR out[CMDLINE_LENGTH] = _T("");
565 TCHAR err[CMDLINE_LENGTH] = _T("");
566 TCHAR szTempPath[MAX_PATH] = _T(".\\");
567 TCHAR szFileName[2][MAX_PATH] = {_T(""), _T("")};
568 HANDLE hFile[2] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE};
569 LPTSTR t = NULL;
570 INT num = 0;
571 INT nRedirFlags = 0;
572 INT Length;
573 UINT Attributes;
574
575 HANDLE hOldConIn;
576 HANDLE hOldConOut;
577 HANDLE hOldConErr;
578 #endif /* FEATURE_REDIRECTION */
579
580 _tcscpy (cmdline, cmd);
581 s = &cmdline[0];
582
583 #ifdef _DEBUG
584 DebugPrintf (_T("ParseCommandLine: (\'%s\')\n"), s);
585 #endif /* DEBUG */
586
587 #ifdef FEATURE_ALIASES
588 /* expand all aliases */
589 ExpandAlias (s, CMDLINE_LENGTH);
590 #endif /* FEATURE_ALIAS */
591
592 #ifdef FEATURE_REDIRECTION
593 /* find the temp path to store temporary files */
594 Length = GetTempPath (MAX_PATH, szTempPath);
595 if (Length > 0 && Length < MAX_PATH)
596 {
597 Attributes = GetFileAttributes(szTempPath);
598 if (Attributes == 0xffffffff ||
599 !(Attributes & FILE_ATTRIBUTE_DIRECTORY))
600 {
601 Length = 0;
602 }
603 }
604 if (Length == 0 || Length >= MAX_PATH)
605 {
606 _tcscpy(szTempPath, _T(".\\"));
607 }
608 if (szTempPath[_tcslen (szTempPath) - 1] != _T('\\'))
609 _tcscat (szTempPath, _T("\\"));
610
611 /* get the redirections from the command line */
612 num = GetRedirection (s, in, out, err, &nRedirFlags);
613
614 /* more efficient, but do we really need to do this? */
615 for (t = in; _istspace (*t); t++)
616 ;
617 _tcscpy (in, t);
618
619 for (t = out; _istspace (*t); t++)
620 ;
621 _tcscpy (out, t);
622
623 for (t = err; _istspace (*t); t++)
624 ;
625 _tcscpy (err, t);
626
627 /* Set up the initial conditions ... */
628 /* preserve STDIN, STDOUT and STDERR handles */
629 hOldConIn = GetStdHandle (STD_INPUT_HANDLE);
630 hOldConOut = GetStdHandle (STD_OUTPUT_HANDLE);
631 hOldConErr = GetStdHandle (STD_ERROR_HANDLE);
632
633 /* redirect STDIN */
634 if (in[0])
635 {
636 HANDLE hFile;
637 SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
638
639 hFile = CreateFile (in, GENERIC_READ, FILE_SHARE_READ, &sa, OPEN_EXISTING,
640 FILE_ATTRIBUTE_NORMAL, NULL);
641 if (hFile == INVALID_HANDLE_VALUE)
642 {
643 LoadString(CMD_ModuleHandle, STRING_CMD_ERROR1, szMsg, RC_STRING_MAX_SIZE);
644 ConErrPrintf(szMsg, in);
645 return;
646 }
647
648 if (!SetStdHandle (STD_INPUT_HANDLE, hFile))
649 {
650 LoadString(CMD_ModuleHandle, STRING_CMD_ERROR1, szMsg, RC_STRING_MAX_SIZE);
651 ConErrPrintf(szMsg, in);
652 return;
653 }
654 #ifdef _DEBUG
655 DebugPrintf (_T("Input redirected from: %s\n"), in);
656 #endif
657 }
658
659 /* Now do all but the last pipe command */
660 *szFileName[0] = _T('\0');
661 hFile[0] = INVALID_HANDLE_VALUE;
662
663 while (num-- > 1)
664 {
665 SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
666
667 /* Create unique temporary file name */
668 GetTempFileName (szTempPath, _T("CMD"), 0, szFileName[1]);
669
670 /* Set current stdout to temporary file */
671 hFile[1] = CreateFile (szFileName[1], GENERIC_WRITE, 0, &sa,
672 TRUNCATE_EXISTING, FILE_ATTRIBUTE_TEMPORARY, NULL);
673 if (hFile[1] == INVALID_HANDLE_VALUE)
674 {
675 LoadString(CMD_ModuleHandle, STRING_CMD_ERROR2, szMsg, RC_STRING_MAX_SIZE);
676 ConErrPrintf(szMsg);
677 return;
678 }
679
680 SetStdHandle (STD_OUTPUT_HANDLE, hFile[1]);
681
682 DoCommand (s);
683
684 /* close stdout file */
685 SetStdHandle (STD_OUTPUT_HANDLE, hOldConOut);
686 if ((hFile[1] != INVALID_HANDLE_VALUE) && (hFile[1] != hOldConOut))
687 {
688 CloseHandle (hFile[1]);
689 hFile[1] = INVALID_HANDLE_VALUE;
690 }
691
692 /* close old stdin file */
693 SetStdHandle (STD_INPUT_HANDLE, hOldConIn);
694 if ((hFile[0] != INVALID_HANDLE_VALUE) && (hFile[0] != hOldConIn))
695 {
696 /* delete old stdin file, if it is a real file */
697 CloseHandle (hFile[0]);
698 hFile[0] = INVALID_HANDLE_VALUE;
699 DeleteFile (szFileName[0]);
700 *szFileName[0] = _T('\0');
701 }
702
703 /* copy stdout file name to stdin file name */
704 _tcscpy (szFileName[0], szFileName[1]);
705 *szFileName[1] = _T('\0');
706
707 /* open new stdin file */
708 hFile[0] = CreateFile (szFileName[0], GENERIC_READ, 0, &sa,
709 OPEN_EXISTING, FILE_ATTRIBUTE_TEMPORARY, NULL);
710 SetStdHandle (STD_INPUT_HANDLE, hFile[0]);
711
712 s = s + _tcslen (s) + 1;
713 }
714
715 /* Now set up the end conditions... */
716 /* redirect STDOUT */
717 if (out[0])
718 {
719 /* Final output to here */
720 HANDLE hFile;
721 SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
722
723 hFile = CreateFile (out, GENERIC_WRITE, FILE_SHARE_READ, &sa,
724 (nRedirFlags & OUTPUT_APPEND) ? OPEN_ALWAYS : CREATE_ALWAYS,
725 FILE_ATTRIBUTE_NORMAL, NULL);
726 if (hFile == INVALID_HANDLE_VALUE)
727 {
728 LoadString(CMD_ModuleHandle, STRING_CMD_ERROR3, szMsg, RC_STRING_MAX_SIZE);
729 ConErrPrintf(szMsg, out);
730 return;
731 }
732
733 if (!SetStdHandle (STD_OUTPUT_HANDLE, hFile))
734 {
735 LoadString(CMD_ModuleHandle, STRING_CMD_ERROR3, szMsg, RC_STRING_MAX_SIZE);
736 ConErrPrintf(szMsg, out);
737 return;
738 }
739
740 if (nRedirFlags & OUTPUT_APPEND)
741 {
742 LONG lHighPos = 0;
743
744 if (GetFileType (hFile) == FILE_TYPE_DISK)
745 SetFilePointer (hFile, 0, &lHighPos, FILE_END);
746 }
747 #ifdef _DEBUG
748 DebugPrintf (_T("Output redirected to: %s\n"), out);
749 #endif
750 }
751 else if (hOldConOut != INVALID_HANDLE_VALUE)
752 {
753 /* Restore original stdout */
754 HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE);
755 SetStdHandle (STD_OUTPUT_HANDLE, hOldConOut);
756 if (hOldConOut != hOut)
757 CloseHandle (hOut);
758 hOldConOut = INVALID_HANDLE_VALUE;
759 }
760
761 /* redirect STDERR */
762 if (err[0])
763 {
764 /* Final output to here */
765 HANDLE hFile;
766 SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
767
768 if (!_tcscmp (err, out))
769 {
770 #ifdef _DEBUG
771 DebugPrintf (_T("Stdout and stderr will use the same file!!\n"));
772 #endif
773 DuplicateHandle (GetCurrentProcess (),
774 GetStdHandle (STD_OUTPUT_HANDLE),
775 GetCurrentProcess (),
776 &hFile, 0, TRUE, DUPLICATE_SAME_ACCESS);
777 }
778 else
779 {
780 hFile = CreateFile (err,
781 GENERIC_WRITE,
782 0,
783 &sa,
784 (nRedirFlags & ERROR_APPEND) ? OPEN_ALWAYS : CREATE_ALWAYS,
785 FILE_ATTRIBUTE_NORMAL,
786 NULL);
787 if (hFile == INVALID_HANDLE_VALUE)
788 {
789 LoadString(CMD_ModuleHandle, STRING_CMD_ERROR3, szMsg, RC_STRING_MAX_SIZE);
790 ConErrPrintf(szMsg, err);
791 return;
792 }
793 }
794
795 if (!SetStdHandle (STD_ERROR_HANDLE, hFile))
796 {
797 LoadString(CMD_ModuleHandle, STRING_CMD_ERROR3, szMsg, RC_STRING_MAX_SIZE);
798 ConErrPrintf(szMsg, err);
799 return;
800 }
801
802 if (nRedirFlags & ERROR_APPEND)
803 {
804 LONG lHighPos = 0;
805
806 if (GetFileType (hFile) == FILE_TYPE_DISK)
807 SetFilePointer (hFile, 0, &lHighPos, FILE_END);
808 }
809 #ifdef _DEBUG
810 DebugPrintf (_T("Error redirected to: %s\n"), err);
811 #endif
812 }
813 else if (hOldConErr != INVALID_HANDLE_VALUE)
814 {
815 /* Restore original stderr */
816 HANDLE hErr = GetStdHandle (STD_ERROR_HANDLE);
817 SetStdHandle (STD_ERROR_HANDLE, hOldConErr);
818 if (hOldConErr != hErr)
819 CloseHandle (hErr);
820 hOldConErr = INVALID_HANDLE_VALUE;
821 }
822 #endif
823
824 /* process final command */
825 DoCommand (s);
826
827 #ifdef FEATURE_REDIRECTION
828 /* close old stdin file */
829 #if 0 /* buggy implementation */
830 SetStdHandle (STD_INPUT_HANDLE, hOldConIn);
831 if ((hFile[0] != INVALID_HANDLE_VALUE) &&
832 (hFile[0] != hOldConIn))
833 {
834 /* delete old stdin file, if it is a real file */
835 CloseHandle (hFile[0]);
836 hFile[0] = INVALID_HANDLE_VALUE;
837 DeleteFile (szFileName[0]);
838 *szFileName[0] = _T('\0');
839 }
840
841 /* Restore original STDIN */
842 if (hOldConIn != INVALID_HANDLE_VALUE)
843 {
844 HANDLE hIn = GetStdHandle (STD_INPUT_HANDLE);
845 SetStdHandle (STD_INPUT_HANDLE, hOldConIn);
846 if (hOldConIn != hIn)
847 CloseHandle (hIn);
848 hOldConIn = INVALID_HANDLE_VALUE;
849 }
850 else
851 {
852 #ifdef _DEBUG
853 DebugPrintf (_T("Can't restore STDIN! Is invalid!!\n"), out);
854 #endif
855 }
856 #endif /* buggy implementation */
857
858
859 if (hOldConIn != INVALID_HANDLE_VALUE)
860 {
861 HANDLE hIn = GetStdHandle (STD_INPUT_HANDLE);
862 SetStdHandle (STD_INPUT_HANDLE, hOldConIn);
863 if (hIn == INVALID_HANDLE_VALUE)
864 {
865 #ifdef _DEBUG
866 DebugPrintf (_T("Previous STDIN is invalid!!\n"));
867 #endif
868 }
869 else
870 {
871 if (GetFileType (hIn) == FILE_TYPE_DISK)
872 {
873 if (hFile[0] == hIn)
874 {
875 CloseHandle (hFile[0]);
876 hFile[0] = INVALID_HANDLE_VALUE;
877 DeleteFile (szFileName[0]);
878 *szFileName[0] = _T('\0');
879 }
880 else
881 {
882 #ifdef _DEBUG
883 DebugPrintf (_T("hFile[0] and hIn dont match!!!\n"));
884 #endif
885 }
886 }
887 }
888 }
889
890
891 /* Restore original STDOUT */
892 if (hOldConOut != INVALID_HANDLE_VALUE)
893 {
894 HANDLE hOut = GetStdHandle (STD_OUTPUT_HANDLE);
895 SetStdHandle (STD_OUTPUT_HANDLE, hOldConOut);
896 if (hOldConOut != hOut)
897 CloseHandle (hOut);
898 hOldConOut = INVALID_HANDLE_VALUE;
899 }
900
901 /* Restore original STDERR */
902 if (hOldConErr != INVALID_HANDLE_VALUE)
903 {
904 HANDLE hErr = GetStdHandle (STD_ERROR_HANDLE);
905 SetStdHandle (STD_ERROR_HANDLE, hOldConErr);
906 if (hOldConErr != hErr)
907 CloseHandle (hErr);
908 hOldConErr = INVALID_HANDLE_VALUE;
909 }
910 #endif /* FEATURE_REDIRECTION */
911 }
912
913
914 /*
915 * do the prompt/input/process loop
916 *
917 */
918
919 static INT
920 ProcessInput (BOOL bFlag)
921 {
922 TCHAR commandline[CMDLINE_LENGTH];
923 TCHAR readline[CMDLINE_LENGTH];
924 LPTSTR tp = NULL;
925 LPTSTR ip;
926 LPTSTR cp;
927 BOOL bEchoThisLine;
928
929
930 do
931 {
932 /* if no batch input then... */
933 if (!(ip = ReadBatchLine (&bEchoThisLine)))
934 {
935 if (bFlag)
936 return 0;
937
938 ReadCommand (readline, CMDLINE_LENGTH);
939 ip = readline;
940 bEchoThisLine = FALSE;
941 }
942
943 cp = commandline;
944 while (*ip)
945 {
946 if (*ip == _T('%'))
947 {
948 switch (*++ip)
949 {
950 case _T('%'):
951 *cp++ = *ip++;
952 break;
953
954 case _T('0'):
955 case _T('1'):
956 case _T('2'):
957 case _T('3'):
958 case _T('4'):
959 case _T('5'):
960 case _T('6'):
961 case _T('7'):
962 case _T('8'):
963 case _T('9'):
964 if ((tp = FindArg (*ip - _T('0'))))
965 {
966 cp = _stpcpy (cp, tp);
967 ip++;
968 }
969 else
970 *cp++ = _T('%');
971 break;
972
973 case _T('?'):
974 cp += _stprintf (cp, _T("%u"), nErrorLevel);
975 ip++;
976 break;
977
978 default:
979 tp = _tcschr(ip, _T('%'));
980 if ((tp != NULL) &&
981 (tp <= _tcschr(ip, _T(' ')) - 1))
982 {
983 TCHAR evar[512];
984 *tp = _T('\0');
985
986 /* FIXME: This is just a quick hack!! */
987 /* Do a proper memory allocation!! */
988 if (GetEnvironmentVariable (ip, evar, 512))
989 cp = _stpcpy (cp, evar);
990
991 ip = tp + 1;
992 }
993 else
994 {
995 *cp++ = _T('%');
996 }
997 break;
998 }
999 continue;
1000 }
1001
1002 if (_istcntrl (*ip))
1003 *ip = _T(' ');
1004 *cp++ = *ip++;
1005 }
1006
1007 *cp = _T('\0');
1008
1009 /* strip trailing spaces */
1010 while ((--cp >= commandline) && _istspace (*cp));
1011
1012 *(cp + 1) = _T('\0');
1013
1014 /* JPP 19980807 */
1015 /* Echo batch file line */
1016 if (bEchoThisLine)
1017 {
1018 PrintPrompt ();
1019 ConOutPuts (commandline);
1020 }
1021
1022 if (*commandline)
1023 {
1024 ParseCommandLine (commandline);
1025 if (bEcho && !bIgnoreEcho)
1026 ConOutChar ('\n');
1027 bIgnoreEcho = FALSE;
1028 }
1029 }
1030 while (!bCanExit || !bExit);
1031
1032 return 0;
1033 }
1034
1035
1036 /*
1037 * control-break handler.
1038 */
1039 BOOL WINAPI BreakHandler (DWORD dwCtrlType)
1040 {
1041
1042 if ((dwCtrlType != CTRL_C_EVENT) &&
1043 (dwCtrlType != CTRL_BREAK_EVENT))
1044 return FALSE;
1045
1046 if (bChildProcessRunning == TRUE)
1047 {
1048 GenerateConsoleCtrlEvent (CTRL_C_EVENT,
1049 dwChildProcessId);
1050 return TRUE;
1051 }
1052
1053 /* FIXME: Handle batch files */
1054
1055 /* FIXME: Print "^C" */
1056
1057
1058 return TRUE;
1059 }
1060
1061
1062 VOID AddBreakHandler (VOID)
1063 {
1064 SetConsoleCtrlHandler ((PHANDLER_ROUTINE)BreakHandler, TRUE);
1065 }
1066
1067
1068 VOID RemoveBreakHandler (VOID)
1069 {
1070 SetConsoleCtrlHandler ((PHANDLER_ROUTINE)BreakHandler, FALSE);
1071 }
1072
1073
1074 /*
1075 * show commands and options that are available.
1076 *
1077 */
1078 #if 0
1079 static VOID
1080 ShowCommands (VOID)
1081 {
1082 /* print command list */
1083 ConOutResPuts(STRING_CMD_HELP1);
1084 PrintCommandList();
1085
1086 /* print feature list */
1087 ConOutResPuts(STRING_CMD_HELP2);
1088
1089 #ifdef FEATURE_ALIASES
1090 ConOutResPuts(STRING_CMD_HELP3);
1091 #endif
1092 #ifdef FEATURE_HISTORY
1093 ConOutResPuts(STRING_CMD_HELP4);
1094 #endif
1095 #ifdef FEATURE_UNIX_FILENAME_COMPLETION
1096 ConOutResPuts(STRING_CMD_HELP5);
1097 #endif
1098 #ifdef FEATURE_DIRECTORY_STACK
1099 ConOutResPuts(STRING_CMD_HELP6);
1100 #endif
1101 #ifdef FEATURE_REDIRECTION
1102 ConOutResPuts(STRING_CMD_HELP7);
1103 #endif
1104 ConOutChar(_T('\n'));
1105 }
1106 #endif
1107
1108 /*
1109 * set up global initializations and process parameters
1110 *
1111 * argc - number of parameters to command.com
1112 * argv - command-line parameters
1113 *
1114 */
1115 static VOID
1116 Initialize (int argc, TCHAR* argv[])
1117 {
1118 TCHAR commandline[CMDLINE_LENGTH];
1119 TCHAR ModuleName[_MAX_PATH + 1];
1120 INT i;
1121
1122 //INT len;
1123 //TCHAR *ptr, *cmdLine;
1124
1125
1126 #ifdef _DEBUG
1127 INT x;
1128
1129 DebugPrintf (_T("[command args:\n"));
1130 for (x = 0; x < argc; x++)
1131 {
1132 DebugPrintf (_T("%d. %s\n"), x, argv[x]);
1133 }
1134 DebugPrintf (_T("]\n"));
1135 #endif
1136
1137 /* get version information */
1138 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
1139 GetVersionEx (&osvi);
1140
1141 InitLocale ();
1142
1143 /* get default input and output console handles */
1144 hOut = GetStdHandle (STD_OUTPUT_HANDLE);
1145 hIn = GetStdHandle (STD_INPUT_HANDLE);
1146
1147
1148 if (argc >= 2 && !_tcsncmp (argv[1], _T("/?"), 2))
1149 {
1150 ConOutResPuts(STRING_CMD_HELP8);
1151 ExitProcess(0);
1152 }
1153 SetConsoleMode (hIn, ENABLE_PROCESSED_INPUT);
1154
1155 #ifdef INCLUDE_CMD_CHDIR
1156 InitLastPath ();
1157 #endif
1158
1159 #ifdef FATURE_ALIASES
1160 InitializeAlias ();
1161 #endif
1162
1163 if (argc >= 2)
1164 {
1165 for (i = 1; i < argc; i++)
1166 {
1167 if (!_tcsicmp (argv[i], _T("/p")))
1168 {
1169 if (!IsExistingFile (_T("\\autoexec.bat")))
1170 {
1171 #ifdef INCLUDE_CMD_DATE
1172 cmd_date (_T(""), _T(""));
1173 #endif
1174 #ifdef INCLUDE_CMD_TIME
1175 cmd_time (_T(""), _T(""));
1176 #endif
1177 }
1178 else
1179 {
1180 ParseCommandLine (_T("\\autoexec.bat"));
1181 }
1182 bCanExit = FALSE;
1183 }
1184 else if (!_tcsicmp (argv[i], _T("/c")))
1185 {
1186 /* This just runs a program and exits */
1187 ++i;
1188 if (i < argc)
1189 {
1190 _tcscpy (commandline, argv[i]);
1191 while (++i < argc)
1192 {
1193 _tcscat (commandline, _T(" "));
1194 _tcscat (commandline, argv[i]);
1195 }
1196
1197 ParseCommandLine(commandline);
1198 ExitProcess (ProcessInput (TRUE));
1199 }
1200 else
1201 {
1202 ExitProcess (0);
1203 }
1204 }
1205 else if (!_tcsicmp (argv[i], _T("/k")))
1206 {
1207 /* This just runs a program and remains */
1208 ++i;
1209 if (i < argc)
1210 {
1211 _tcscpy (commandline, argv[i]);
1212 while (++i < argc)
1213 {
1214 _tcscat (commandline, _T(" "));
1215 _tcscat (commandline, argv[i]);
1216 }
1217
1218 ParseCommandLine(commandline);
1219 }
1220 }
1221 #ifdef INCLUDE_CMD_COLOR
1222 else if (!_tcsnicmp (argv[i], _T("/t:"), 3))
1223 {
1224 /* process /t (color) argument */
1225 wDefColor = (WORD)_tcstoul (&argv[i][3], NULL, 16);
1226 wColor = wDefColor;
1227 SetScreenColor (wColor, TRUE);
1228 }
1229 #endif
1230 }
1231 }
1232
1233 /* run cmdstart.bat */
1234 if (IsExistingFile (_T("cmdstart.bat")))
1235 {
1236 ParseCommandLine (_T("cmdstart.bat"));
1237 }
1238 else if (IsExistingFile (_T("\\cmdstart.bat")))
1239 {
1240 ParseCommandLine (_T("\\cmdstart.bat"));
1241 }
1242 #ifndef __REACTOS__
1243 else
1244 {
1245 /* try to run cmdstart.bat from install dir */
1246 LPTSTR p;
1247
1248 _tcscpy (commandline, argv[0]);
1249 p = _tcsrchr (commandline, _T('\\')) + 1;
1250 _tcscpy (p, _T("cmdstart.bat"));
1251
1252 if (IsExistingFile (_T("commandline")))
1253 {
1254 LoadString(CMD_ModuleHandle, STRING_CMD_ERROR4, szMsg, RC_STRING_MAX_SIZE);
1255 ConErrPrintf(szMsg, commandline);
1256 ParseCommandLine (commandline);
1257 }
1258 }
1259 #endif
1260
1261 #ifdef FEATURE_DIR_STACK
1262 /* initialize directory stack */
1263 InitDirectoryStack ();
1264 #endif
1265
1266
1267 #ifdef FEATURE_HISTORY
1268 /*initialize history*/
1269 InitHistory();
1270 #endif
1271
1272 /* Set COMSPEC environment variable */
1273 if (0 != GetModuleFileName (NULL, ModuleName, _MAX_PATH + 1))
1274 {
1275 ModuleName[_MAX_PATH] = _T('\0');
1276 SetEnvironmentVariable (_T("COMSPEC"), ModuleName);
1277 }
1278
1279 /* add ctrl break handler */
1280 AddBreakHandler ();
1281 }
1282
1283
1284 static VOID Cleanup (int argc, TCHAR *argv[])
1285 {
1286 #ifndef __REACTOS__
1287 TCHAR szMsg[RC_STRING_MAX_SIZE];
1288 #endif
1289
1290 /* run cmdexit.bat */
1291 if (IsExistingFile (_T("cmdexit.bat")))
1292 {
1293 ConErrResPuts(STRING_CMD_ERROR5);
1294
1295 ParseCommandLine (_T("cmdexit.bat"));
1296 }
1297 else if (IsExistingFile (_T("\\cmdexit.bat")))
1298 {
1299 ConErrResPuts (STRING_CMD_ERROR5);
1300 ParseCommandLine (_T("\\cmdexit.bat"));
1301 }
1302 #ifndef __REACTOS__
1303 else
1304 {
1305 /* try to run cmdexit.bat from install dir */
1306 TCHAR commandline[CMDLINE_LENGTH];
1307 LPTSTR p;
1308
1309 _tcscpy (commandline, argv[0]);
1310 p = _tcsrchr (commandline, _T('\\')) + 1;
1311 _tcscpy (p, _T("cmdexit.bat"));
1312
1313 if (IsExistingFile (_T("commandline")))
1314 {
1315 LoadString(CMD_ModuleHandle, STRING_CMD_ERROR4, szMsg, RC_STRING_MAX_SIZE);
1316 ConErrPrintf(szMsg, commandline);
1317 ParseCommandLine (commandline);
1318 }
1319 }
1320 #endif
1321
1322 #ifdef FEATURE_ALIASES
1323 DestroyAlias ();
1324 #endif
1325
1326 #ifdef FEATURE_DIECTORY_STACK
1327 /* destroy directory stack */
1328 DestroyDirectoryStack ();
1329 #endif
1330
1331 #ifdef INCLUDE_CMD_CHDIR
1332 FreeLastPath ();
1333 #endif
1334
1335 #ifdef FEATURE_HISTORY
1336 CleanHistory();
1337 #endif
1338
1339
1340 /* remove ctrl break handler */
1341 RemoveBreakHandler ();
1342 SetConsoleMode( GetStdHandle( STD_INPUT_HANDLE ),
1343 ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT );
1344 }
1345
1346 #ifdef __REACTOS__
1347 #ifdef _UNICODE
1348 PWCHAR * _CommandLineToArgvW(PWCHAR lpCmdLine, int *pNumArgs)
1349 {
1350 PWCHAR * argvw = NULL;
1351 PWCHAR ptr = lpCmdLine;
1352 PWCHAR str;
1353 int len;
1354 int NumArgs;
1355
1356 NumArgs = 0;
1357
1358 while(lpCmdLine && *lpCmdLine)
1359 {
1360 while (iswspace(*lpCmdLine)) lpCmdLine++;
1361 if (*lpCmdLine)
1362 {
1363 if ((NumArgs % 10)==0)
1364 {
1365 PWCHAR * old_argvw = argvw;
1366 argvw = malloc((NumArgs + 10) * sizeof(PWCHAR));
1367 memcpy(argvw, old_argvw, NumArgs * sizeof(PWCHAR));
1368 free(old_argvw);
1369 }
1370 ptr = wcschr(lpCmdLine, L' ');
1371 if (ptr)
1372 {
1373 len = ptr - lpCmdLine;
1374 }
1375 else
1376 {
1377 len = wcslen(lpCmdLine);
1378 }
1379 str = malloc((len + 1) * sizeof(WCHAR));
1380 memcpy(str, lpCmdLine, len * sizeof(WCHAR));
1381 str[len] = 0;
1382 argvw[NumArgs]=str;
1383 NumArgs++;
1384 lpCmdLine = ptr;
1385 }
1386 }
1387 *pNumArgs = NumArgs;
1388 return argvw;
1389 }
1390 #endif
1391 #endif
1392
1393 /*
1394 * main function
1395 */
1396 #ifdef _UNICODE
1397 int main(void)
1398 #else
1399 int main (int argc, char *argv[])
1400 #endif
1401 {
1402 CONSOLE_SCREEN_BUFFER_INFO Info;
1403 INT nExitCode;
1404 #ifdef _UNICODE
1405 PWCHAR * argv;
1406 int argc=0;
1407 #ifdef __REACTOS__
1408 argv = _CommandLineToArgvW(GetCommandLineW(), &argc);
1409 #else
1410 argv = CommandLineToArgvW(GetCommandLineW(), &argc);
1411 #endif
1412 #endif
1413
1414 SetFileApisToOEM();
1415 InputCodePage= 0;
1416 OutputCodePage = 0;
1417
1418 hConsole = CreateFile(_T("CONOUT$"), GENERIC_READ|GENERIC_WRITE,
1419 FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
1420 OPEN_EXISTING, 0, NULL);
1421 if (GetConsoleScreenBufferInfo(hConsole, &Info) == FALSE)
1422 {
1423 ConOutFormatMessage(GetLastError());
1424 return(1);
1425 }
1426 wColor = Info.wAttributes;
1427 wDefColor = wColor;
1428
1429 InputCodePage= GetConsoleCP();
1430 OutputCodePage = GetConsoleOutputCP();
1431 CMD_ModuleHandle = GetModuleHandle(NULL);
1432
1433 /* check switches on command-line */
1434 Initialize(argc, argv);
1435
1436 /* call prompt routine */
1437 nExitCode = ProcessInput(FALSE);
1438
1439 /* do the cleanup */
1440 Cleanup(argc, argv);
1441
1442 return(nExitCode);
1443 }
1444
1445 /* EOF */