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 LPTSTR lpOriginalEnvironment
;
58 extern WORD wDefColor
;
59 extern BOOL bCtrlBreak
;
60 extern BOOL bIgnoreEcho
;
62 extern BOOL bDisableBatchEcho
;
63 extern BOOL bDelayedExpansion
;
64 extern INT nErrorLevel
;
67 extern OSVERSIONINFO osvi
;
68 extern BOOL bUnicodeOutput
;
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 first
, LPTSTR rest
, 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 BOOL
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 BOOL
OnOffCommand(LPTSTR param
, LPBOOL flag
, INT message
);
215 INT
CommandEcho (LPTSTR
);
216 INT
CommandEchos (LPTSTR
);
217 INT
CommandEchoerr (LPTSTR
);
218 INT
CommandEchoserr (LPTSTR
);
221 /* Prototypes for ERROR.C */
222 VOID
ErrorMessage (DWORD
, LPTSTR
, ...);
224 VOID
error_no_pipe (VOID
);
225 VOID
error_bad_command (LPTSTR
);
226 VOID
error_invalid_drive (VOID
);
227 VOID
error_req_param_missing (VOID
);
228 VOID
error_sfile_not_found (LPTSTR
);
229 VOID
error_file_not_found (VOID
);
230 VOID
error_path_not_found (VOID
);
231 VOID
error_too_many_parameters (LPTSTR
);
232 VOID
error_parameter_format(TCHAR
);
233 VOID
error_invalid_switch (TCHAR
);
234 VOID
error_invalid_parameter_format (LPTSTR
);
235 VOID
error_out_of_memory (VOID
);
236 VOID
error_syntax (LPTSTR
);
238 VOID
msg_pause (VOID
);
241 /* Prototypes for FILECOMP.C */
242 #ifdef FEATURE_UNIX_FILENAME_COMPLETION
243 VOID
CompleteFilename (LPTSTR
, UINT
);
244 INT
ShowCompletionMatches (LPTSTR
, INT
);
246 #ifdef FEATURE_4NT_FILENAME_COMPLETION
247 VOID
CompleteFilename (LPTSTR
, BOOL
, LPTSTR
, UINT
);
251 /* Prototypes for FOR.C */
252 #define FOR_DIRS 1 /* /D */
253 #define FOR_F 2 /* /F */
254 #define FOR_LOOP 4 /* /L */
255 #define FOR_RECURSIVE 8 /* /R */
256 INT
cmd_for (LPTSTR
);
257 BOOL
ExecuteFor(struct _PARSED_COMMAND
*Cmd
);
260 /* Prototypes for FREE.C */
261 INT
CommandFree (LPTSTR
);
264 /* Prototypes for GOTO.C */
265 INT
cmd_goto (LPTSTR
);
268 /* Prototypes for HISTORY.C */
269 #ifdef FEATURE_HISTORY
270 LPCTSTR
PeekHistory(INT
);
271 VOID
History (INT
, LPTSTR
);/*add entries browse history*/
272 VOID
History_move_to_bottom(VOID
);/*F3*/
273 VOID
InitHistory(VOID
);
274 VOID
CleanHistory(VOID
);
275 VOID
History_del_current_entry(LPTSTR str
);/*CTRL-D*/
276 INT
CommandHistory (LPTSTR param
);
280 /* Prototypes for IF.C */
281 #define IFFLAG_NEGATE 1 /* NOT */
282 #define IFFLAG_IGNORECASE 2 /* /I */
283 enum { IF_CMDEXTVERSION
, IF_DEFINED
, IF_ERRORLEVEL
, IF_EXIST
,
284 IF_STRINGEQ
, /* == */
285 IF_EQU
, IF_GTR
, IF_GEQ
, IF_LSS
, IF_LEQ
, IF_NEQ
};
286 BOOL
ExecuteIf(struct _PARSED_COMMAND
*Cmd
);
289 /* Prototypes for INTERNAL.C */
290 VOID
InitLastPath (VOID
);
291 VOID
FreeLastPath (VOID
);
292 INT
cmd_chdir (LPTSTR
);
293 INT
cmd_mkdir (LPTSTR
);
294 INT
cmd_rmdir (LPTSTR
);
295 INT
CommandExit (LPTSTR
);
296 INT
CommandRem (LPTSTR
);
297 INT
CommandShowCommands (LPTSTR
);
298 INT
CommandShowCommandsDetail (LPTSTR
);
300 /* Prototypes for LABEL.C */
301 INT
cmd_label (LPTSTR
);
304 /* Prototypes for LOCALE.C */
305 extern TCHAR cDateSeparator
;
306 extern INT nDateFormat
;
307 extern TCHAR cTimeSeparator
;
308 extern INT nTimeFormat
;
309 extern TCHAR cThousandSeparator
;
310 extern TCHAR cDecimalSeparator
;
311 extern INT nNumberGroups
;
314 VOID
InitLocale (VOID
);
315 LPTSTR
GetDateString (VOID
);
316 LPTSTR
GetTimeString (VOID
);
319 extern UINT InputCodePage
;
320 extern UINT OutputCodePage
;
322 /* Prototypes for MEMORY.C */
323 INT
CommandMemory (LPTSTR
);
326 /* Prototypes for MKLINK.C */
327 INT
cmd_mklink(LPTSTR
);
330 /* Prototypes for MISC.C */
331 INT
GetRootPath(TCHAR
*InPath
,TCHAR
*OutPath
,INT size
);
332 BOOL
SetRootPath(TCHAR
*oldpath
,TCHAR
*InPath
);
333 TCHAR
cgetchar (VOID
);
334 BOOL
CheckCtrlBreak (INT
);
335 BOOL
add_entry (LPINT ac
, LPTSTR
**arg
, LPCTSTR entry
);
336 LPTSTR
*split (LPTSTR
, LPINT
, BOOL
);
337 LPTSTR
*splitspace (LPTSTR
, LPINT
);
338 VOID
freep (LPTSTR
*);
339 LPTSTR
_stpcpy (LPTSTR
, LPCTSTR
);
340 VOID
StripQuotes(LPTSTR
);
341 BOOL
IsValidPathName (LPCTSTR
);
342 BOOL
IsExistingFile (LPCTSTR
);
343 BOOL
IsExistingDirectory (LPCTSTR
);
344 BOOL
FileGetString (HANDLE
, LPTSTR
, INT
);
345 VOID
GetPathCase(TCHAR
*, TCHAR
*);
350 #define PROMPT_BREAK 3
352 INT
PagePrompt (VOID
);
353 INT
FilePromptYN (UINT
);
354 INT
FilePromptYNA (UINT
);
357 /* Prototypes for MOVE.C */
358 INT
cmd_move (LPTSTR
);
361 /* Prototypes for MSGBOX.C */
362 INT
CommandMsgbox (LPTSTR
);
365 /* Prototypes from PARSER.C */
366 enum { C_COMMAND
, C_QUIET
, C_BLOCK
, C_MULTI
, C_IFFAILURE
, C_IFSUCCESS
, C_PIPE
, C_IF
, C_FOR
};
367 typedef struct _PARSED_COMMAND
369 struct _PARSED_COMMAND
*Subcommands
;
370 struct _PARSED_COMMAND
*Next
;
371 struct _REDIRECTION
*Redirections
;
393 struct tagFORCONTEXT
*Context
;
397 PARSED_COMMAND
*ParseCommand(LPTSTR Line
);
398 VOID
EchoCommand(PARSED_COMMAND
*Cmd
);
399 TCHAR
*Unparse(PARSED_COMMAND
*Cmd
, TCHAR
*Out
, TCHAR
*OutEnd
);
400 VOID
FreeCommand(PARSED_COMMAND
*Cmd
);
403 /* Prototypes from PATH.C */
404 INT
cmd_path (LPTSTR
);
407 /* Prototypes from PROMPT.C */
408 VOID
PrintPrompt (VOID
);
409 INT
cmd_prompt (LPTSTR
);
412 /* Prototypes for REDIR.C */
413 enum { REDIR_READ
, REDIR_WRITE
, REDIR_APPEND
};
414 typedef struct _REDIRECTION
416 struct _REDIRECTION
*Next
;
422 BOOL
PerformRedirection(REDIRECTION
*);
423 VOID
UndoRedirection(REDIRECTION
*, REDIRECTION
*End
);
424 INT
GetRedirection(LPTSTR
, REDIRECTION
**);
425 VOID
FreeRedirection(REDIRECTION
*);
428 /* Prototypes for REN.C */
429 INT
cmd_rename (LPTSTR
);
431 /* Prototypes for REN.C */
432 INT
cmd_replace (LPTSTR
);
434 /* Prototypes for SCREEN.C */
435 INT
CommandScreen (LPTSTR
);
438 /* Prototypes for SET.C */
439 INT
cmd_set (LPTSTR
);
441 /* Prototypes for SETLOCAL.C */
442 LPTSTR
DuplicateEnvironment(VOID
);
443 INT
cmd_setlocal (LPTSTR
);
444 INT
cmd_endlocal (LPTSTR
);
446 /* Prototypes for START.C */
447 INT
cmd_start (LPTSTR
);
450 /* Prototypes for STRTOCLR.C */
451 BOOL
StringToColor (LPWORD
, LPTSTR
*);
454 /* Prototypes for TIME.C */
455 INT
cmd_time (LPTSTR
);
458 /* Prototypes for TIMER.C */
459 INT
CommandTimer (LPTSTR param
);
462 /* Prototypes for TITLE.C */
463 INT
cmd_title (LPTSTR
);
466 /* Prototypes for TYPE.C */
467 INT
cmd_type (LPTSTR
);
470 /* Prototypes for VER.C */
471 VOID
ShortVersion (VOID
);
472 INT
cmd_ver (LPTSTR
);
475 /* Prototypes for VERIFY.C */
476 INT
cmd_verify (LPTSTR
);
479 /* Prototypes for VOL.C */
480 INT
cmd_vol (LPTSTR
);
483 /* Prototypes for WHERE.C */
484 BOOL
SearchForExecutable (LPCTSTR
, LPTSTR
);
486 /* Prototypes for WINDOW.C */
487 INT
CommandActivate (LPTSTR
);
488 INT
CommandWindow (LPTSTR
);
491 /* The MSDOS Batch Commands [MS-DOS 5.0 User's Guide and Reference p359] */
493 int cmd_pause(TCHAR
*);
494 int cmd_shift(TCHAR
*);
496 #endif /* _CMD_H_INCLUDED_ */