2 * CMD.H - header file for the modules in CMD.EXE
11 * Moved error messages in here
14 * Moved more error messages here.
16 * 30-Jul-1998 (John P Price <linux-guru@gcfl.net>)
17 * Added compile date to version.
19 * 26-Feb-1999 (Eric Kohl)
20 * Introduced a new version string.
21 * Thanks to Emanuele Aliberti!
24 #ifndef _CMD_H_INCLUDED_
25 #define _CMD_H_INCLUDED_
36 #define BREAK_BATCHFILE 1
37 #define BREAK_OUTOFBATCH 2
39 #define BREAK_IGNORE 4
41 /* define some error messages */
44 #define D_OFF _T("off")
47 /* command line buffer length */
48 #define CMDLINE_LENGTH 8192
50 /* 16k = max buffer size */
51 #define BUFF_SIZE 16384
53 /* global variables */
56 extern HANDLE hConsole
;
57 extern LPTSTR lpOriginalEnvironment
;
59 extern WORD wDefColor
;
60 extern BOOL bCtrlBreak
;
61 extern BOOL bIgnoreEcho
;
63 extern BOOL bDelayedExpansion
;
64 extern INT nErrorLevel
;
67 extern OSVERSIONINFO osvi
;
71 /* Prototypes for ALIAS.C */
72 VOID
ExpandAlias (LPTSTR
, INT
);
73 INT
CommandAlias (LPTSTR
);
75 /* Prototypes for ASSOC.C */
76 INT
CommandAssoc (LPTSTR
);
78 /* Prototypes for ATTRIB.C */
79 INT
CommandAttrib (LPTSTR
);
82 /* Prototypes for BEEP.C */
83 INT
cmd_beep (LPTSTR
);
86 /* Prototypes for CALL.C */
87 INT
cmd_call (LPTSTR
);
90 /* Prototypes for CHCP.C */
91 INT
CommandChcp (LPTSTR
);
94 /* Prototypes for CHOICE.C */
95 INT
CommandChoice (LPTSTR
);
98 /* Prototypes for CLS.C */
102 /* Prototypes for CMD.C */
103 INT
ConvertULargeInteger(ULONGLONG num
, LPTSTR des
, INT len
, BOOL bPutSeperator
);
104 HANDLE
RunFile(DWORD
, LPTSTR
, LPTSTR
, LPTSTR
, INT
);
105 VOID
ParseCommandLine (LPTSTR
);
106 struct _PARSED_COMMAND
;
107 BOOL
ExecuteCommand(struct _PARSED_COMMAND
*Cmd
);
108 LPCTSTR
GetEnvVarOrSpecial ( LPCTSTR varName
);
109 VOID
AddBreakHandler (VOID
);
110 VOID
RemoveBreakHandler (VOID
);
111 BOOL
SubstituteVars(TCHAR
*Src
, TCHAR
*Dest
, TCHAR Delim
);
112 BOOL
SubstituteForVars(TCHAR
*Src
, TCHAR
*Dest
);
113 LPTSTR
DoDelayedExpansion(LPTSTR Line
);
114 BOOL
DoCommand (LPTSTR line
, struct _PARSED_COMMAND
*Cmd
);
115 BOOL
ReadLine(TCHAR
*commandline
, BOOL bMore
);
116 int cmd_main (int argc
, const TCHAR
*argv
[]);
118 extern HANDLE CMD_ModuleHandle
;
121 /* Prototypes for CMDINPUT.C */
122 VOID
ReadCommand (LPTSTR
, INT
);
125 /* Prototypes for CMDTABLE.C */
126 #define CMD_SPECIAL 1
127 #define CMD_BATCHONLY 2
130 typedef struct tagCOMMAND
135 } COMMAND
, *LPCOMMAND
;
137 extern COMMAND cmds
[]; /* The internal command table */
139 VOID
PrintCommandList (VOID
);
140 VOID
PrintCommandListDetail (VOID
);
143 LPCTSTR
GetParsedEnvVar ( LPCTSTR varName
, UINT
* varNameLen
, BOOL ModeSetA
);
145 /* Prototypes for COLOR.C */
146 VOID
SetScreenColor(WORD wArgColor
, BOOL bFill
);
147 INT
CommandColor (LPTSTR
);
149 VOID
ConInDummy (VOID
);
150 VOID
ConInDisable (VOID
);
151 VOID
ConInEnable (VOID
);
152 VOID
ConInFlush (VOID
);
153 VOID
ConInKey (PINPUT_RECORD
);
154 VOID
ConInString (LPTSTR
, DWORD
);
156 VOID
ConOutChar (TCHAR
);
157 VOID
ConOutPuts (LPTSTR
);
158 VOID
ConPrintf(LPTSTR
, va_list, DWORD
);
159 INT
ConPrintfPaging(BOOL NewPage
, LPTSTR
, va_list, DWORD
);
160 VOID
ConOutPrintf (LPTSTR
, ...);
161 INT
ConOutPrintfPaging (BOOL NewPage
, LPTSTR
, ...);
162 VOID
ConErrChar (TCHAR
);
163 VOID
ConErrPuts (LPTSTR
);
164 VOID
ConErrPrintf (LPTSTR
, ...);
165 VOID
ConOutFormatMessage (DWORD MessageId
, ...);
166 VOID
ConErrFormatMessage (DWORD MessageId
, ...);
168 SHORT
GetCursorX (VOID
);
169 SHORT
GetCursorY (VOID
);
170 VOID
GetCursorXY (PSHORT
, PSHORT
);
171 VOID
SetCursorXY (SHORT
, SHORT
);
173 VOID
GetScreenSize (PSHORT
, PSHORT
);
174 VOID
SetCursorType (BOOL
, BOOL
);
176 VOID
ConOutResPuts (UINT resID
);
177 VOID
ConErrResPuts (UINT resID
);
178 VOID
ConOutResPrintf (UINT resID
, ...);
179 VOID
ConErrResPrintf (UINT resID
, ...);
180 VOID
ConOutResPaging(BOOL NewPage
, UINT resID
);
182 /* Prototypes for COPY.C */
183 INT
cmd_copy (LPTSTR
);
186 /* Prototypes for DATE.C */
187 INT
cmd_date (LPTSTR
);
190 /* Prototypes for DEL.C */
191 INT
CommandDelete (LPTSTR
);
194 /* Prototypes for DELAY.C */
195 INT
CommandDelay (LPTSTR
);
198 /* Prototypes for DIR.C */
199 INT
FormatDate (TCHAR
*, LPSYSTEMTIME
, BOOL
);
200 INT
FormatTime (TCHAR
*, LPSYSTEMTIME
);
201 INT
CommandDir (LPTSTR
);
204 /* Prototypes for DIRSTACK.C */
205 VOID
InitDirectoryStack (VOID
);
206 VOID
DestroyDirectoryStack (VOID
);
207 INT
GetDirectoryStackDepth (VOID
);
208 INT
CommandPushd (LPTSTR
);
209 INT
CommandPopd (LPTSTR
);
210 INT
CommandDirs (LPTSTR
);
213 /* Prototypes for ECHO.C */
214 INT
CommandEcho (LPTSTR
);
215 INT
CommandEchos (LPTSTR
);
216 INT
CommandEchoerr (LPTSTR
);
217 INT
CommandEchoserr (LPTSTR
);
220 /* Prototypes for ERROR.C */
221 VOID
ErrorMessage (DWORD
, LPTSTR
, ...);
223 VOID
error_no_pipe (VOID
);
224 VOID
error_bad_command (LPTSTR
);
225 VOID
error_invalid_drive (VOID
);
226 VOID
error_req_param_missing (VOID
);
227 VOID
error_sfile_not_found (LPTSTR
);
228 VOID
error_file_not_found (VOID
);
229 VOID
error_path_not_found (VOID
);
230 VOID
error_too_many_parameters (LPTSTR
);
231 VOID
error_parameter_format(TCHAR
);
232 VOID
error_invalid_switch (TCHAR
);
233 VOID
error_invalid_parameter_format (LPTSTR
);
234 VOID
error_out_of_memory (VOID
);
235 VOID
error_syntax (LPTSTR
);
237 VOID
msg_pause (VOID
);
240 /* Prototypes for FILECOMP.C */
241 #ifdef FEATURE_UNIX_FILENAME_COMPLETION
242 VOID
CompleteFilename (LPTSTR
, UINT
);
243 INT
ShowCompletionMatches (LPTSTR
, INT
);
245 #ifdef FEATURE_4NT_FILENAME_COMPLETION
246 VOID
CompleteFilename (LPTSTR
, BOOL
, LPTSTR
, UINT
);
250 /* Prototypes for FOR.C */
251 #define FOR_DIRS 1 /* /D */
252 #define FOR_F 2 /* /F */
253 #define FOR_LOOP 4 /* /L */
254 #define FOR_RECURSIVE 8 /* /R */
255 INT
cmd_for (LPTSTR
);
256 BOOL
ExecuteFor(struct _PARSED_COMMAND
*Cmd
);
259 /* Prototypes for FREE.C */
260 INT
CommandFree (LPTSTR
);
263 /* Prototypes for GOTO.C */
264 INT
cmd_goto (LPTSTR
);
267 /* Prototypes for HISTORY.C */
268 #ifdef FEATURE_HISTORY
269 LPCTSTR
PeekHistory(INT
);
270 VOID
History (INT
, LPTSTR
);/*add entries browse history*/
271 VOID
History_move_to_bottom(VOID
);/*F3*/
272 VOID
InitHistory(VOID
);
273 VOID
CleanHistory(VOID
);
274 VOID
History_del_current_entry(LPTSTR str
);/*CTRL-D*/
275 INT
CommandHistory (LPTSTR param
);
279 /* Prototypes for IF.C */
280 #define IFFLAG_NEGATE 1 /* NOT */
281 #define IFFLAG_IGNORECASE 2 /* /I */
282 enum { IF_CMDEXTVERSION
, IF_DEFINED
, IF_ERRORLEVEL
, IF_EXIST
,
283 IF_STRINGEQ
, /* == */
284 IF_EQU
, IF_GTR
, IF_GEQ
, IF_LSS
, IF_LEQ
, IF_NEQ
};
285 BOOL
ExecuteIf(struct _PARSED_COMMAND
*Cmd
);
288 /* Prototypes for INTERNAL.C */
289 VOID
InitLastPath (VOID
);
290 VOID
FreeLastPath (VOID
);
291 INT
cmd_chdir (LPTSTR
);
292 INT
cmd_mkdir (LPTSTR
);
293 INT
cmd_rmdir (LPTSTR
);
294 INT
CommandExit (LPTSTR
);
295 INT
CommandRem (LPTSTR
);
296 INT
CommandShowCommands (LPTSTR
);
297 INT
CommandShowCommandsDetail (LPTSTR
);
299 /* Prototypes for LABEL.C */
300 INT
cmd_label (LPTSTR
);
303 /* Prototypes for LOCALE.C */
304 extern TCHAR cDateSeparator
;
305 extern INT nDateFormat
;
306 extern TCHAR cTimeSeparator
;
307 extern INT nTimeFormat
;
308 extern TCHAR cThousandSeparator
;
309 extern TCHAR cDecimalSeparator
;
310 extern INT nNumberGroups
;
313 VOID
InitLocale (VOID
);
314 LPTSTR
GetDateString (VOID
);
315 LPTSTR
GetTimeString (VOID
);
318 extern UINT InputCodePage
;
319 extern UINT OutputCodePage
;
321 /* Prototypes for MEMORY.C */
322 INT
CommandMemory (LPTSTR
);
325 /* Prototypes for MKLINK.C */
326 INT
cmd_mklink(LPTSTR
);
329 /* Prototypes for MISC.C */
330 INT
GetRootPath(TCHAR
*InPath
,TCHAR
*OutPath
,INT size
);
331 BOOL
SetRootPath(TCHAR
*InPath
);
332 TCHAR
cgetchar (VOID
);
333 BOOL
CheckCtrlBreak (INT
);
334 BOOL
add_entry (LPINT ac
, LPTSTR
**arg
, LPCTSTR entry
);
335 LPTSTR
*split (LPTSTR
, LPINT
, BOOL
);
336 LPTSTR
*splitspace (LPTSTR
, LPINT
);
337 VOID
freep (LPTSTR
*);
338 LPTSTR
_stpcpy (LPTSTR
, LPCTSTR
);
339 VOID
StripQuotes(LPTSTR
);
340 BOOL
IsValidPathName (LPCTSTR
);
341 BOOL
IsExistingFile (LPCTSTR
);
342 BOOL
IsExistingDirectory (LPCTSTR
);
343 BOOL
FileGetString (HANDLE
, LPTSTR
, INT
);
344 VOID
GetPathCase(TCHAR
*, TCHAR
*);
349 #define PROMPT_BREAK 3
351 INT
PagePrompt (VOID
);
352 INT
FilePromptYN (UINT
);
353 INT
FilePromptYNA (UINT
);
356 /* Prototypes for MOVE.C */
357 INT
cmd_move (LPTSTR
);
360 /* Prototypes for MSGBOX.C */
361 INT
CommandMsgbox (LPTSTR
);
364 /* Prototypes from PARSER.C */
365 enum { C_COMMAND
, C_QUIET
, C_BLOCK
, C_MULTI
, C_IFFAILURE
, C_IFSUCCESS
, C_PIPE
, C_IF
, C_FOR
};
366 typedef struct _PARSED_COMMAND
368 struct _PARSED_COMMAND
*Subcommands
;
369 struct _PARSED_COMMAND
*Next
;
370 struct _REDIRECTION
*Redirections
;
392 struct tagFORCONTEXT
*Context
;
396 PARSED_COMMAND
*ParseCommand(LPTSTR Line
);
397 VOID
EchoCommand(PARSED_COMMAND
*Cmd
);
398 TCHAR
*Unparse(PARSED_COMMAND
*Cmd
, TCHAR
*Out
, TCHAR
*OutEnd
);
399 VOID
FreeCommand(PARSED_COMMAND
*Cmd
);
402 /* Prototypes from PATH.C */
403 INT
cmd_path (LPTSTR
);
406 /* Prototypes from PROMPT.C */
407 VOID
PrintPrompt (VOID
);
408 INT
cmd_prompt (LPTSTR
);
411 /* Prototypes for REDIR.C */
412 enum { REDIR_READ
, REDIR_WRITE
, REDIR_APPEND
};
413 typedef struct _REDIRECTION
415 struct _REDIRECTION
*Next
;
421 BOOL
PerformRedirection(REDIRECTION
*);
422 VOID
UndoRedirection(REDIRECTION
*, REDIRECTION
*End
);
423 INT
GetRedirection(LPTSTR
, REDIRECTION
**);
424 VOID
FreeRedirection(REDIRECTION
*);
427 /* Prototypes for REN.C */
428 INT
cmd_rename (LPTSTR
);
430 /* Prototypes for REN.C */
431 INT
cmd_replace (LPTSTR
);
433 /* Prototypes for SCREEN.C */
434 INT
CommandScreen (LPTSTR
);
437 /* Prototypes for SET.C */
438 INT
cmd_set (LPTSTR
);
440 /* Prototypes for SETLOCAL.C */
441 LPTSTR
DuplicateEnvironment(VOID
);
442 INT
cmd_setlocal (LPTSTR
);
443 INT
cmd_endlocal (LPTSTR
);
445 /* Prototypes for START.C */
446 INT
cmd_start (LPTSTR
);
449 /* Prototypes for STRTOCLR.C */
450 BOOL
StringToColor (LPWORD
, LPTSTR
*);
453 /* Prototypes for TIME.C */
454 INT
cmd_time (LPTSTR
);
457 /* Prototypes for TIMER.C */
458 INT
CommandTimer (LPTSTR param
);
461 /* Prototypes for TITLE.C */
462 INT
cmd_title (LPTSTR
);
465 /* Prototypes for TYPE.C */
466 INT
cmd_type (LPTSTR
);
469 /* Prototypes for VER.C */
470 VOID
ShortVersion (VOID
);
471 INT
cmd_ver (LPTSTR
);
474 /* Prototypes for VERIFY.C */
475 INT
cmd_verify (LPTSTR
);
478 /* Prototypes for VOL.C */
479 INT
cmd_vol (LPTSTR
);
482 /* Prototypes for WHERE.C */
483 BOOL
SearchForExecutable (LPCTSTR
, LPTSTR
);
485 /* Prototypes for WINDOW.C */
486 INT
CommandActivate (LPTSTR
);
487 INT
CommandWindow (LPTSTR
);
490 /* The MSDOS Batch Commands [MS-DOS 5.0 User's Guide and Reference p359] */
492 int cmd_pause(TCHAR
*);
493 int cmd_shift(TCHAR
*);
495 #endif /* _CMD_H_INCLUDED_ */