Added MORE command.
[reactos.git] / rosapps / 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
28 #include "config.h"
29
30 #include <windows.h>
31 #include <tchar.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 #include "cmd.h"
37 #include "batch.h"
38
39
40 /*
41 * Perform CALL command.
42 *
43 * Allocate a new batch context and add it to the current chain.
44 * Call parsecommandline passing in our param string
45 * If No batch file was opened then remove our newly allocted
46 * context block.
47 */
48
49 INT cmd_call (LPTSTR cmd, LPTSTR param)
50 {
51 LPBATCH_CONTEXT n = NULL;
52
53 #ifdef _DEBUG
54 DebugPrintf ("cmd_call: (\'%s\',\'%s\')\n", cmd, param);
55 #endif
56 if (!_tcsncmp (param, _T("/?"), 2))
57 {
58 ConOutPuts (_T("Calls one batch program from another.\n\n"
59 "CALL [drive:][path]filename [batch-parameter]\n\n"
60 " batch-parameter Specifies any command-line information required by the\n"
61 " batch program."));
62 return 0;
63 }
64
65 n = (LPBATCH_CONTEXT)malloc (sizeof (BATCH_CONTEXT));
66
67 if (n == NULL)
68 {
69 error_out_of_memory ();
70 return 1;
71 }
72
73 n->prev = bc;
74 bc = n;
75
76 bc->hBatchFile = INVALID_HANDLE_VALUE;
77 bc->params = NULL;
78 bc->shiftlevel = 0;
79 bc->forvar = 0; /* HBP004 */
80 bc->forproto = NULL; /* HBP004 */
81
82 ParseCommandLine (param);
83
84 /* Wasn't a batch file so remove conext */
85 if (bc->hBatchFile == INVALID_HANDLE_VALUE)
86 {
87 bc = bc->prev;
88 free (n);
89 }
90
91 return 0;
92 }