Make START command able to open non-executable files/directories/URLs using ShellExec...
[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 #ifndef _CMD_H_INCLUDED_
25 #define _CMD_H_INCLUDED_
26
27 #include "config.h"
28
29 #include <windows.h>
30 #include <tchar.h>
31
32 #include "cmdver.h"
33
34 #include "cmddbg.h"
35
36 #define BREAK_BATCHFILE 1
37 #define BREAK_OUTOFBATCH 2
38 #define BREAK_INPUT 3
39 #define BREAK_IGNORE 4
40
41 /* define some error messages */
42
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 hOut;
55 extern HANDLE hIn;
56 extern HANDLE hConsole;
57 extern WORD wColor;
58 extern WORD wDefColor;
59 extern BOOL bCtrlBreak;
60 extern BOOL bIgnoreEcho;
61 extern BOOL bExit;
62 extern BOOL bDelayedExpansion;
63 extern INT nErrorLevel;
64 extern SHORT maxx;
65 extern SHORT maxy;
66 extern OSVERSIONINFO osvi;
67
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, INT len, BOOL bPutSeperator);
103 HANDLE RunFile(DWORD, LPTSTR, LPTSTR, LPTSTR, INT);
104 VOID ParseCommandLine (LPTSTR);
105 struct _PARSED_COMMAND;
106 BOOL 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 BOOL DoCommand (LPTSTR line, 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 VOID 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 INT CommandEcho (LPTSTR);
214 INT CommandEchos (LPTSTR);
215 INT CommandEchoerr (LPTSTR);
216 INT CommandEchoserr (LPTSTR);
217
218
219 /* Prototypes for ERROR.C */
220 VOID ErrorMessage (DWORD, LPTSTR, ...);
221
222 VOID error_no_pipe (VOID);
223 VOID error_bad_command (LPTSTR);
224 VOID error_invalid_drive (VOID);
225 VOID error_req_param_missing (VOID);
226 VOID error_sfile_not_found (LPTSTR);
227 VOID error_file_not_found (VOID);
228 VOID error_path_not_found (VOID);
229 VOID error_too_many_parameters (LPTSTR);
230 VOID error_parameter_format(TCHAR);
231 VOID error_invalid_switch (TCHAR);
232 VOID error_invalid_parameter_format (LPTSTR);
233 VOID error_out_of_memory (VOID);
234 VOID error_syntax (LPTSTR);
235
236 VOID msg_pause (VOID);
237
238
239 /* Prototypes for FILECOMP.C */
240 #ifdef FEATURE_UNIX_FILENAME_COMPLETION
241 VOID CompleteFilename (LPTSTR, UINT);
242 INT ShowCompletionMatches (LPTSTR, INT);
243 #endif
244 #ifdef FEATURE_4NT_FILENAME_COMPLETION
245 VOID CompleteFilename (LPTSTR, BOOL, LPTSTR, UINT);
246 #endif
247
248
249 /* Prototypes for FOR.C */
250 #define FOR_DIRS 1 /* /D */
251 #define FOR_F 2 /* /F */
252 #define FOR_LOOP 4 /* /L */
253 #define FOR_RECURSIVE 8 /* /R */
254 INT cmd_for (LPTSTR);
255 BOOL ExecuteFor(struct _PARSED_COMMAND *Cmd);
256
257
258 /* Prototypes for FREE.C */
259 INT CommandFree (LPTSTR);
260
261
262 /* Prototypes for GOTO.C */
263 INT cmd_goto (LPTSTR);
264
265
266 /* Prototypes for HISTORY.C */
267 #ifdef FEATURE_HISTORY
268 LPCTSTR PeekHistory(INT);
269 VOID History (INT, LPTSTR);/*add entries browse history*/
270 VOID History_move_to_bottom(VOID);/*F3*/
271 VOID InitHistory(VOID);
272 VOID CleanHistory(VOID);
273 VOID History_del_current_entry(LPTSTR str);/*CTRL-D*/
274 INT CommandHistory (LPTSTR param);
275 #endif
276
277
278 /* Prototypes for IF.C */
279 #define IFFLAG_NEGATE 1 /* NOT */
280 #define IFFLAG_IGNORECASE 2 /* /I */
281 enum { IF_CMDEXTVERSION, IF_DEFINED, IF_ERRORLEVEL, IF_EXIST,
282 IF_STRINGEQ, /* == */
283 IF_EQU, IF_GTR, IF_GEQ, IF_LSS, IF_LEQ, IF_NEQ };
284 BOOL ExecuteIf(struct _PARSED_COMMAND *Cmd);
285
286
287 /* Prototypes for INTERNAL.C */
288 VOID InitLastPath (VOID);
289 VOID FreeLastPath (VOID);
290 INT cmd_chdir (LPTSTR);
291 INT cmd_mkdir (LPTSTR);
292 INT cmd_rmdir (LPTSTR);
293 INT CommandExit (LPTSTR);
294 INT CommandRem (LPTSTR);
295 INT CommandShowCommands (LPTSTR);
296 INT CommandShowCommandsDetail (LPTSTR);
297
298 /* Prototypes for LABEL.C */
299 INT cmd_label (LPTSTR);
300
301
302 /* Prototypes for LOCALE.C */
303 extern TCHAR cDateSeparator;
304 extern INT nDateFormat;
305 extern TCHAR cTimeSeparator;
306 extern INT nTimeFormat;
307 extern TCHAR cThousandSeparator;
308 extern TCHAR cDecimalSeparator;
309 extern INT nNumberGroups;
310
311
312 VOID InitLocale (VOID);
313 LPTSTR GetDateString (VOID);
314 LPTSTR GetTimeString (VOID);
315
316 /* cache codepage */
317 extern UINT InputCodePage;
318 extern UINT OutputCodePage;
319
320 /* Prototypes for MEMORY.C */
321 INT CommandMemory (LPTSTR);
322
323
324 /* Prototypes for MKLINK.C */
325 INT cmd_mklink(LPTSTR);
326
327
328 /* Prototypes for MISC.C */
329 INT GetRootPath(TCHAR *InPath,TCHAR *OutPath,INT size);
330 BOOL SetRootPath(TCHAR *InPath);
331 TCHAR cgetchar (VOID);
332 BOOL CheckCtrlBreak (INT);
333 BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry);
334 LPTSTR *split (LPTSTR, LPINT, BOOL);
335 LPTSTR *splitspace (LPTSTR, LPINT);
336 VOID freep (LPTSTR *);
337 LPTSTR _stpcpy (LPTSTR, LPCTSTR);
338 VOID StripQuotes(LPTSTR);
339 BOOL IsValidPathName (LPCTSTR);
340 BOOL IsExistingFile (LPCTSTR);
341 BOOL IsExistingDirectory (LPCTSTR);
342 BOOL FileGetString (HANDLE, LPTSTR, INT);
343 VOID GetPathCase(TCHAR *, TCHAR *);
344
345 #define PROMPT_NO 0
346 #define PROMPT_YES 1
347 #define PROMPT_ALL 2
348 #define PROMPT_BREAK 3
349
350 INT PagePrompt (VOID);
351 INT FilePromptYN (UINT);
352 INT FilePromptYNA (UINT);
353
354
355 /* Prototypes for MOVE.C */
356 INT cmd_move (LPTSTR);
357
358
359 /* Prototypes for MSGBOX.C */
360 INT CommandMsgbox (LPTSTR);
361
362
363 /* Prototypes from PARSER.C */
364 enum { C_COMMAND, C_QUIET, C_BLOCK, C_MULTI, C_IFFAILURE, C_IFSUCCESS, C_PIPE, C_IF, C_FOR };
365 typedef struct _PARSED_COMMAND
366 {
367 struct _PARSED_COMMAND *Subcommands;
368 struct _PARSED_COMMAND *Next;
369 struct _REDIRECTION *Redirections;
370 BYTE Type;
371 union
372 {
373 struct
374 {
375 TCHAR *Tail;
376 TCHAR CommandLine[];
377 } Command;
378 struct
379 {
380 BYTE Flags;
381 BYTE Operator;
382 TCHAR *LeftArg;
383 TCHAR *RightArg;
384 } If;
385 struct
386 {
387 BYTE Switches;
388 TCHAR Variable;
389 LPTSTR Params;
390 LPTSTR List;
391 struct tagFORCONTEXT *Context;
392 } For;
393 };
394 } PARSED_COMMAND;
395 PARSED_COMMAND *ParseCommand(LPTSTR Line);
396 VOID EchoCommand(PARSED_COMMAND *Cmd);
397 TCHAR *Unparse(PARSED_COMMAND *Cmd, TCHAR *Out, TCHAR *OutEnd);
398 VOID FreeCommand(PARSED_COMMAND *Cmd);
399
400
401 /* Prototypes from PATH.C */
402 INT cmd_path (LPTSTR);
403
404
405 /* Prototypes from PROMPT.C */
406 VOID PrintPrompt (VOID);
407 INT cmd_prompt (LPTSTR);
408
409
410 /* Prototypes for REDIR.C */
411 enum { REDIR_READ, REDIR_WRITE, REDIR_APPEND };
412 typedef struct _REDIRECTION
413 {
414 struct _REDIRECTION *Next;
415 HANDLE OldHandle;
416 BYTE Number;
417 BYTE Type;
418 TCHAR Filename[];
419 } REDIRECTION;
420 BOOL PerformRedirection(REDIRECTION *);
421 VOID UndoRedirection(REDIRECTION *, REDIRECTION *End);
422 INT GetRedirection(LPTSTR, REDIRECTION **);
423 VOID FreeRedirection(REDIRECTION *);
424
425
426 /* Prototypes for REN.C */
427 INT cmd_rename (LPTSTR);
428
429 /* Prototypes for REN.C */
430 INT cmd_replace (LPTSTR);
431
432 /* Prototypes for SCREEN.C */
433 INT CommandScreen (LPTSTR);
434
435
436 /* Prototypes for SET.C */
437 INT cmd_set (LPTSTR);
438
439 /* Prototypes for SETLOCAL.C */
440 INT cmd_setlocal (LPTSTR);
441 INT cmd_endlocal (LPTSTR);
442
443 /* Prototypes for START.C */
444 INT cmd_start (LPTSTR);
445
446
447 /* Prototypes for STRTOCLR.C */
448 BOOL StringToColor (LPWORD, LPTSTR *);
449
450
451 /* Prototypes for TIME.C */
452 INT cmd_time (LPTSTR);
453
454
455 /* Prototypes for TIMER.C */
456 INT CommandTimer (LPTSTR param);
457
458
459 /* Prototypes for TITLE.C */
460 INT cmd_title (LPTSTR);
461
462
463 /* Prototypes for TYPE.C */
464 INT cmd_type (LPTSTR);
465
466
467 /* Prototypes for VER.C */
468 VOID ShortVersion (VOID);
469 INT cmd_ver (LPTSTR);
470
471
472 /* Prototypes for VERIFY.C */
473 INT cmd_verify (LPTSTR);
474
475
476 /* Prototypes for VOL.C */
477 INT cmd_vol (LPTSTR);
478
479
480 /* Prototypes for WHERE.C */
481 BOOL SearchForExecutable (LPCTSTR, LPTSTR);
482
483 /* Prototypes for WINDOW.C */
484 INT CommandActivate (LPTSTR);
485 INT CommandWindow (LPTSTR);
486
487
488 /* The MSDOS Batch Commands [MS-DOS 5.0 User's Guide and Reference p359] */
489 int cmd_if(TCHAR *);
490 int cmd_pause(TCHAR *);
491 int cmd_shift(TCHAR *);
492
493 #endif /* _CMD_H_INCLUDED_ */