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