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