Crtl-C gives a new line when reading input
[reactos.git] / reactos / subsys / system / cmd / call.c
1 /*
2 * CALL.C - call internal batch command.
3 *
4 *
5 * History:
6 *
7 * 16 Jul 1998 (Hans B Pufal)
8 * started.
9 *
10 * 16 Jul 1998 (John P Price)
11 * Seperated commands into individual files.
12 *
13 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
14 * added config.h include
15 *
16 * 04-Aug-1998 (Hans B Pufal)
17 * added lines to initialize for pointers (HBP004) This fixed the
18 * lock-up that happened sometimes when calling a batch file from
19 * another batch file.
20 *
21 * 07-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
22 * Added help text ("call /?") and cleaned up.
23 *
24 * 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
25 * Unicode and redirection safe!
26 *
27 * 02-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
28 * Remove all hardcode string to En.rc
29 */
30
31 #include <precomp.h>
32 #include "resource.h"
33
34
35 /*
36 * Perform CALL command.
37 *
38 * Allocate a new batch context and add it to the current chain.
39 * Call parsecommandline passing in our param string
40 * If No batch file was opened then remove our newly allocted
41 * context block.
42 */
43
44 INT cmd_call (LPTSTR cmd, LPTSTR param)
45 {
46 LPBATCH_CONTEXT n = NULL;
47
48 #ifdef _DEBUG
49 DebugPrintf (_T("cmd_call: (\'%s\',\'%s\')\n"), cmd, param);
50 #endif
51 if (!_tcsncmp (param, _T("/?"), 2))
52 {
53 ConOutResPaging(TRUE,STRING_CALL_HELP);
54 return 0;
55 }
56
57 nErrorLevel = 0;
58
59 n = (LPBATCH_CONTEXT)malloc (sizeof (BATCH_CONTEXT));
60
61 if (n == NULL)
62 {
63 error_out_of_memory ();
64 return 1;
65 }
66
67 n->prev = bc;
68 bc = n;
69
70 bc->hBatchFile = INVALID_HANDLE_VALUE;
71 bc->params = NULL;
72 bc->shiftlevel = 0;
73 bc->forvar = 0; /* HBP004 */
74 bc->forproto = NULL; /* HBP004 */
75 ParseCommandLine (param);
76 if (bc->prev)
77 {
78 _tcscpy(bc->In, bc->prev->In);
79 _tcscpy(bc->Out, bc->prev->Out);
80 _tcscpy(bc->Err, bc->prev->Err);
81 }
82 else
83 {
84 bc->In[0] = _T('\0');
85 bc->Out[0] = _T('\0');
86 bc->Err[0] = _T('\0');
87 }
88
89
90 /* Wasn't a batch file so remove conext */
91 if (bc->hBatchFile == INVALID_HANDLE_VALUE)
92 {
93 bc = bc->prev;
94 free (n);
95 }
96
97 return 0;
98 }
99
100 /* EOF */