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
;
58 extern WORD wDefColor
;
59 extern BOOL bCtrlBreak
;
60 extern BOOL bIgnoreEcho
;
62 extern BOOL bDelayedExpansion
;
63 extern INT nErrorLevel
;
66 extern OSVERSIONINFO osvi
;
70 /* Prototypes for ALIAS.C */
71 VOID
ExpandAlias (LPTSTR
, INT
);
72 INT
CommandAlias (LPTSTR
);
74 /* Prototypes for ASSOC.C */
75 INT
CommandAssoc (LPTSTR
);
77 /* Prototypes for ATTRIB.C */
78 INT
CommandAttrib (LPTSTR
);
81 /* Prototypes for BEEP.C */
82 INT
cmd_beep (LPTSTR
);
85 /* Prototypes for CALL.C */
86 INT
cmd_call (LPTSTR
);
89 /* Prototypes for CHCP.C */
90 INT
CommandChcp (LPTSTR
);
93 /* Prototypes for CHOICE.C */
94 INT
CommandChoice (LPTSTR
);
97 /* Prototypes for CLS.C */
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
[]);
117 extern HANDLE CMD_ModuleHandle
;
120 /* Prototypes for CMDINPUT.C */
121 VOID
ReadCommand (LPTSTR
, INT
);
124 /* Prototypes for CMDTABLE.C */
125 #define CMD_SPECIAL 1
126 #define CMD_BATCHONLY 2
129 typedef struct tagCOMMAND
134 } COMMAND
, *LPCOMMAND
;
136 extern COMMAND cmds
[]; /* The internal command table */
138 VOID
PrintCommandList (VOID
);
139 VOID
PrintCommandListDetail (VOID
);
142 LPCTSTR
GetParsedEnvVar ( LPCTSTR varName
, UINT
* varNameLen
, BOOL ModeSetA
);
144 /* Prototypes for COLOR.C */
145 VOID
SetScreenColor(WORD wArgColor
, BOOL bFill
);
146 INT
CommandColor (LPTSTR
);
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
);
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
, ...);
167 SHORT
GetCursorX (VOID
);
168 SHORT
GetCursorY (VOID
);
169 VOID
GetCursorXY (PSHORT
, PSHORT
);
170 VOID
SetCursorXY (SHORT
, SHORT
);
172 VOID
GetScreenSize (PSHORT
, PSHORT
);
173 VOID
SetCursorType (BOOL
, BOOL
);
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
);
181 /* Prototypes for COPY.C */
182 INT
cmd_copy (LPTSTR
);
185 /* Prototypes for DATE.C */
186 INT
cmd_date (LPTSTR
);
189 /* Prototypes for DEL.C */
190 INT
CommandDelete (LPTSTR
);
193 /* Prototypes for DELAY.C */
194 INT
CommandDelay (LPTSTR
);
197 /* Prototypes for DIR.C */
198 INT
FormatDate (TCHAR
*, LPSYSTEMTIME
, BOOL
);
199 INT
FormatTime (TCHAR
*, LPSYSTEMTIME
);
200 INT
CommandDir (LPTSTR
);
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
);
212 /* Prototypes for ECHO.C */
213 INT
CommandEcho (LPTSTR
);
214 INT
CommandEchos (LPTSTR
);
215 INT
CommandEchoerr (LPTSTR
);
216 INT
CommandEchoserr (LPTSTR
);
219 /* Prototypes for ERROR.C */
220 VOID
ErrorMessage (DWORD
, LPTSTR
, ...);
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
);
236 VOID
msg_pause (VOID
);
239 /* Prototypes for FILECOMP.C */
240 #ifdef FEATURE_UNIX_FILENAME_COMPLETION
241 VOID
CompleteFilename (LPTSTR
, UINT
);
242 INT
ShowCompletionMatches (LPTSTR
, INT
);
244 #ifdef FEATURE_4NT_FILENAME_COMPLETION
245 VOID
CompleteFilename (LPTSTR
, BOOL
, LPTSTR
, UINT
);
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
);
258 /* Prototypes for FREE.C */
259 INT
CommandFree (LPTSTR
);
262 /* Prototypes for GOTO.C */
263 INT
cmd_goto (LPTSTR
);
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
);
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
);
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
);
298 /* Prototypes for LABEL.C */
299 INT
cmd_label (LPTSTR
);
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
;
312 VOID
InitLocale (VOID
);
313 LPTSTR
GetDateString (VOID
);
314 LPTSTR
GetTimeString (VOID
);
317 extern UINT InputCodePage
;
318 extern UINT OutputCodePage
;
320 /* Prototypes for MEMORY.C */
321 INT
CommandMemory (LPTSTR
);
324 /* Prototypes for MKLINK.C */
325 INT
cmd_mklink(LPTSTR
);
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
*);
348 #define PROMPT_BREAK 3
350 INT
PagePrompt (VOID
);
351 INT
FilePromptYN (UINT
);
352 INT
FilePromptYNA (UINT
);
355 /* Prototypes for MOVE.C */
356 INT
cmd_move (LPTSTR
);
359 /* Prototypes for MSGBOX.C */
360 INT
CommandMsgbox (LPTSTR
);
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
367 struct _PARSED_COMMAND
*Subcommands
;
368 struct _PARSED_COMMAND
*Next
;
369 struct _REDIRECTION
*Redirections
;
391 struct tagFORCONTEXT
*Context
;
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
);
401 /* Prototypes from PATH.C */
402 INT
cmd_path (LPTSTR
);
405 /* Prototypes from PROMPT.C */
406 VOID
PrintPrompt (VOID
);
407 INT
cmd_prompt (LPTSTR
);
410 /* Prototypes for REDIR.C */
411 enum { REDIR_READ
, REDIR_WRITE
, REDIR_APPEND
};
412 typedef struct _REDIRECTION
414 struct _REDIRECTION
*Next
;
420 BOOL
PerformRedirection(REDIRECTION
*);
421 VOID
UndoRedirection(REDIRECTION
*, REDIRECTION
*End
);
422 INT
GetRedirection(LPTSTR
, REDIRECTION
**);
423 VOID
FreeRedirection(REDIRECTION
*);
426 /* Prototypes for REN.C */
427 INT
cmd_rename (LPTSTR
);
429 /* Prototypes for REN.C */
430 INT
cmd_replace (LPTSTR
);
432 /* Prototypes for SCREEN.C */
433 INT
CommandScreen (LPTSTR
);
436 /* Prototypes for SET.C */
437 INT
cmd_set (LPTSTR
);
439 /* Prototypes for SETLOCAL.C */
440 INT
cmd_setlocal (LPTSTR
);
441 INT
cmd_endlocal (LPTSTR
);
443 /* Prototypes for START.C */
444 INT
cmd_start (LPTSTR
);
447 /* Prototypes for STRTOCLR.C */
448 BOOL
StringToColor (LPWORD
, LPTSTR
*);
451 /* Prototypes for TIME.C */
452 INT
cmd_time (LPTSTR
);
455 /* Prototypes for TIMER.C */
456 INT
CommandTimer (LPTSTR param
);
459 /* Prototypes for TITLE.C */
460 INT
cmd_title (LPTSTR
);
463 /* Prototypes for TYPE.C */
464 INT
cmd_type (LPTSTR
);
467 /* Prototypes for VER.C */
468 VOID
ShortVersion (VOID
);
469 INT
cmd_ver (LPTSTR
);
472 /* Prototypes for VERIFY.C */
473 INT
cmd_verify (LPTSTR
);
476 /* Prototypes for VOL.C */
477 INT
cmd_vol (LPTSTR
);
480 /* Prototypes for WHERE.C */
481 BOOL
SearchForExecutable (LPCTSTR
, LPTSTR
);
483 /* Prototypes for WINDOW.C */
484 INT
CommandActivate (LPTSTR
);
485 INT
CommandWindow (LPTSTR
);
488 /* The MSDOS Batch Commands [MS-DOS 5.0 User's Guide and Reference p359] */
490 int cmd_pause(TCHAR
*);
491 int cmd_shift(TCHAR
*);
493 #endif /* _CMD_H_INCLUDED_ */