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