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