[CMD]
[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 <windows.h>
29 #include <tchar.h>
30
31 #include "cmdver.h"
32
33 #include "cmddbg.h"
34
35 #define BREAK_BATCHFILE 1
36 #define BREAK_OUTOFBATCH 2
37 #define BREAK_INPUT 3
38 #define BREAK_IGNORE 4
39
40 /* define some error messages */
41
42 #define D_ON _T("on")
43 #define D_OFF _T("off")
44
45
46 /* command line buffer length */
47 #define CMDLINE_LENGTH 8192
48
49 /* 16k = max buffer size */
50 #define BUFF_SIZE 16384
51
52 /* global variables */
53 extern HANDLE hOut;
54 extern HANDLE hIn;
55 extern LPTSTR lpOriginalEnvironment;
56 extern WORD wColor;
57 extern WORD wDefColor;
58 extern BOOL bCtrlBreak;
59 extern BOOL bIgnoreEcho;
60 extern BOOL bExit;
61 extern BOOL bDisableBatchEcho;
62 extern BOOL bDelayedExpansion;
63 extern INT nErrorLevel;
64 extern SHORT maxx;
65 extern SHORT maxy;
66 extern OSVERSIONINFO osvi;
67 extern BOOL bUnicodeOutput;
68
69
70 /* Prototypes for ALIAS.C */
71 VOID ExpandAlias (LPTSTR, INT);
72 INT CommandAlias (LPTSTR);
73
74 /* Prototypes for ASSOC.C */
75 INT CommandAssoc (LPTSTR);
76
77 /* Prototypes for ATTRIB.C */
78 INT CommandAttrib (LPTSTR);
79
80
81 /* Prototypes for BEEP.C */
82 INT cmd_beep (LPTSTR);
83
84
85 /* Prototypes for CALL.C */
86 INT cmd_call (LPTSTR);
87
88
89 /* Prototypes for CHCP.C */
90 INT CommandChcp (LPTSTR);
91
92
93 /* Prototypes for CHOICE.C */
94 INT CommandChoice (LPTSTR);
95
96
97 /* Prototypes for CLS.C */
98 INT cmd_cls (LPTSTR);
99
100
101 /* Prototypes for CMD.C */
102 INT ConvertULargeInteger(ULONGLONG num, LPTSTR des, UINT len, BOOL bPutSeperator);
103 HANDLE RunFile(DWORD, LPTSTR, LPTSTR, LPTSTR, INT);
104 INT ParseCommandLine(LPTSTR);
105 struct _PARSED_COMMAND;
106 INT ExecuteCommand(struct _PARSED_COMMAND *Cmd);
107 LPCTSTR GetEnvVarOrSpecial ( LPCTSTR varName );
108 VOID AddBreakHandler (VOID);
109 VOID RemoveBreakHandler (VOID);
110 BOOL SubstituteVars(TCHAR *Src, TCHAR *Dest, TCHAR Delim);
111 BOOL SubstituteForVars(TCHAR *Src, TCHAR *Dest);
112 LPTSTR DoDelayedExpansion(LPTSTR Line);
113 INT DoCommand(LPTSTR first, LPTSTR rest, struct _PARSED_COMMAND *Cmd);
114 BOOL ReadLine(TCHAR *commandline, BOOL bMore);
115 int cmd_main (int argc, const TCHAR *argv[]);
116
117 extern HANDLE CMD_ModuleHandle;
118
119
120 /* Prototypes for CMDINPUT.C */
121 BOOL ReadCommand (LPTSTR, INT);
122
123
124 /* Prototypes for CMDTABLE.C */
125 #define CMD_SPECIAL 1
126 #define CMD_BATCHONLY 2
127 #define CMD_HIDE 4
128
129 typedef struct tagCOMMAND
130 {
131 LPTSTR name;
132 INT flags;
133 INT (*func)(LPTSTR);
134 } COMMAND, *LPCOMMAND;
135
136 extern COMMAND cmds[]; /* The internal command table */
137
138 VOID PrintCommandList (VOID);
139 VOID PrintCommandListDetail (VOID);
140
141
142 LPCTSTR GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA );
143
144 /* Prototypes for COLOR.C */
145 VOID SetScreenColor(WORD wArgColor, BOOL bFill);
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 INT CommandShowCommandsDetail (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 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 *);