a0c7b56d52557ee6c6a3103ed7d7334c259d6ec7
[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 #define D_ON _T("on")
44 #define D_OFF _T("off")
45
46
47 /* command line buffer length */
48 #define CMDLINE_LENGTH 8192
49
50 /* 16k = max buffer size */
51 #define BUFF_SIZE 16384
52
53 /* Global variables */
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 bEnableExtensions;
63 extern BOOL bDelayedExpansion;
64 extern INT nErrorLevel;
65 extern SHORT maxx;
66 extern SHORT maxy;
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 /* Prototypes for BEEP.C */
81 INT cmd_beep (LPTSTR);
82
83 /* Prototypes for CALL.C */
84 INT cmd_call (LPTSTR);
85
86
87 /* Prototypes for CHOICE.C */
88 INT CommandChoice (LPTSTR);
89
90 /* Prototypes for CLS.C */
91 INT cmd_cls (LPTSTR);
92
93 /* Prototypes for CMD.C */
94 INT ConvertULargeInteger(ULONGLONG num, LPTSTR des, UINT len, BOOL bPutSeparator);
95 HANDLE RunFile(DWORD, LPTSTR, LPTSTR, LPTSTR, INT);
96 INT ParseCommandLine(LPTSTR);
97 struct _PARSED_COMMAND;
98 INT ExecuteCommand(struct _PARSED_COMMAND *Cmd);
99 LPCTSTR GetEnvVarOrSpecial ( LPCTSTR varName );
100 VOID AddBreakHandler (VOID);
101 VOID RemoveBreakHandler (VOID);
102 BOOL SubstituteVars(TCHAR *Src, TCHAR *Dest, TCHAR Delim);
103 BOOL SubstituteForVars(TCHAR *Src, TCHAR *Dest);
104 LPTSTR DoDelayedExpansion(LPTSTR Line);
105 INT DoCommand(LPTSTR first, LPTSTR rest, struct _PARSED_COMMAND *Cmd);
106 BOOL ReadLine(TCHAR *commandline, BOOL bMore);
107
108 extern HANDLE CMD_ModuleHandle;
109
110
111 /* Prototypes for CMDINPUT.C */
112 BOOL ReadCommand (LPTSTR, INT);
113
114 extern TCHAR AutoCompletionChar;
115 extern TCHAR PathCompletionChar;
116
117 #define IS_COMPLETION_DISABLED(CompletionCtrl) \
118 ((CompletionCtrl) == 0x00 || (CompletionCtrl) == 0x0D || (CompletionCtrl) >= 0x20)
119
120
121 /* Prototypes for CMDTABLE.C */
122 #define CMD_SPECIAL 1
123 #define CMD_BATCHONLY 2
124 #define CMD_HIDE 4
125
126 typedef struct tagCOMMAND
127 {
128 LPTSTR name;
129 INT flags;
130 INT (*func)(LPTSTR);
131 } COMMAND, *LPCOMMAND;
132
133 extern COMMAND cmds[]; /* The internal command table */
134
135 VOID PrintCommandList (VOID);
136
137
138 LPCTSTR GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA );
139
140 /* Prototypes for COLOR.C */
141 INT CommandColor(LPTSTR);
142
143 /* Prototypes for CONSOLE.C */
144 #include "console.h"
145
146 /* Prototypes for COPY.C */
147 INT cmd_copy (LPTSTR);
148
149 /* Prototypes for DATE.C */
150 INT cmd_date (LPTSTR);
151
152 /* Prototypes for DEL.C */
153 INT CommandDelete (LPTSTR);
154
155 /* Prototypes for DELAY.C */
156 INT CommandDelay (LPTSTR);
157
158 /* Prototypes for DIR.C */
159 INT FormatDate (TCHAR *, LPSYSTEMTIME, BOOL);
160 INT FormatTime (TCHAR *, LPSYSTEMTIME);
161 INT CommandDir (LPTSTR);
162
163 /* Prototypes for DIRSTACK.C */
164 VOID InitDirectoryStack (VOID);
165 VOID DestroyDirectoryStack (VOID);
166 INT GetDirectoryStackDepth (VOID);
167 INT CommandPushd (LPTSTR);
168 INT CommandPopd (LPTSTR);
169 INT CommandDirs (LPTSTR);
170
171 /* Prototypes for ECHO.C */
172 BOOL OnOffCommand(LPTSTR param, LPBOOL flag, INT message);
173 INT CommandEcho (LPTSTR);
174 INT CommandEchos (LPTSTR);
175 INT CommandEchoerr (LPTSTR);
176 INT CommandEchoserr (LPTSTR);
177
178 /* Prototypes for ERROR.C */
179 VOID ErrorMessage (DWORD, LPTSTR, ...);
180
181 VOID error_no_pipe (VOID);
182 VOID error_bad_command (LPTSTR);
183 VOID error_invalid_drive (VOID);
184 VOID error_req_param_missing (VOID);
185 VOID error_sfile_not_found (LPTSTR);
186 VOID error_file_not_found (VOID);
187 VOID error_path_not_found (VOID);
188 VOID error_too_many_parameters (LPTSTR);
189 VOID error_parameter_format(TCHAR);
190 VOID error_invalid_switch (TCHAR);
191 VOID error_invalid_parameter_format (LPTSTR);
192 VOID error_out_of_memory (VOID);
193 VOID error_syntax (LPTSTR);
194
195 VOID msg_pause (VOID);
196
197 /* Prototypes for FILECOMP.C */
198 #ifdef FEATURE_UNIX_FILENAME_COMPLETION
199 VOID CompleteFilename (LPTSTR, UINT);
200 INT ShowCompletionMatches (LPTSTR, INT);
201 #endif
202 #ifdef FEATURE_4NT_FILENAME_COMPLETION
203 VOID CompleteFilename (LPTSTR, BOOL, LPTSTR, UINT);
204 #endif
205
206
207 /* Prototypes for FOR.C */
208 #define FOR_DIRS 1 /* /D */
209 #define FOR_F 2 /* /F */
210 #define FOR_LOOP 4 /* /L */
211 #define FOR_RECURSIVE 8 /* /R */
212 INT cmd_for (LPTSTR);
213 INT ExecuteFor(struct _PARSED_COMMAND *Cmd);
214
215
216 /* Prototypes for FREE.C */
217 INT CommandFree (LPTSTR);
218
219 /* Prototypes for GOTO.C */
220 INT cmd_goto (LPTSTR);
221
222 /* Prototypes for HISTORY.C */
223 #ifdef FEATURE_HISTORY
224 LPCTSTR PeekHistory(INT);
225 VOID History (INT, LPTSTR);/*add entries browse history*/
226 VOID History_move_to_bottom(VOID);/*F3*/
227 VOID InitHistory(VOID);
228 VOID CleanHistory(VOID);
229 VOID History_del_current_entry(LPTSTR str);/*CTRL-D*/
230 INT CommandHistory (LPTSTR param);
231 #endif
232
233 /* Prototypes for IF.C */
234 #define IFFLAG_NEGATE 1 /* NOT */
235 #define IFFLAG_IGNORECASE 2 /* /I */
236 enum { IF_CMDEXTVERSION, IF_DEFINED, IF_ERRORLEVEL, IF_EXIST,
237 IF_STRINGEQ, /* == */
238 IF_EQU, IF_GTR, IF_GEQ, IF_LSS, IF_LEQ, IF_NEQ };
239 INT ExecuteIf(struct _PARSED_COMMAND *Cmd);
240
241 /* Prototypes for INTERNAL.C */
242 VOID InitLastPath (VOID);
243 VOID FreeLastPath (VOID);
244 INT cmd_chdir (LPTSTR);
245 INT cmd_mkdir (LPTSTR);
246 INT cmd_rmdir (LPTSTR);
247 INT CommandExit (LPTSTR);
248 INT CommandRem (LPTSTR);
249 INT CommandShowCommands (LPTSTR);
250
251 /* Prototypes for LABEL.C */
252 INT cmd_label (LPTSTR);
253
254 /* Prototypes for LOCALE.C */
255 extern TCHAR cDateSeparator;
256 extern INT nDateFormat;
257 extern TCHAR cTimeSeparator;
258 extern INT nTimeFormat;
259 extern TCHAR cThousandSeparator;
260 extern TCHAR cDecimalSeparator;
261 extern INT nNumberGroups;
262
263 VOID InitLocale (VOID);
264 LPTSTR GetDateString (VOID);
265 LPTSTR GetTimeString (VOID);
266
267 /* Prototypes for MEMORY.C */
268 INT CommandMemory (LPTSTR);
269
270 /* Prototypes for MKLINK.C */
271 INT cmd_mklink(LPTSTR);
272
273 /* Prototypes for MISC.C */
274 INT GetRootPath(TCHAR *InPath,TCHAR *OutPath,INT size);
275 BOOL SetRootPath(TCHAR *oldpath,TCHAR *InPath);
276 TCHAR cgetchar (VOID);
277 BOOL CheckCtrlBreak (INT);
278 BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry);
279 LPTSTR *split (LPTSTR, LPINT, BOOL, BOOL);
280 LPTSTR *splitspace (LPTSTR, LPINT);
281 VOID freep (LPTSTR *);
282 LPTSTR _stpcpy (LPTSTR, LPCTSTR);
283 VOID StripQuotes(LPTSTR);
284 BOOL IsValidPathName (LPCTSTR);
285 BOOL IsExistingFile (LPCTSTR);
286 BOOL IsExistingDirectory (LPCTSTR);
287 BOOL FileGetString (HANDLE, LPTSTR, INT);
288 VOID GetPathCase(TCHAR *, TCHAR *);
289
290 #define PROMPT_NO 0
291 #define PROMPT_YES 1
292 #define PROMPT_ALL 2
293 #define PROMPT_BREAK 3
294
295 INT PagePrompt (VOID);
296 INT FilePromptYN (UINT);
297 INT FilePromptYNA (UINT);
298
299 /* Prototypes for MOVE.C */
300 INT cmd_move (LPTSTR);
301
302 /* Prototypes for MSGBOX.C */
303 INT CommandMsgbox (LPTSTR);
304
305 /* Prototypes from PARSER.C */
306 enum { C_COMMAND, C_QUIET, C_BLOCK, C_MULTI, C_IFFAILURE, C_IFSUCCESS, C_PIPE, C_IF, C_FOR };
307 typedef struct _PARSED_COMMAND
308 {
309 struct _PARSED_COMMAND *Subcommands;
310 struct _PARSED_COMMAND *Next;
311 struct _REDIRECTION *Redirections;
312 BYTE Type;
313 union
314 {
315 struct
316 {
317 TCHAR *Rest;
318 TCHAR First[];
319 } Command;
320 struct
321 {
322 BYTE Flags;
323 BYTE Operator;
324 TCHAR *LeftArg;
325 TCHAR *RightArg;
326 } If;
327 struct
328 {
329 BYTE Switches;
330 TCHAR Variable;
331 LPTSTR Params;
332 LPTSTR List;
333 struct tagFORCONTEXT *Context;
334 } For;
335 };
336 } PARSED_COMMAND;
337 PARSED_COMMAND *ParseCommand(LPTSTR Line);
338 VOID EchoCommand(PARSED_COMMAND *Cmd);
339 TCHAR *Unparse(PARSED_COMMAND *Cmd, TCHAR *Out, TCHAR *OutEnd);
340 VOID FreeCommand(PARSED_COMMAND *Cmd);
341
342 /* Prototypes from PATH.C */
343 INT cmd_path (LPTSTR);
344
345 /* Prototypes from PROMPT.C */
346 VOID InitPrompt (VOID);
347 VOID PrintPrompt (VOID);
348 INT cmd_prompt (LPTSTR);
349
350 /* Prototypes for REDIR.C */
351 typedef enum _REDIR_MODE
352 {
353 REDIR_READ = 0,
354 REDIR_WRITE = 1,
355 REDIR_APPEND = 2
356 } REDIR_MODE;
357 typedef struct _REDIRECTION
358 {
359 struct _REDIRECTION *Next;
360 HANDLE OldHandle;
361 BYTE Number;
362 REDIR_MODE Mode;
363 TCHAR Filename[];
364 } REDIRECTION;
365 BOOL PerformRedirection(REDIRECTION *);
366 VOID UndoRedirection(REDIRECTION *, REDIRECTION *End);
367 INT GetRedirection(LPTSTR, REDIRECTION **);
368 VOID FreeRedirection(REDIRECTION *);
369
370 /* Prototypes for REN.C */
371 INT cmd_rename (LPTSTR);
372
373 /* Prototypes for REN.C */
374 INT cmd_replace (LPTSTR);
375
376 /* Prototypes for SCREEN.C */
377 INT CommandScreen (LPTSTR);
378
379 /* Prototypes for SET.C */
380 INT cmd_set (LPTSTR);
381
382 /* Prototypes for SETLOCAL.C */
383 LPTSTR DuplicateEnvironment(VOID);
384 INT cmd_setlocal (LPTSTR);
385 INT cmd_endlocal (LPTSTR);
386
387 /* Prototypes for START.C */
388 INT cmd_start (LPTSTR);
389
390 /* Prototypes for STRTOCLR.C */
391 BOOL StringToColor (LPWORD, LPTSTR *);
392
393 /* Prototypes for TIME.C */
394 INT cmd_time (LPTSTR);
395
396 /* Prototypes for TIMER.C */
397 INT CommandTimer (LPTSTR param);
398
399 /* Prototypes for TITLE.C */
400 INT cmd_title (LPTSTR);
401
402 /* Prototypes for TYPE.C */
403 INT cmd_type (LPTSTR);
404
405 /* Prototypes for VER.C */
406 VOID InitOSVersion(VOID);
407 VOID PrintOSVersion(VOID);
408 INT cmd_ver (LPTSTR);
409
410 /* Prototypes for VERIFY.C */
411 INT cmd_verify (LPTSTR);
412
413 /* Prototypes for VOL.C */
414 INT cmd_vol (LPTSTR);
415
416 /* Prototypes for WHERE.C */
417 BOOL SearchForExecutable (LPCTSTR, LPTSTR);
418
419 /* Prototypes for WINDOW.C */
420 INT CommandActivate (LPTSTR);
421 INT CommandWindow (LPTSTR);
422
423 /* The MSDOS Batch Commands [MS-DOS 5.0 User's Guide and Reference p359] */
424 int cmd_if(TCHAR *);
425 int cmd_pause(TCHAR *);
426 int cmd_shift(TCHAR *);