- Sync with trunk r58248 to bring the latest changes from Amine (headers) and others...
[reactos.git] / 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 int cmd_main (int argc, const TCHAR *argv[]);
118
119 extern HANDLE CMD_ModuleHandle;
120
121
122 /* Prototypes for CMDINPUT.C */
123 BOOL ReadCommand (LPTSTR, INT);
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 VOID PrintCommandListDetail (VOID);
142
143
144 LPCTSTR GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA );
145
146 /* Prototypes for COLOR.C */
147 VOID SetScreenColor(WORD wArgColor, BOOL bFill);
148 INT CommandColor (LPTSTR);
149
150 VOID ConInDummy (VOID);
151 VOID ConInDisable (VOID);
152 VOID ConInEnable (VOID);
153 VOID ConInFlush (VOID);
154 VOID ConInKey (PINPUT_RECORD);
155 VOID ConInString (LPTSTR, DWORD);
156
157 VOID ConOutChar (TCHAR);
158 VOID ConOutPuts (LPTSTR);
159 VOID ConPrintf(LPTSTR, va_list, DWORD);
160 INT ConPrintfPaging(BOOL NewPage, LPTSTR, va_list, DWORD);
161 VOID ConOutPrintf (LPTSTR, ...);
162 INT ConOutPrintfPaging (BOOL NewPage, LPTSTR, ...);
163 VOID ConErrChar (TCHAR);
164 VOID ConErrPuts (LPTSTR);
165 VOID ConErrPrintf (LPTSTR, ...);
166 VOID ConOutFormatMessage (DWORD MessageId, ...);
167 VOID ConErrFormatMessage (DWORD MessageId, ...);
168
169 SHORT GetCursorX (VOID);
170 SHORT GetCursorY (VOID);
171 VOID GetCursorXY (PSHORT, PSHORT);
172 VOID SetCursorXY (SHORT, SHORT);
173
174 VOID GetScreenSize (PSHORT, PSHORT);
175 VOID SetCursorType (BOOL, BOOL);
176
177 VOID ConOutResPuts (UINT resID);
178 VOID ConErrResPuts (UINT resID);
179 VOID ConOutResPrintf (UINT resID, ...);
180 VOID ConErrResPrintf (UINT resID, ...);
181 VOID ConOutResPaging(BOOL NewPage, UINT resID);
182
183 /* Prototypes for COPY.C */
184 INT cmd_copy (LPTSTR);
185
186
187 /* Prototypes for DATE.C */
188 INT cmd_date (LPTSTR);
189
190
191 /* Prototypes for DEL.C */
192 INT CommandDelete (LPTSTR);
193
194
195 /* Prototypes for DELAY.C */
196 INT CommandDelay (LPTSTR);
197
198
199 /* Prototypes for DIR.C */
200 INT FormatDate (TCHAR *, LPSYSTEMTIME, BOOL);
201 INT FormatTime (TCHAR *, LPSYSTEMTIME);
202 INT CommandDir (LPTSTR);
203
204
205 /* Prototypes for DIRSTACK.C */
206 VOID InitDirectoryStack (VOID);
207 VOID DestroyDirectoryStack (VOID);
208 INT GetDirectoryStackDepth (VOID);
209 INT CommandPushd (LPTSTR);
210 INT CommandPopd (LPTSTR);
211 INT CommandDirs (LPTSTR);
212
213
214 /* Prototypes for ECHO.C */
215 BOOL OnOffCommand(LPTSTR param, LPBOOL flag, INT message);
216 INT CommandEcho (LPTSTR);
217 INT CommandEchos (LPTSTR);
218 INT CommandEchoerr (LPTSTR);
219 INT CommandEchoserr (LPTSTR);
220
221
222 /* Prototypes for ERROR.C */
223 VOID ErrorMessage (DWORD, LPTSTR, ...);
224
225 VOID error_no_pipe (VOID);
226 VOID error_bad_command (LPTSTR);
227 VOID error_invalid_drive (VOID);
228 VOID error_req_param_missing (VOID);
229 VOID error_sfile_not_found (LPTSTR);
230 VOID error_file_not_found (VOID);
231 VOID error_path_not_found (VOID);
232 VOID error_too_many_parameters (LPTSTR);
233 VOID error_parameter_format(TCHAR);
234 VOID error_invalid_switch (TCHAR);
235 VOID error_invalid_parameter_format (LPTSTR);
236 VOID error_out_of_memory (VOID);
237 VOID error_syntax (LPTSTR);
238
239 VOID msg_pause (VOID);
240
241
242 /* Prototypes for FILECOMP.C */
243 #ifdef FEATURE_UNIX_FILENAME_COMPLETION
244 VOID CompleteFilename (LPTSTR, UINT);
245 INT ShowCompletionMatches (LPTSTR, INT);
246 #endif
247 #ifdef FEATURE_4NT_FILENAME_COMPLETION
248 VOID CompleteFilename (LPTSTR, BOOL, LPTSTR, UINT);
249 #endif
250
251
252 /* Prototypes for FOR.C */
253 #define FOR_DIRS 1 /* /D */
254 #define FOR_F 2 /* /F */
255 #define FOR_LOOP 4 /* /L */
256 #define FOR_RECURSIVE 8 /* /R */
257 INT cmd_for (LPTSTR);
258 INT ExecuteFor(struct _PARSED_COMMAND *Cmd);
259
260
261 /* Prototypes for FREE.C */
262 INT CommandFree (LPTSTR);
263
264
265 /* Prototypes for GOTO.C */
266 INT cmd_goto (LPTSTR);
267
268
269 /* Prototypes for HISTORY.C */
270 #ifdef FEATURE_HISTORY
271 LPCTSTR PeekHistory(INT);
272 VOID History (INT, LPTSTR);/*add entries browse history*/
273 VOID History_move_to_bottom(VOID);/*F3*/
274 VOID InitHistory(VOID);
275 VOID CleanHistory(VOID);
276 VOID History_del_current_entry(LPTSTR str);/*CTRL-D*/
277 INT CommandHistory (LPTSTR param);
278 #endif
279
280
281 /* Prototypes for IF.C */
282 #define IFFLAG_NEGATE 1 /* NOT */
283 #define IFFLAG_IGNORECASE 2 /* /I */
284 enum { IF_CMDEXTVERSION, IF_DEFINED, IF_ERRORLEVEL, IF_EXIST,
285 IF_STRINGEQ, /* == */
286 IF_EQU, IF_GTR, IF_GEQ, IF_LSS, IF_LEQ, IF_NEQ };
287 INT ExecuteIf(struct _PARSED_COMMAND *Cmd);
288
289
290 /* Prototypes for INTERNAL.C */
291 VOID InitLastPath (VOID);
292 VOID FreeLastPath (VOID);
293 INT cmd_chdir (LPTSTR);
294 INT cmd_mkdir (LPTSTR);
295 INT cmd_rmdir (LPTSTR);
296 INT CommandExit (LPTSTR);
297 INT CommandRem (LPTSTR);
298 INT CommandShowCommands (LPTSTR);
299 INT CommandShowCommandsDetail (LPTSTR);
300
301 /* Prototypes for LABEL.C */
302 INT cmd_label (LPTSTR);
303
304
305 /* Prototypes for LOCALE.C */
306 extern TCHAR cDateSeparator;
307 extern INT nDateFormat;
308 extern TCHAR cTimeSeparator;
309 extern INT nTimeFormat;
310 extern TCHAR cThousandSeparator;
311 extern TCHAR cDecimalSeparator;
312 extern INT nNumberGroups;
313
314
315 VOID InitLocale (VOID);
316 LPTSTR GetDateString (VOID);
317 LPTSTR GetTimeString (VOID);
318
319 /* cache codepage */
320 extern UINT InputCodePage;
321 extern UINT OutputCodePage;
322
323 /* Prototypes for MEMORY.C */
324 INT CommandMemory (LPTSTR);
325
326
327 /* Prototypes for MKLINK.C */
328 INT cmd_mklink(LPTSTR);
329
330
331 /* Prototypes for MISC.C */
332 INT GetRootPath(TCHAR *InPath,TCHAR *OutPath,INT size);
333 BOOL SetRootPath(TCHAR *oldpath,TCHAR *InPath);
334 TCHAR cgetchar (VOID);
335 BOOL CheckCtrlBreak (INT);
336 BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry);
337 LPTSTR *split (LPTSTR, LPINT, BOOL, BOOL);
338 LPTSTR *splitspace (LPTSTR, LPINT);
339 VOID freep (LPTSTR *);
340 LPTSTR _stpcpy (LPTSTR, LPCTSTR);
341 VOID StripQuotes(LPTSTR);
342 BOOL IsValidPathName (LPCTSTR);
343 BOOL IsExistingFile (LPCTSTR);
344 BOOL IsExistingDirectory (LPCTSTR);
345 BOOL FileGetString (HANDLE, LPTSTR, INT);
346 VOID GetPathCase(TCHAR *, TCHAR *);
347
348 #define PROMPT_NO 0
349 #define PROMPT_YES 1
350 #define PROMPT_ALL 2
351 #define PROMPT_BREAK 3
352
353 INT PagePrompt (VOID);
354 INT FilePromptYN (UINT);
355 INT FilePromptYNA (UINT);
356
357
358 /* Prototypes for MOVE.C */
359 INT cmd_move (LPTSTR);
360
361
362 /* Prototypes for MSGBOX.C */
363 INT CommandMsgbox (LPTSTR);
364
365
366 /* Prototypes from PARSER.C */
367 enum { C_COMMAND, C_QUIET, C_BLOCK, C_MULTI, C_IFFAILURE, C_IFSUCCESS, C_PIPE, C_IF, C_FOR };
368 typedef struct _PARSED_COMMAND
369 {
370 struct _PARSED_COMMAND *Subcommands;
371 struct _PARSED_COMMAND *Next;
372 struct _REDIRECTION *Redirections;
373 BYTE Type;
374 union
375 {
376 struct
377 {
378 TCHAR *Rest;
379 TCHAR First[];
380 } Command;
381 struct
382 {
383 BYTE Flags;
384 BYTE Operator;
385 TCHAR *LeftArg;
386 TCHAR *RightArg;
387 } If;
388 struct
389 {
390 BYTE Switches;
391 TCHAR Variable;
392 LPTSTR Params;
393 LPTSTR List;
394 struct tagFORCONTEXT *Context;
395 } For;
396 };
397 } PARSED_COMMAND;
398 PARSED_COMMAND *ParseCommand(LPTSTR Line);
399 VOID EchoCommand(PARSED_COMMAND *Cmd);
400 TCHAR *Unparse(PARSED_COMMAND *Cmd, TCHAR *Out, TCHAR *OutEnd);
401 VOID FreeCommand(PARSED_COMMAND *Cmd);
402
403
404 /* Prototypes from PATH.C */
405 INT cmd_path (LPTSTR);
406
407
408 /* Prototypes from PROMPT.C */
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 *);