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