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 /* Version of the Command Extensions */ 32 #define CMDEXTVERSION 2 33 34 #define BREAK_BATCHFILE 1 35 #define BREAK_OUTOFBATCH 2 /* aka. BREAK_ENDOFBATCHFILES */ 36 #define BREAK_INPUT 3 37 #define BREAK_IGNORE 4 38 39 /* define some error messages */ 40 #define D_ON _T("on") 41 #define D_OFF _T("off") 42 43 /* command line buffer length */ 44 #define CMDLINE_LENGTH 8192 45 46 /* 16k = max buffer size */ 47 #define BUFF_SIZE 16384 48 49 /* Global variables */ 50 extern LPTSTR lpOriginalEnvironment; 51 extern WORD wColor; 52 extern WORD wDefColor; 53 extern BOOL bCtrlBreak; 54 extern BOOL bIgnoreEcho; 55 extern BOOL bExit; 56 extern BOOL bDisableBatchEcho; 57 extern BOOL bEnableExtensions; 58 extern BOOL bDelayedExpansion; 59 extern INT nErrorLevel; 60 61 62 /* Prototypes for ALIAS.C */ 63 VOID ExpandAlias (LPTSTR, INT); 64 INT CommandAlias (LPTSTR); 65 66 /* Prototypes for ASSOC.C */ 67 INT CommandAssoc (LPTSTR); 68 69 /* Prototypes for BEEP.C */ 70 INT cmd_beep (LPTSTR); 71 72 /* Prototypes for CALL.C */ 73 INT cmd_call (LPTSTR); 74 75 /* Prototypes for CHOICE.C */ 76 INT CommandChoice (LPTSTR); 77 78 /* Prototypes for CLS.C */ 79 INT cmd_cls (LPTSTR); 80 81 /* Prototypes for CMD.C */ 82 INT ConvertULargeInteger(ULONGLONG num, LPTSTR des, UINT len, BOOL bPutSeparator); 83 HANDLE RunFile(DWORD, LPTSTR, LPTSTR, LPTSTR, INT); 84 INT ParseCommandLine(LPTSTR); 85 struct _PARSED_COMMAND; 86 87 INT 88 ExecuteCommand( 89 IN struct _PARSED_COMMAND *Cmd); 90 91 INT 92 ExecuteCommandWithEcho( 93 IN struct _PARSED_COMMAND *Cmd); 94 95 LPCTSTR GetEnvVarOrSpecial ( LPCTSTR varName ); 96 VOID AddBreakHandler (VOID); 97 VOID RemoveBreakHandler (VOID); 98 99 BOOL 100 SubstituteVar( 101 IN PCTSTR Src, 102 OUT size_t* SrcIncLen, // VarNameLen 103 OUT PTCHAR Dest, 104 IN PTCHAR DestEnd, 105 OUT size_t* DestIncLen, 106 IN TCHAR Delim); 107 108 BOOL 109 SubstituteVars( 110 IN PCTSTR Src, 111 OUT PTSTR Dest, 112 IN TCHAR Delim); 113 114 BOOL 115 SubstituteForVars( 116 IN PCTSTR Src, 117 OUT PTSTR Dest); 118 119 PTSTR 120 DoDelayedExpansion( 121 IN PCTSTR Line); 122 123 INT DoCommand(LPTSTR first, LPTSTR rest, struct _PARSED_COMMAND *Cmd); 124 BOOL ReadLine(TCHAR *commandline, BOOL bMore); 125 126 extern HANDLE CMD_ModuleHandle; 127 128 129 /* Prototypes for CMDINPUT.C */ 130 BOOL ReadCommand (LPTSTR, INT); 131 132 extern TCHAR AutoCompletionChar; 133 extern TCHAR PathCompletionChar; 134 135 #define IS_COMPLETION_DISABLED(CompletionCtrl) \ 136 ((CompletionCtrl) == 0x00 || (CompletionCtrl) == 0x0D || (CompletionCtrl) >= 0x20) 137 138 139 /* Prototypes for CMDTABLE.C */ 140 #define CMD_SPECIAL 1 141 #define CMD_BATCHONLY 2 142 #define CMD_HIDE 4 143 144 typedef struct tagCOMMAND 145 { 146 LPTSTR name; 147 INT flags; 148 INT (*func)(LPTSTR); 149 } COMMAND, *LPCOMMAND; 150 151 extern COMMAND cmds[]; /* The internal command table */ 152 153 VOID PrintCommandList (VOID); 154 155 LPCTSTR GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA ); 156 157 /* Prototypes for CTTY.C */ 158 #ifdef INCLUDE_CMD_CTTY 159 INT cmd_ctty(LPTSTR); 160 #endif 161 162 /* Prototypes for COLOR.C */ 163 INT CommandColor(LPTSTR); 164 165 /* Prototypes for CONSOLE.C */ 166 #include "console.h" 167 168 /* Prototypes for COPY.C */ 169 INT cmd_copy (LPTSTR); 170 171 /* Prototypes for DATE.C */ 172 INT cmd_date (LPTSTR); 173 174 /* Prototypes for DEL.C */ 175 INT CommandDelete (LPTSTR); 176 177 /* Prototypes for DELAY.C */ 178 INT CommandDelay (LPTSTR); 179 180 /* Prototypes for DIR.C */ 181 INT FormatDate (TCHAR *, LPSYSTEMTIME, BOOL); 182 INT FormatTime (TCHAR *, LPSYSTEMTIME); 183 INT CommandDir (LPTSTR); 184 185 /* Prototypes for DIRSTACK.C */ 186 VOID InitDirectoryStack (VOID); 187 VOID DestroyDirectoryStack (VOID); 188 INT GetDirectoryStackDepth (VOID); 189 INT CommandPushd (LPTSTR); 190 INT CommandPopd (LPTSTR); 191 INT CommandDirs (LPTSTR); 192 193 /* Prototypes for ECHO.C */ 194 BOOL OnOffCommand(LPTSTR param, LPBOOL flag, INT message); 195 INT CommandEcho (LPTSTR); 196 INT CommandEchos (LPTSTR); 197 INT CommandEchoerr (LPTSTR); 198 INT CommandEchoserr (LPTSTR); 199 200 /* Prototypes for ERROR.C */ 201 VOID 202 ErrorMessage( 203 IN DWORD dwErrorCode, 204 IN PCTSTR szFormat OPTIONAL, 205 ...); 206 207 VOID error_no_pipe(VOID); 208 VOID error_bad_command(PCTSTR s); 209 VOID error_invalid_drive(VOID); 210 VOID error_req_param_missing(VOID); 211 VOID error_sfile_not_found(PCTSTR s); 212 VOID error_file_not_found(VOID); 213 VOID error_path_not_found(VOID); 214 VOID error_too_many_parameters(PCTSTR s); 215 VOID error_parameter_format(TCHAR ch); 216 VOID error_invalid_switch(TCHAR ch); 217 VOID error_invalid_parameter_format(PCTSTR s); 218 VOID error_out_of_memory(VOID); 219 VOID error_syntax(PCTSTR s); 220 221 VOID msg_pause(VOID); 222 223 /* Prototypes for FILECOMP.C */ 224 #ifdef FEATURE_UNIX_FILENAME_COMPLETION 225 VOID CompleteFilename (LPTSTR, UINT); 226 INT ShowCompletionMatches (LPTSTR, INT); 227 #endif 228 #ifdef FEATURE_4NT_FILENAME_COMPLETION 229 VOID CompleteFilename (LPTSTR, BOOL, LPTSTR, UINT); 230 #endif 231 232 233 /* Prototypes for FOR.C */ 234 #define FOR_DIRS 1 /* /D */ 235 #define FOR_F 2 /* /F */ 236 #define FOR_LOOP 4 /* /L */ 237 #define FOR_RECURSIVE 8 /* /R */ 238 INT cmd_for (LPTSTR); 239 INT ExecuteFor(struct _PARSED_COMMAND *Cmd); 240 241 242 /* Prototypes for FREE.C */ 243 INT CommandFree (LPTSTR); 244 245 /* Prototypes for GOTO.C */ 246 INT cmd_goto (LPTSTR); 247 248 /* Prototypes for HISTORY.C */ 249 #ifdef FEATURE_HISTORY 250 LPCTSTR PeekHistory(INT); 251 VOID History(INT, LPTSTR);/*add entries browse history*/ 252 VOID History_move_to_bottom(VOID);/*F3*/ 253 VOID InitHistory(VOID); 254 VOID CleanHistory(VOID); 255 VOID History_del_current_entry(LPTSTR str);/*CTRL-D*/ 256 INT CommandHistory(LPTSTR param); 257 #endif 258 259 /* Prototypes for IF.C */ 260 #define IFFLAG_NEGATE 1 /* NOT */ 261 #define IFFLAG_IGNORECASE 2 /* /I - Extended */ 262 typedef enum _IF_OPERATOR 263 { 264 /** Unary operators **/ 265 /* Standard */ 266 IF_ERRORLEVEL, IF_EXIST, 267 /* Extended */ 268 IF_CMDEXTVERSION, IF_DEFINED, 269 270 /** Binary operators **/ 271 /* Standard */ 272 IF_STRINGEQ, /* == */ 273 /* Extended */ 274 IF_EQU, IF_NEQ, IF_LSS, IF_LEQ, IF_GTR, IF_GEQ 275 } IF_OPERATOR; 276 277 INT ExecuteIf(struct _PARSED_COMMAND *Cmd); 278 279 /* Prototypes for INTERNAL.C */ 280 VOID InitLastPath (VOID); 281 VOID FreeLastPath (VOID); 282 INT cmd_chdir (LPTSTR); 283 INT cmd_mkdir (LPTSTR); 284 INT cmd_rmdir (LPTSTR); 285 INT CommandExit (LPTSTR); 286 INT CommandRem (LPTSTR); 287 INT CommandShowCommands (LPTSTR); 288 289 /* Prototypes for LOCALE.C */ 290 extern TCHAR cDateSeparator; 291 extern INT nDateFormat; 292 extern TCHAR cTimeSeparator; 293 extern INT nTimeFormat; 294 extern TCHAR cThousandSeparator; 295 extern TCHAR cDecimalSeparator; 296 extern INT nNumberGroups; 297 298 VOID InitLocale (VOID); 299 LPTSTR GetDateString (VOID); 300 LPTSTR GetTimeString (VOID); 301 302 /* Prototypes for MEMORY.C */ 303 INT CommandMemory (LPTSTR); 304 305 /* Prototypes for MKLINK.C */ 306 INT cmd_mklink(LPTSTR); 307 308 /* Prototypes for MISC.C */ 309 INT 310 GetRootPath( 311 IN LPCTSTR InPath, 312 OUT LPTSTR OutPath, 313 IN INT size); 314 315 BOOL SetRootPath(TCHAR *oldpath,TCHAR *InPath); 316 TCHAR cgetchar (VOID); 317 BOOL CheckCtrlBreak (INT); 318 BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry); 319 LPTSTR *split (LPTSTR, LPINT, BOOL, BOOL); 320 LPTSTR *splitspace (LPTSTR, LPINT); 321 VOID freep (LPTSTR *); 322 LPTSTR _stpcpy (LPTSTR, LPCTSTR); 323 VOID StripQuotes(LPTSTR); 324 325 BOOL IsValidPathName(IN LPCTSTR pszPath); 326 BOOL IsExistingFile(IN LPCTSTR pszPath); 327 BOOL IsExistingDirectory(IN LPCTSTR pszPath); 328 VOID GetPathCase(IN LPCTSTR Path, OUT LPTSTR OutPath); 329 330 #define PROMPT_NO 0 331 #define PROMPT_YES 1 332 #define PROMPT_ALL 2 333 #define PROMPT_BREAK 3 334 335 BOOL __stdcall PagePrompt(PCON_PAGER Pager, DWORD Done, DWORD Total); 336 INT FilePromptYN (UINT); 337 INT FilePromptYNA (UINT); 338 339 /* Prototypes for MOVE.C */ 340 INT cmd_move (LPTSTR); 341 342 /* Prototypes for MSGBOX.C */ 343 INT CommandMsgbox (LPTSTR); 344 345 /* Prototypes from PARSER.C */ 346 347 /* These three characters act like spaces to the parser in most contexts */ 348 #define STANDARD_SEPS _T(",;=") 349 350 typedef enum _COMMAND_TYPE 351 { 352 /* Standard command */ 353 C_COMMAND, 354 /* Quiet operator */ 355 C_QUIET, 356 /* Parenthesized block */ 357 C_BLOCK, 358 /* Operators */ 359 C_MULTI, C_OR, C_AND, C_PIPE, 360 /* Special parsed commands */ 361 C_FOR, C_IF, C_REM 362 } COMMAND_TYPE; 363 364 typedef struct _PARSED_COMMAND 365 { 366 /* 367 * For IF : this is the 'main' case (the 'else' is obtained via SubCmd->Next). 368 * For FOR: this is the list of all the subcommands in the DO. 369 */ 370 struct _PARSED_COMMAND *Subcommands; 371 372 struct _PARSED_COMMAND *Next; // Next command(s) in the chain. 373 struct _REDIRECTION *Redirections; 374 COMMAND_TYPE Type; 375 union 376 { 377 struct 378 { 379 PTSTR Rest; 380 TCHAR First[]; 381 } Command; 382 struct 383 { 384 BYTE Switches; 385 TCHAR Variable; 386 PTSTR Params; 387 PTSTR List; 388 struct _FOR_CONTEXT *Context; 389 } For; 390 struct 391 { 392 BYTE Flags; 393 IF_OPERATOR Operator; 394 PTSTR LeftArg; 395 PTSTR RightArg; 396 } If; 397 }; 398 } PARSED_COMMAND; 399 400 PARSED_COMMAND* 401 ParseCommand( 402 IN PCTSTR Line); 403 404 VOID 405 DumpCommand( 406 IN PARSED_COMMAND* Cmd, 407 IN ULONG SpacePad); 408 409 VOID 410 EchoCommand( 411 IN PARSED_COMMAND* Cmd); 412 413 PTCHAR 414 UnparseCommand( 415 IN PARSED_COMMAND* Cmd, 416 OUT PTCHAR Out, 417 IN PTCHAR OutEnd); 418 419 VOID 420 FreeCommand( 421 IN OUT PARSED_COMMAND* Cmd); 422 423 VOID ParseErrorEx(IN PCTSTR s); 424 extern BOOL bParseError; 425 extern TCHAR ParseLine[CMDLINE_LENGTH]; 426 427 extern BOOL bIgnoreParserComments; 428 extern BOOL bHandleContinuations; 429 430 /* Prototypes from PATH.C */ 431 INT cmd_path (LPTSTR); 432 433 /* Prototypes from PROMPT.C */ 434 VOID InitPrompt (VOID); 435 VOID PrintPrompt (VOID); 436 INT cmd_prompt (LPTSTR); 437 BOOL HasInfoLine(VOID); 438 439 /* Prototypes for REDIR.C */ 440 HANDLE GetHandle(UINT Number); 441 VOID SetHandle(UINT Number, HANDLE Handle); 442 443 typedef enum _REDIR_MODE 444 { 445 REDIR_READ = 0, 446 REDIR_WRITE = 1, 447 REDIR_APPEND = 2 448 } REDIR_MODE; 449 typedef struct _REDIRECTION 450 { 451 struct _REDIRECTION *Next; 452 HANDLE OldHandle; 453 BYTE Number; 454 REDIR_MODE Mode; 455 TCHAR Filename[]; 456 } REDIRECTION; 457 BOOL PerformRedirection(REDIRECTION *); 458 VOID UndoRedirection(REDIRECTION *, REDIRECTION *End); 459 INT GetRedirection(LPTSTR, REDIRECTION **); 460 VOID FreeRedirection(REDIRECTION *); 461 462 /* Prototypes for REN.C */ 463 INT cmd_rename (LPTSTR); 464 465 /* Prototypes for REN.C */ 466 INT cmd_replace (LPTSTR); 467 468 /* Prototypes for SCREEN.C */ 469 INT CommandScreen (LPTSTR); 470 471 /* Prototypes for SET.C */ 472 INT cmd_set (LPTSTR); 473 474 /* Prototypes for SETLOCAL.C */ 475 LPTSTR DuplicateEnvironment(VOID); 476 INT cmd_setlocal (LPTSTR); 477 INT cmd_endlocal (LPTSTR); 478 479 /* Prototypes for START.C */ 480 INT cmd_start (LPTSTR); 481 482 /* Prototypes for STRTOCLR.C */ 483 BOOL StringToColor (LPWORD, LPTSTR *); 484 485 /* Prototypes for TIME.C */ 486 INT cmd_time (LPTSTR); 487 488 /* Prototypes for TIMER.C */ 489 INT CommandTimer (LPTSTR param); 490 491 /* Prototypes for TITLE.C */ 492 INT cmd_title (LPTSTR); 493 494 /* Prototypes for TYPE.C */ 495 INT cmd_type (LPTSTR); 496 497 /* Prototypes for VER.C */ 498 VOID InitOSVersion(VOID); 499 VOID PrintOSVersion(VOID); 500 INT cmd_ver (LPTSTR); 501 502 /* Prototypes for VERIFY.C */ 503 INT cmd_verify (LPTSTR); 504 505 /* Prototypes for VOL.C */ 506 INT cmd_vol (LPTSTR); 507 508 /* Prototypes for WHERE.C */ 509 BOOL SearchForExecutable (LPCTSTR, LPTSTR); 510 511 /* Prototypes for WINDOW.C */ 512 INT CommandActivate (LPTSTR); 513 INT CommandWindow (LPTSTR); 514 515 /* The MSDOS Batch Commands [MS-DOS 5.0 User's Guide and Reference p359] */ 516 int cmd_if(TCHAR *); 517 int cmd_pause(TCHAR *); 518 int cmd_shift(TCHAR *); 519