Make CALL command do another round of %-variable substitutions.
[reactos.git] / reactos / base / shell / cmd / cmd.h
1 /*
2 * CMD.H - header file for the modules in CMD.EXE
3 *
4 *
5 * History:
6 *
7 * 7-15-95 Tim Norman
8 * started
9 *
10 * 06/29/98 (Rob Lake)
11 * Moved error messages in here
12 *
13 * 07/12/98 (Rob Lake)
14 * Moved more error messages here.
15 *
16 * 30-Jul-1998 (John P Price <linux-guru@gcfl.net>)
17 * Added compile date to version.
18 *
19 * 26-Feb-1999 (Eric Kohl)
20 * Introduced a new version string.
21 * Thanks to Emanuele Aliberti!
22 */
23
24 #ifndef _CMD_H_INCLUDED_
25 #define _CMD_H_INCLUDED_
26
27 #include "config.h"
28
29 #include <windows.h>
30 #include <tchar.h>
31
32 #include "cmdver.h"
33
34 #include "cmddbg.h"
35
36 #define BREAK_BATCHFILE 1
37 #define BREAK_OUTOFBATCH 2
38 #define BREAK_INPUT 3
39 #define BREAK_IGNORE 4
40
41 /* define some error messages */
42
43 #define D_ON _T("on")
44 #define D_OFF _T("off")
45
46
47 /* command line buffer length */
48 #define CMDLINE_LENGTH 8192
49
50 /* 16k = max buffer size */
51 #define BUFF_SIZE 16384
52
53 /* global variables */
54 extern HANDLE hOut;
55 extern HANDLE hIn;
56 extern HANDLE hConsole;
57 extern WORD wColor;
58 extern WORD wDefColor;
59 extern BOOL bCtrlBreak;
60 extern BOOL bIgnoreEcho;
61 extern BOOL bExit;
62 extern INT nErrorLevel;
63 extern SHORT maxx;
64 extern SHORT maxy;
65 extern OSVERSIONINFO osvi;
66
67
68
69 /* Prototypes for ALIAS.C */
70 VOID ExpandAlias (LPTSTR, INT);
71 INT CommandAlias (LPTSTR);
72
73 /* Prototypes for ATTRIB.C */
74 INT CommandAttrib (LPTSTR);
75
76
77 /* Prototypes for BEEP.C */
78 INT cmd_beep (LPTSTR);
79
80
81 /* Prototypes for CALL.C */
82 INT cmd_call (LPTSTR);
83
84
85 /* Prototypes for CHCP.C */
86 INT CommandChcp (LPTSTR);
87
88
89 /* Prototypes for CHOICE.C */
90 INT CommandChoice (LPTSTR);
91
92
93 /* Prototypes for CLS.C */
94 INT cmd_cls (LPTSTR);
95
96
97 /* Prototypes for CMD.C */
98 INT ConvertULargeInteger (ULARGE_INTEGER num, LPTSTR des, INT len, BOOL bPutSeperator);
99 VOID ParseCommandLine (LPTSTR);
100 struct _PARSED_COMMAND;
101 BOOL ExecuteCommand(struct _PARSED_COMMAND *Cmd);
102 LPCTSTR GetEnvVarOrSpecial ( LPCTSTR varName );
103 VOID AddBreakHandler (VOID);
104 VOID RemoveBreakHandler (VOID);
105 BOOL SubstituteVars(TCHAR *Src, TCHAR *Dest, TCHAR Delim);
106 BOOL SubstituteForVars(TCHAR *Src, TCHAR *Dest);
107 LPTSTR DoDelayedExpansion(LPTSTR Line);
108 BOOL DoCommand (LPTSTR line, struct _PARSED_COMMAND *Cmd);
109 BOOL ReadLine(TCHAR *commandline, BOOL bMore);
110 int cmd_main (int argc, const TCHAR *argv[]);
111
112 extern HANDLE CMD_ModuleHandle;
113
114
115 /* Prototypes for CMDINPUT.C */
116 VOID ReadCommand (LPTSTR, INT);
117
118
119 /* Prototypes for CMDTABLE.C */
120 #define CMD_SPECIAL 1
121 #define CMD_BATCHONLY 2
122 #define CMD_HIDE 4
123
124 typedef struct tagCOMMAND
125 {
126 LPTSTR name;
127 INT flags;
128 INT (*func)(LPTSTR);
129 } COMMAND, *LPCOMMAND;
130
131 extern COMMAND cmds[]; /* The internal command table */
132
133 VOID PrintCommandList (VOID);
134 VOID PrintCommandListDetail (VOID);
135
136
137 LPCTSTR GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA );
138
139 /* Prototypes for COLOR.C */
140 VOID SetScreenColor(WORD wArgColor, BOOL bFill);
141 INT CommandColor (LPTSTR);
142
143 VOID ConInDummy (VOID);
144 VOID ConInDisable (VOID);
145 VOID ConInEnable (VOID);
146 VOID ConInFlush (VOID);
147 VOID ConInKey (PINPUT_RECORD);
148 VOID ConInString (LPTSTR, DWORD);
149
150 VOID ConOutChar (TCHAR);
151 VOID ConOutPuts (LPTSTR);
152 VOID ConOutPrintf (LPTSTR, ...);
153 INT ConOutPrintfPaging (BOOL NewPage, LPTSTR, ...);
154 VOID ConErrChar (TCHAR);
155 VOID ConErrPuts (LPTSTR);
156 VOID ConErrPrintf (LPTSTR, ...);
157 VOID ConOutFormatMessage (DWORD MessageId, ...);
158 VOID ConErrFormatMessage (DWORD MessageId, ...);
159
160 SHORT GetCursorX (VOID);
161 SHORT GetCursorY (VOID);
162 VOID GetCursorXY (PSHORT, PSHORT);
163 VOID SetCursorXY (SHORT, SHORT);
164
165 VOID GetScreenSize (PSHORT, PSHORT);
166 VOID SetCursorType (BOOL, BOOL);
167
168 VOID ConOutResPuts (UINT resID);
169 VOID ConErrResPuts (UINT resID);
170 VOID ConOutResPrintf (UINT resID, ...);
171 VOID ConErrResPrintf (UINT resID, ...);
172 VOID ConOutResPaging(BOOL NewPage, UINT resID);
173
174 /* Prototypes for COPY.C */
175 INT cmd_copy (LPTSTR);
176
177
178 /* Prototypes for DATE.C */
179 INT cmd_date (LPTSTR);
180
181
182 /* Prototypes for DEL.C */
183 INT CommandDelete (LPTSTR);
184
185
186 /* Prototypes for DELAY.C */
187 INT CommandDelay (LPTSTR);
188
189
190 /* Prototypes for DIR.C */
191 INT CommandDir (LPTSTR);
192
193
194 /* Prototypes for DIRSTACK.C */
195 VOID InitDirectoryStack (VOID);
196 VOID DestroyDirectoryStack (VOID);
197 INT GetDirectoryStackDepth (VOID);
198 INT CommandPushd (LPTSTR);
199 INT CommandPopd (LPTSTR);
200 INT CommandDirs (LPTSTR);
201
202
203 /* Prototypes for ECHO.C */
204 INT CommandEcho (LPTSTR);
205 INT CommandEchos (LPTSTR);
206 INT CommandEchoerr (LPTSTR);
207 INT CommandEchoserr (LPTSTR);
208
209
210 /* Prototypes for ERROR.C */
211 VOID ErrorMessage (DWORD, LPTSTR, ...);
212
213 VOID error_no_pipe (VOID);
214 VOID error_bad_command (VOID);
215 VOID error_invalid_drive (VOID);
216 VOID error_req_param_missing (VOID);
217 VOID error_sfile_not_found (LPTSTR);
218 VOID error_file_not_found (VOID);
219 VOID error_path_not_found (VOID);
220 VOID error_too_many_parameters (LPTSTR);
221 VOID error_parameter_format(TCHAR);
222 VOID error_invalid_switch (TCHAR);
223 VOID error_invalid_parameter_format (LPTSTR);
224 VOID error_out_of_memory (VOID);
225 VOID error_syntax (LPTSTR);
226
227 VOID msg_pause (VOID);
228
229
230 /* Prototypes for FILECOMP.C */
231 #ifdef FEATURE_UNIX_FILENAME_COMPLETION
232 VOID CompleteFilename (LPTSTR, UINT);
233 INT ShowCompletionMatches (LPTSTR, INT);
234 #endif
235 #ifdef FEATURE_4NT_FILENAME_COMPLETION
236 VOID CompleteFilename (LPTSTR, BOOL, LPTSTR, UINT);
237 #endif
238
239
240 /* Prototypes for FOR.C */
241 #define FOR_DIRS 1 /* /D */
242 #define FOR_F 2 /* /F */
243 #define FOR_LOOP 4 /* /L */
244 #define FOR_RECURSIVE 8 /* /R */
245 INT cmd_for (LPTSTR);
246 BOOL ExecuteFor(struct _PARSED_COMMAND *Cmd);
247
248
249 /* Prototypes for FREE.C */
250 INT CommandFree (LPTSTR);
251
252
253 /* Prototypes for GOTO.C */
254 INT cmd_goto (LPTSTR);
255
256
257 /* Prototypes for HISTORY.C */
258 #ifdef FEATURE_HISTORY
259 LPCTSTR PeekHistory(INT);
260 VOID History (INT, LPTSTR);/*add entries browse history*/
261 VOID History_move_to_bottom(VOID);/*F3*/
262 VOID InitHistory(VOID);
263 VOID CleanHistory(VOID);
264 VOID History_del_current_entry(LPTSTR str);/*CTRL-D*/
265 INT CommandHistory (LPTSTR param);
266 #endif
267
268
269 /* Prototypes for IF.C */
270 #define IFFLAG_NEGATE 1 /* NOT */
271 #define IFFLAG_IGNORECASE 2 /* /I */
272 enum { IF_CMDEXTVERSION, IF_DEFINED, IF_ERRORLEVEL, IF_EXIST,
273 IF_STRINGEQ, /* == */
274 IF_EQU, IF_GTR, IF_GEQ, IF_LSS, IF_LEQ, IF_NEQ };
275 BOOL ExecuteIf(struct _PARSED_COMMAND *Cmd);
276
277
278 /* Prototypes for INTERNAL.C */
279 VOID InitLastPath (VOID);
280 VOID FreeLastPath (VOID);
281 INT cmd_chdir (LPTSTR);
282 INT cmd_mkdir (LPTSTR);
283 INT cmd_rmdir (LPTSTR);
284 INT CommandExit (LPTSTR);
285 INT CommandRem (LPTSTR);
286 INT CommandShowCommands (LPTSTR);
287 INT CommandShowCommandsDetail (LPTSTR);
288
289 /* Prototypes for LABEL.C */
290 INT cmd_label (LPTSTR);
291
292
293 /* Prototypes for LOCALE.C */
294 extern TCHAR cDateSeparator;
295 extern INT nDateFormat;
296 extern TCHAR cTimeSeparator;
297 extern INT nTimeFormat;
298 extern TCHAR cThousandSeparator;
299 extern TCHAR cDecimalSeparator;
300 extern INT nNumberGroups;
301
302
303 VOID InitLocale (VOID);
304 VOID PrintDate (VOID);
305 VOID PrintTime (VOID);
306
307 /* cache codepage */
308 extern UINT InputCodePage;
309 extern UINT OutputCodePage;
310
311 /* Prototypes for MEMORY.C */
312 INT CommandMemory (LPTSTR);
313
314
315 /* Prototypes for MISC.C */
316 INT GetRootPath(TCHAR *InPath,TCHAR *OutPath,INT size);
317 BOOL SetRootPath(TCHAR *InPath);
318 TCHAR cgetchar (VOID);
319 BOOL CheckCtrlBreak (INT);
320 BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry);
321 LPTSTR *split (LPTSTR, LPINT, BOOL);
322 LPTSTR *splitspace (LPTSTR, LPINT);
323 VOID freep (LPTSTR *);
324 LPTSTR _stpcpy (LPTSTR, LPCTSTR);
325 VOID StripQuotes(LPTSTR);
326 BOOL IsValidPathName (LPCTSTR);
327 BOOL IsExistingFile (LPCTSTR);
328 BOOL IsExistingDirectory (LPCTSTR);
329 BOOL FileGetString (HANDLE, LPTSTR, INT);
330 VOID GetPathCase(TCHAR *, TCHAR *);
331
332 #define PROMPT_NO 0
333 #define PROMPT_YES 1
334 #define PROMPT_ALL 2
335 #define PROMPT_BREAK 3
336
337 INT PagePrompt (VOID);
338 INT FilePromptYN (UINT);
339 INT FilePromptYNA (UINT);
340
341
342 /* Prototypes for MOVE.C */
343 INT cmd_move (LPTSTR);
344
345
346 /* Prototypes for MSGBOX.C */
347 INT CommandMsgbox (LPTSTR);
348
349
350 /* Prototypes from PARSER.C */
351 enum { C_COMMAND, C_QUIET, C_BLOCK, C_MULTI, C_IFFAILURE, C_IFSUCCESS, C_PIPE, C_IF, C_FOR };
352 typedef struct _PARSED_COMMAND
353 {
354 struct _PARSED_COMMAND *Subcommands;
355 struct _PARSED_COMMAND *Next;
356 struct _REDIRECTION *Redirections;
357 BYTE Type;
358 union
359 {
360 struct
361 {
362 TCHAR *Tail;
363 TCHAR CommandLine[];
364 } Command;
365 struct
366 {
367 BYTE Flags;
368 BYTE Operator;
369 TCHAR *LeftArg;
370 TCHAR *RightArg;
371 } If;
372 struct
373 {
374 BYTE Switches;
375 TCHAR Variable;
376 LPTSTR Params;
377 LPTSTR List;
378 struct tagFORCONTEXT *Context;
379 } For;
380 };
381 } PARSED_COMMAND;
382 PARSED_COMMAND *ParseCommand(LPTSTR Line);
383 VOID EchoCommand(PARSED_COMMAND *Cmd);
384 VOID FreeCommand(PARSED_COMMAND *Cmd);
385
386
387 /* Prototypes from PATH.C */
388 INT cmd_path (LPTSTR);
389
390
391 /* Prototypes from PROMPT.C */
392 VOID PrintPrompt (VOID);
393 INT cmd_prompt (LPTSTR);
394
395
396 /* Prototypes for REDIR.C */
397 enum { REDIR_READ, REDIR_WRITE, REDIR_APPEND };
398 typedef struct _REDIRECTION
399 {
400 struct _REDIRECTION *Next;
401 HANDLE OldHandle;
402 BYTE Number;
403 BYTE Type;
404 TCHAR Filename[];
405 } REDIRECTION;
406 BOOL PerformRedirection(REDIRECTION *);
407 VOID UndoRedirection(REDIRECTION *, REDIRECTION *End);
408 INT GetRedirection(LPTSTR, REDIRECTION **);
409 VOID FreeRedirection(REDIRECTION *);
410
411
412 /* Prototypes for REN.C */
413 INT cmd_rename (LPTSTR);
414
415 /* Prototypes for REN.C */
416 INT cmd_replace (LPTSTR);
417
418 /* Prototypes for SCREEN.C */
419 INT CommandScreen (LPTSTR);
420
421
422 /* Prototypes for SET.C */
423 INT cmd_set (LPTSTR);
424
425 /* Prototypes for SETLOCAL.C */
426 INT cmd_setlocal (LPTSTR);
427 INT cmd_endlocal (LPTSTR);
428
429 /* Prototypes for START.C */
430 INT cmd_start (LPTSTR);
431
432
433 /* Prototypes for STRTOCLR.C */
434 BOOL StringToColor (LPWORD, LPTSTR *);
435
436
437 /* Prototypes for TIME.C */
438 INT cmd_time (LPTSTR);
439
440
441 /* Prototypes for TIMER.C */
442 INT CommandTimer (LPTSTR param);
443
444
445 /* Prototypes for TITLE.C */
446 INT cmd_title (LPTSTR);
447
448
449 /* Prototypes for TYPE.C */
450 INT cmd_type (LPTSTR);
451
452
453 /* Prototypes for VER.C */
454 VOID ShortVersion (VOID);
455 INT cmd_ver (LPTSTR);
456
457
458 /* Prototypes for VERIFY.C */
459 INT cmd_verify (LPTSTR);
460
461
462 /* Prototypes for VOL.C */
463 INT cmd_vol (LPTSTR);
464
465
466 /* Prototypes for WHERE.C */
467 BOOL SearchForExecutable (LPCTSTR, LPTSTR);
468
469 /* Prototypes for WINDOW.C */
470 INT CommandActivate (LPTSTR);
471 INT CommandWindow (LPTSTR);
472
473
474 /* The MSDOS Batch Commands [MS-DOS 5.0 User's Guide and Reference p359] */
475 int cmd_if(TCHAR *);
476 int cmd_pause(TCHAR *);
477 int cmd_shift(TCHAR *);
478
479 #endif /* _CMD_H_INCLUDED_ */