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