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 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 enum { C_COMMAND, C_QUIET, C_BLOCK, C_MULTI, C_IFFAILURE, C_IFSUCCESS, C_PIPE, C_IF, C_FOR }; 305 typedef struct _PARSED_COMMAND 306 { 307 struct _PARSED_COMMAND *Subcommands; 308 struct _PARSED_COMMAND *Next; 309 struct _REDIRECTION *Redirections; 310 BYTE Type; 311 union 312 { 313 struct 314 { 315 TCHAR *Rest; 316 TCHAR First[]; 317 } Command; 318 struct 319 { 320 BYTE Flags; 321 BYTE Operator; 322 TCHAR *LeftArg; 323 TCHAR *RightArg; 324 } If; 325 struct 326 { 327 BYTE Switches; 328 TCHAR Variable; 329 LPTSTR Params; 330 LPTSTR List; 331 struct tagFORCONTEXT *Context; 332 } For; 333 }; 334 } PARSED_COMMAND; 335 PARSED_COMMAND *ParseCommand(LPTSTR Line); 336 VOID EchoCommand(PARSED_COMMAND *Cmd); 337 TCHAR *Unparse(PARSED_COMMAND *Cmd, TCHAR *Out, TCHAR *OutEnd); 338 VOID FreeCommand(PARSED_COMMAND *Cmd); 339 340 /* Prototypes from PATH.C */ 341 INT cmd_path (LPTSTR); 342 343 /* Prototypes from PROMPT.C */ 344 VOID InitPrompt (VOID); 345 VOID PrintPrompt (VOID); 346 INT cmd_prompt (LPTSTR); 347 348 /* Prototypes for REDIR.C */ 349 HANDLE GetHandle(UINT Number); 350 VOID SetHandle(UINT Number, HANDLE Handle); 351 352 typedef enum _REDIR_MODE 353 { 354 REDIR_READ = 0, 355 REDIR_WRITE = 1, 356 REDIR_APPEND = 2 357 } REDIR_MODE; 358 typedef struct _REDIRECTION 359 { 360 struct _REDIRECTION *Next; 361 HANDLE OldHandle; 362 BYTE Number; 363 REDIR_MODE Mode; 364 TCHAR Filename[]; 365 } REDIRECTION; 366 BOOL PerformRedirection(REDIRECTION *); 367 VOID UndoRedirection(REDIRECTION *, REDIRECTION *End); 368 INT GetRedirection(LPTSTR, REDIRECTION **); 369 VOID FreeRedirection(REDIRECTION *); 370 371 /* Prototypes for REN.C */ 372 INT cmd_rename (LPTSTR); 373 374 /* Prototypes for REN.C */ 375 INT cmd_replace (LPTSTR); 376 377 /* Prototypes for SCREEN.C */ 378 INT CommandScreen (LPTSTR); 379 380 /* Prototypes for SET.C */ 381 INT cmd_set (LPTSTR); 382 383 /* Prototypes for SETLOCAL.C */ 384 LPTSTR DuplicateEnvironment(VOID); 385 INT cmd_setlocal (LPTSTR); 386 INT cmd_endlocal (LPTSTR); 387 388 /* Prototypes for START.C */ 389 INT cmd_start (LPTSTR); 390 391 /* Prototypes for STRTOCLR.C */ 392 BOOL StringToColor (LPWORD, LPTSTR *); 393 394 /* Prototypes for TIME.C */ 395 INT cmd_time (LPTSTR); 396 397 /* Prototypes for TIMER.C */ 398 INT CommandTimer (LPTSTR param); 399 400 /* Prototypes for TITLE.C */ 401 INT cmd_title (LPTSTR); 402 403 /* Prototypes for TYPE.C */ 404 INT cmd_type (LPTSTR); 405 406 /* Prototypes for VER.C */ 407 VOID InitOSVersion(VOID); 408 VOID PrintOSVersion(VOID); 409 INT cmd_ver (LPTSTR); 410 411 /* Prototypes for VERIFY.C */ 412 INT cmd_verify (LPTSTR); 413 414 /* Prototypes for VOL.C */ 415 INT cmd_vol (LPTSTR); 416 417 /* Prototypes for WHERE.C */ 418 BOOL SearchForExecutable (LPCTSTR, LPTSTR); 419 420 /* Prototypes for WINDOW.C */ 421 INT CommandActivate (LPTSTR); 422 INT CommandWindow (LPTSTR); 423 424 /* The MSDOS Batch Commands [MS-DOS 5.0 User's Guide and Reference p359] */ 425 int cmd_if(TCHAR *); 426 int cmd_pause(TCHAR *); 427 int cmd_shift(TCHAR *); 428