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