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