ce220330692b8ca33ecd6094558a6d884ae1e269
[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 hIn;
56 extern LPTSTR lpOriginalEnvironment;
57 extern WORD wColor;
58 extern WORD wDefColor;
59 extern BOOL bCtrlBreak;
60 extern BOOL bIgnoreEcho;
61 extern BOOL bExit;
62 extern BOOL bDisableBatchEcho;
63 extern BOOL bEnableExtensions;
64 extern BOOL bDelayedExpansion;
65 extern INT nErrorLevel;
66 extern SHORT maxx;
67 extern SHORT maxy;
68 extern BOOL bUnicodeOutput;
69
70
71 /* Prototypes for ALIAS.C */
72 VOID ExpandAlias (LPTSTR, INT);
73 INT CommandAlias (LPTSTR);
74
75 /* Prototypes for ASSOC.C */
76 INT CommandAssoc (LPTSTR);
77
78 /* Prototypes for ATTRIB.C */
79 INT CommandAttrib (LPTSTR);
80
81
82 /* Prototypes for BEEP.C */
83 INT cmd_beep (LPTSTR);
84
85
86 /* Prototypes for CALL.C */
87 INT cmd_call (LPTSTR);
88
89
90 /* Prototypes for CHOICE.C */
91 INT CommandChoice (LPTSTR);
92
93
94 /* Prototypes for CLS.C */
95 INT cmd_cls (LPTSTR);
96
97
98 /* Prototypes for CMD.C */
99 INT ConvertULargeInteger(ULONGLONG num, LPTSTR des, UINT len, BOOL bPutSeparator);
100 HANDLE RunFile(DWORD, LPTSTR, LPTSTR, LPTSTR, INT);
101 INT ParseCommandLine(LPTSTR);
102 struct _PARSED_COMMAND;
103 INT ExecuteCommand(struct _PARSED_COMMAND *Cmd);
104 LPCTSTR GetEnvVarOrSpecial ( LPCTSTR varName );
105 VOID AddBreakHandler (VOID);
106 VOID RemoveBreakHandler (VOID);
107 BOOL SubstituteVars(TCHAR *Src, TCHAR *Dest, TCHAR Delim);
108 BOOL SubstituteForVars(TCHAR *Src, TCHAR *Dest);
109 LPTSTR DoDelayedExpansion(LPTSTR Line);
110 INT DoCommand(LPTSTR first, LPTSTR rest, struct _PARSED_COMMAND *Cmd);
111 BOOL ReadLine(TCHAR *commandline, BOOL bMore);
112
113 extern HANDLE CMD_ModuleHandle;
114
115
116 /* Prototypes for CMDINPUT.C */
117 BOOL ReadCommand (LPTSTR, INT);
118
119 extern TCHAR AutoCompletionChar;
120 extern TCHAR PathCompletionChar;
121
122 #define IS_COMPLETION_DISABLED(CompletionCtrl) \
123 ((CompletionCtrl) == 0x00 || (CompletionCtrl) == 0x0D || (CompletionCtrl) >= 0x20)
124
125
126 /* Prototypes for CMDTABLE.C */
127 #define CMD_SPECIAL 1
128 #define CMD_BATCHONLY 2
129 #define CMD_HIDE 4
130
131 typedef struct tagCOMMAND
132 {
133 LPTSTR name;
134 INT flags;
135 INT (*func)(LPTSTR);
136 } COMMAND, *LPCOMMAND;
137
138 extern COMMAND cmds[]; /* The internal command table */
139
140 VOID PrintCommandList (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
299 /* Prototypes for LABEL.C */
300 INT cmd_label (LPTSTR);
301
302
303 /* Prototypes for LOCALE.C */
304 extern TCHAR cDateSeparator;
305 extern INT nDateFormat;
306 extern TCHAR cTimeSeparator;
307 extern INT nTimeFormat;
308 extern TCHAR cThousandSeparator;
309 extern TCHAR cDecimalSeparator;
310 extern INT nNumberGroups;
311
312
313 VOID InitLocale (VOID);
314 LPTSTR GetDateString (VOID);
315 LPTSTR GetTimeString (VOID);
316
317 /* cache codepage */
318 extern UINT InputCodePage;
319 extern UINT OutputCodePage;
320
321 /* Prototypes for MEMORY.C */
322 INT CommandMemory (LPTSTR);
323
324
325 /* Prototypes for MKLINK.C */
326 INT cmd_mklink(LPTSTR);
327
328
329 /* Prototypes for MISC.C */
330 INT GetRootPath(TCHAR *InPath,TCHAR *OutPath,INT size);
331 BOOL SetRootPath(TCHAR *oldpath,TCHAR *InPath);
332 TCHAR cgetchar (VOID);
333 BOOL CheckCtrlBreak (INT);
334 BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry);
335 LPTSTR *split (LPTSTR, LPINT, BOOL, BOOL);
336 LPTSTR *splitspace (LPTSTR, LPINT);
337 VOID freep (LPTSTR *);
338 LPTSTR _stpcpy (LPTSTR, LPCTSTR);
339 VOID StripQuotes(LPTSTR);
340 BOOL IsValidPathName (LPCTSTR);
341 BOOL IsExistingFile (LPCTSTR);
342 BOOL IsExistingDirectory (LPCTSTR);
343 BOOL FileGetString (HANDLE, LPTSTR, INT);
344 VOID GetPathCase(TCHAR *, TCHAR *);
345
346 #define PROMPT_NO 0
347 #define PROMPT_YES 1
348 #define PROMPT_ALL 2
349 #define PROMPT_BREAK 3
350
351 INT PagePrompt (VOID);
352 INT FilePromptYN (UINT);
353 INT FilePromptYNA (UINT);
354
355
356 /* Prototypes for MOVE.C */
357 INT cmd_move (LPTSTR);
358
359
360 /* Prototypes for MSGBOX.C */
361 INT CommandMsgbox (LPTSTR);
362
363
364 /* Prototypes from PARSER.C */
365 enum { C_COMMAND, C_QUIET, C_BLOCK, C_MULTI, C_IFFAILURE, C_IFSUCCESS, C_PIPE, C_IF, C_FOR };
366 typedef struct _PARSED_COMMAND
367 {
368 struct _PARSED_COMMAND *Subcommands;
369 struct _PARSED_COMMAND *Next;
370 struct _REDIRECTION *Redirections;
371 BYTE Type;
372 union
373 {
374 struct
375 {
376 TCHAR *Rest;
377 TCHAR First[];
378 } Command;
379 struct
380 {
381 BYTE Flags;
382 BYTE Operator;
383 TCHAR *LeftArg;
384 TCHAR *RightArg;
385 } If;
386 struct
387 {
388 BYTE Switches;
389 TCHAR Variable;
390 LPTSTR Params;
391 LPTSTR List;
392 struct tagFORCONTEXT *Context;
393 } For;
394 };
395 } PARSED_COMMAND;
396 PARSED_COMMAND *ParseCommand(LPTSTR Line);
397 VOID EchoCommand(PARSED_COMMAND *Cmd);
398 TCHAR *Unparse(PARSED_COMMAND *Cmd, TCHAR *Out, TCHAR *OutEnd);
399 VOID FreeCommand(PARSED_COMMAND *Cmd);
400
401
402 /* Prototypes from PATH.C */
403 INT cmd_path (LPTSTR);
404
405
406 /* Prototypes from PROMPT.C */
407 VOID InitPrompt (VOID);
408 VOID PrintPrompt (VOID);
409 INT cmd_prompt (LPTSTR);
410
411
412 /* Prototypes for REDIR.C */
413 typedef enum _REDIR_MODE
414 {
415 REDIR_READ = 0,
416 REDIR_WRITE = 1,
417 REDIR_APPEND = 2
418 } REDIR_MODE;
419 typedef struct _REDIRECTION
420 {
421 struct _REDIRECTION *Next;
422 HANDLE OldHandle;
423 BYTE Number;
424 REDIR_MODE Mode;
425 TCHAR Filename[];
426 } REDIRECTION;
427 BOOL PerformRedirection(REDIRECTION *);
428 VOID UndoRedirection(REDIRECTION *, REDIRECTION *End);
429 INT GetRedirection(LPTSTR, REDIRECTION **);
430 VOID FreeRedirection(REDIRECTION *);
431
432
433 /* Prototypes for REN.C */
434 INT cmd_rename (LPTSTR);
435
436 /* Prototypes for REN.C */
437 INT cmd_replace (LPTSTR);
438
439 /* Prototypes for SCREEN.C */
440 INT CommandScreen (LPTSTR);
441
442
443 /* Prototypes for SET.C */
444 INT cmd_set (LPTSTR);
445
446 /* Prototypes for SETLOCAL.C */
447 LPTSTR DuplicateEnvironment(VOID);
448 INT cmd_setlocal (LPTSTR);
449 INT cmd_endlocal (LPTSTR);
450
451 /* Prototypes for START.C */
452 INT cmd_start (LPTSTR);
453
454
455 /* Prototypes for STRTOCLR.C */
456 BOOL StringToColor (LPWORD, LPTSTR *);
457
458
459 /* Prototypes for TIME.C */
460 INT cmd_time (LPTSTR);
461
462
463 /* Prototypes for TIMER.C */
464 INT CommandTimer (LPTSTR param);
465
466
467 /* Prototypes for TITLE.C */
468 INT cmd_title (LPTSTR);
469
470
471 /* Prototypes for TYPE.C */
472 INT cmd_type (LPTSTR);
473
474
475 /* Prototypes for VER.C */
476 VOID InitOSVersion(VOID);
477 VOID PrintOSVersion(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 *);