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