Separate batch file contexts and FOR contexts into two different structs, since they...
[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 SubstituteForVars(TCHAR *Src, TCHAR *Dest);
106 LPTSTR DoDelayedExpansion(LPTSTR Line);
107 BOOL DoCommand (LPTSTR line);
108 BOOL ReadLine(TCHAR *commandline, BOOL bMore);
109 int cmd_main (int argc, const TCHAR *argv[]);
110
111 extern HANDLE CMD_ModuleHandle;
112
113
114 /* Prototypes for CMDINPUT.C */
115 VOID ReadCommand (LPTSTR, INT);
116
117
118 /* Prototypes for CMDTABLE.C */
119 #define CMD_SPECIAL 1
120 #define CMD_BATCHONLY 2
121 #define CMD_HIDE 4
122
123 typedef struct tagCOMMAND
124 {
125 LPTSTR name;
126 INT flags;
127 INT (*func)(LPTSTR);
128 } COMMAND, *LPCOMMAND;
129
130 extern COMMAND cmds[]; /* The internal command table */
131
132 VOID PrintCommandList (VOID);
133 VOID PrintCommandListDetail (VOID);
134
135
136 LPCTSTR GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA );
137
138 /* Prototypes for COLOR.C */
139 VOID SetScreenColor(WORD wArgColor, BOOL bFill);
140 INT CommandColor (LPTSTR);
141
142 VOID ConInDummy (VOID);
143 VOID ConInDisable (VOID);
144 VOID ConInEnable (VOID);
145 VOID ConInFlush (VOID);
146 VOID ConInKey (PINPUT_RECORD);
147 VOID ConInString (LPTSTR, DWORD);
148
149 VOID ConOutChar (TCHAR);
150 VOID ConOutPuts (LPTSTR);
151 VOID ConOutPrintf (LPTSTR, ...);
152 INT ConOutPrintfPaging (BOOL NewPage, LPTSTR, ...);
153 VOID ConErrChar (TCHAR);
154 VOID ConErrPuts (LPTSTR);
155 VOID ConErrPrintf (LPTSTR, ...);
156 VOID ConOutFormatMessage (DWORD MessageId, ...);
157 VOID ConErrFormatMessage (DWORD MessageId, ...);
158
159 SHORT GetCursorX (VOID);
160 SHORT GetCursorY (VOID);
161 VOID GetCursorXY (PSHORT, PSHORT);
162 VOID SetCursorXY (SHORT, SHORT);
163
164 VOID GetScreenSize (PSHORT, PSHORT);
165 VOID SetCursorType (BOOL, BOOL);
166
167 VOID ConOutResPuts (UINT resID);
168 VOID ConErrResPuts (UINT resID);
169 VOID ConOutResPrintf (UINT resID, ...);
170 VOID ConErrResPrintf (UINT resID, ...);
171 VOID ConOutResPaging(BOOL NewPage, UINT resID);
172
173 /* Prototypes for COPY.C */
174 INT cmd_copy (LPTSTR);
175
176
177 /* Prototypes for DATE.C */
178 INT cmd_date (LPTSTR);
179
180
181 /* Prototypes for DEL.C */
182 INT CommandDelete (LPTSTR);
183
184
185 /* Prototypes for DELAY.C */
186 INT CommandDelay (LPTSTR);
187
188
189 /* Prototypes for DIR.C */
190 INT CommandDir (LPTSTR);
191
192
193 /* Prototypes for DIRSTACK.C */
194 VOID InitDirectoryStack (VOID);
195 VOID DestroyDirectoryStack (VOID);
196 INT GetDirectoryStackDepth (VOID);
197 INT CommandPushd (LPTSTR);
198 INT CommandPopd (LPTSTR);
199 INT CommandDirs (LPTSTR);
200
201
202 /* Prototypes for ECHO.C */
203 INT CommandEcho (LPTSTR);
204 INT CommandEchos (LPTSTR);
205 INT CommandEchoerr (LPTSTR);
206 INT CommandEchoserr (LPTSTR);
207
208
209 /* Prototypes for ERROR.C */
210 VOID ErrorMessage (DWORD, LPTSTR, ...);
211
212 VOID error_no_pipe (VOID);
213 VOID error_bad_command (VOID);
214 VOID error_invalid_drive (VOID);
215 VOID error_req_param_missing (VOID);
216 VOID error_sfile_not_found (LPTSTR);
217 VOID error_file_not_found (VOID);
218 VOID error_path_not_found (VOID);
219 VOID error_too_many_parameters (LPTSTR);
220 VOID error_parameter_format(TCHAR);
221 VOID error_invalid_switch (TCHAR);
222 VOID error_invalid_parameter_format (LPTSTR);
223 VOID error_out_of_memory (VOID);
224 VOID error_syntax (LPTSTR);
225
226 VOID msg_pause (VOID);
227
228
229 /* Prototypes for FILECOMP.C */
230 #ifdef FEATURE_UNIX_FILENAME_COMPLETION
231 VOID CompleteFilename (LPTSTR, UINT);
232 INT ShowCompletionMatches (LPTSTR, INT);
233 #endif
234 #ifdef FEATURE_4NT_FILENAME_COMPLETION
235 VOID CompleteFilename (LPTSTR, BOOL, LPTSTR, UINT);
236 #endif
237
238
239 /* Prototypes for FOR.C */
240 #define FOR_DIRS 1 /* /D */
241 #define FOR_F 2 /* /F */
242 #define FOR_LOOP 4 /* /L */
243 #define FOR_RECURSIVE 8 /* /R */
244 INT cmd_for (LPTSTR);
245 BOOL ExecuteFor(struct _PARSED_COMMAND *Cmd);
246
247
248 /* Prototypes for FREE.C */
249 INT CommandFree (LPTSTR);
250
251
252 /* Prototypes for GOTO.C */
253 INT cmd_goto (LPTSTR);
254
255
256 /* Prototypes for HISTORY.C */
257 #ifdef FEATURE_HISTORY
258 LPCTSTR PeekHistory(INT);
259 VOID History (INT, LPTSTR);/*add entries browse history*/
260 VOID History_move_to_bottom(VOID);/*F3*/
261 VOID InitHistory(VOID);
262 VOID CleanHistory(VOID);
263 VOID History_del_current_entry(LPTSTR str);/*CTRL-D*/
264 INT CommandHistory (LPTSTR param);
265 #endif
266
267
268 /* Prototypes for IF.C */
269 #define IFFLAG_NEGATE 1 /* NOT */
270 #define IFFLAG_IGNORECASE 2 /* /I */
271 enum { IF_CMDEXTVERSION, IF_DEFINED, IF_ERRORLEVEL, IF_EXIST,
272 IF_STRINGEQ, /* == */
273 IF_EQU, IF_GTR, IF_GEQ, IF_LSS, IF_LEQ, IF_NEQ };
274 BOOL ExecuteIf(struct _PARSED_COMMAND *Cmd);
275
276
277 /* Prototypes for INTERNAL.C */
278 VOID InitLastPath (VOID);
279 VOID FreeLastPath (VOID);
280 INT cmd_chdir (LPTSTR);
281 INT cmd_mkdir (LPTSTR);
282 INT cmd_rmdir (LPTSTR);
283 INT CommandExit (LPTSTR);
284 INT CommandRem (LPTSTR);
285 INT CommandShowCommands (LPTSTR);
286 INT CommandShowCommandsDetail (LPTSTR);
287
288 /* Prototypes for LABEL.C */
289 INT cmd_label (LPTSTR);
290
291
292 /* Prototypes for LOCALE.C */
293 extern TCHAR cDateSeparator;
294 extern INT nDateFormat;
295 extern TCHAR cTimeSeparator;
296 extern INT nTimeFormat;
297 extern TCHAR cThousandSeparator;
298 extern TCHAR cDecimalSeparator;
299 extern INT nNumberGroups;
300
301
302 VOID InitLocale (VOID);
303 VOID PrintDate (VOID);
304 VOID PrintTime (VOID);
305
306 /* cache codepage */
307 extern UINT InputCodePage;
308 extern UINT OutputCodePage;
309
310 /* Prototypes for MEMORY.C */
311 INT CommandMemory (LPTSTR);
312
313
314 /* Prototypes for MISC.C */
315 INT GetRootPath(TCHAR *InPath,TCHAR *OutPath,INT size);
316 BOOL SetRootPath(TCHAR *InPath);
317 TCHAR cgetchar (VOID);
318 BOOL CheckCtrlBreak (INT);
319 BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry);
320 LPTSTR *split (LPTSTR, LPINT, BOOL);
321 LPTSTR *splitspace (LPTSTR, LPINT);
322 VOID freep (LPTSTR *);
323 LPTSTR _stpcpy (LPTSTR, LPCTSTR);
324 VOID StripQuotes(LPTSTR);
325 BOOL IsValidPathName (LPCTSTR);
326 BOOL IsExistingFile (LPCTSTR);
327 BOOL IsExistingDirectory (LPCTSTR);
328 BOOL FileGetString (HANDLE, LPTSTR, INT);
329 VOID GetPathCase(TCHAR *, TCHAR *);
330
331 #define PROMPT_NO 0
332 #define PROMPT_YES 1
333 #define PROMPT_ALL 2
334 #define PROMPT_BREAK 3
335
336 INT PagePrompt (VOID);
337 INT FilePromptYN (UINT);
338 INT FilePromptYNA (UINT);
339
340
341 /* Prototypes for MOVE.C */
342 INT cmd_move (LPTSTR);
343
344
345 /* Prototypes for MSGBOX.C */
346 INT CommandMsgbox (LPTSTR);
347
348
349 /* Prototypes from PARSER.C */
350 enum { C_COMMAND, C_QUIET, C_BLOCK, C_MULTI, C_IFFAILURE, C_IFSUCCESS, C_PIPE, C_IF, C_FOR };
351 typedef struct _PARSED_COMMAND
352 {
353 struct _PARSED_COMMAND *Subcommands;
354 struct _PARSED_COMMAND *Next;
355 struct _REDIRECTION *Redirections;
356 BYTE Type;
357 union
358 {
359 struct
360 {
361 TCHAR *Tail;
362 TCHAR CommandLine[];
363 } Command;
364 struct
365 {
366 BYTE Flags;
367 BYTE Operator;
368 TCHAR *LeftArg;
369 TCHAR *RightArg;
370 } If;
371 struct
372 {
373 BYTE Switches;
374 TCHAR Variable;
375 LPTSTR Params;
376 LPTSTR List;
377 struct tagFORCONTEXT *Context;
378 } For;
379 };
380 } PARSED_COMMAND;
381 PARSED_COMMAND *ParseCommand(LPTSTR Line);
382 VOID EchoCommand(PARSED_COMMAND *Cmd);
383 VOID FreeCommand(PARSED_COMMAND *Cmd);
384
385
386 /* Prototypes from PATH.C */
387 INT cmd_path (LPTSTR);
388
389
390 /* Prototypes from PROMPT.C */
391 VOID PrintPrompt (VOID);
392 INT cmd_prompt (LPTSTR);
393
394
395 /* Prototypes for REDIR.C */
396 enum { REDIR_READ, REDIR_WRITE, REDIR_APPEND };
397 typedef struct _REDIRECTION
398 {
399 struct _REDIRECTION *Next;
400 HANDLE OldHandle;
401 BYTE Number;
402 BYTE Type;
403 TCHAR Filename[];
404 } REDIRECTION;
405 BOOL PerformRedirection(REDIRECTION *);
406 VOID UndoRedirection(REDIRECTION *, REDIRECTION *End);
407 INT GetRedirection(LPTSTR, REDIRECTION **);
408 VOID FreeRedirection(REDIRECTION *);
409
410
411 /* Prototypes for REN.C */
412 INT cmd_rename (LPTSTR);
413
414 /* Prototypes for REN.C */
415 INT cmd_replace (LPTSTR);
416
417 /* Prototypes for SCREEN.C */
418 INT CommandScreen (LPTSTR);
419
420
421 /* Prototypes for SET.C */
422 INT cmd_set (LPTSTR);
423
424 /* Prototypes for SETLOCAL.C */
425 INT cmd_setlocal (LPTSTR);
426 INT cmd_endlocal (LPTSTR);
427
428 /* Prototypes for START.C */
429 INT cmd_start (LPTSTR);
430
431
432 /* Prototypes for STRTOCLR.C */
433 BOOL StringToColor (LPWORD, LPTSTR *);
434
435
436 /* Prototypes for TIME.C */
437 INT cmd_time (LPTSTR);
438
439
440 /* Prototypes for TIMER.C */
441 INT CommandTimer (LPTSTR param);
442
443
444 /* Prototypes for TITLE.C */
445 INT cmd_title (LPTSTR);
446
447
448 /* Prototypes for TYPE.C */
449 INT cmd_type (LPTSTR);
450
451
452 /* Prototypes for VER.C */
453 VOID ShortVersion (VOID);
454 INT cmd_ver (LPTSTR);
455
456
457 /* Prototypes for VERIFY.C */
458 INT cmd_verify (LPTSTR);
459
460
461 /* Prototypes for VOL.C */
462 INT cmd_vol (LPTSTR);
463
464
465 /* Prototypes for WHERE.C */
466 BOOL SearchForExecutable (LPCTSTR, LPTSTR);
467
468 /* Prototypes for WINDOW.C */
469 INT CommandActivate (LPTSTR);
470 INT CommandWindow (LPTSTR);
471
472
473 /* The MSDOS Batch Commands [MS-DOS 5.0 User's Guide and Reference p359] */
474 int cmd_if(TCHAR *);
475 int cmd_pause(TCHAR *);
476 int cmd_shift(TCHAR *);
477
478 #endif /* _CMD_H_INCLUDED_ */