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