ReactOS 0.4.15-dev-7788-g1ad9096
cmd.h File Reference
#include <config.h>
#include "cmdver.h"
#include "cmddbg.h"
#include "console.h"
Include dependency graph for cmd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tagCOMMAND
 
struct  _PARSED_COMMAND
 
struct  _REDIRECTION
 

Macros

#define CMDEXTVERSION   2
 
#define BREAK_BATCHFILE   1
 
#define BREAK_OUTOFBATCH   2 /* aka. BREAK_ENDOFBATCHFILES */
 
#define BREAK_INPUT   3
 
#define BREAK_IGNORE   4
 
#define D_ON   _T("on")
 
#define D_OFF   _T("off")
 
#define CMDLINE_LENGTH   8192
 
#define BUFF_SIZE   16384
 
#define IS_COMPLETION_DISABLED(CompletionCtrl)    ((CompletionCtrl) == 0x00 || (CompletionCtrl) == 0x0D || (CompletionCtrl) >= 0x20)
 
#define CMD_SPECIAL   1
 
#define CMD_BATCHONLY   2
 
#define CMD_HIDE   4
 
#define FOR_DIRS   1 /* /D */
 
#define FOR_F   2 /* /F */
 
#define FOR_LOOP   4 /* /L */
 
#define FOR_RECURSIVE   8 /* /R */
 
#define IFFLAG_NEGATE   1 /* NOT */
 
#define IFFLAG_IGNORECASE   2 /* /I - Extended */
 
#define PROMPT_NO   0
 
#define PROMPT_YES   1
 
#define PROMPT_ALL   2
 
#define PROMPT_BREAK   3
 
#define STANDARD_SEPS   _T(",;=")
 

Typedefs

typedef struct tagCOMMAND COMMAND
 
typedef struct tagCOMMANDLPCOMMAND
 
typedef enum _IF_OPERATOR IF_OPERATOR
 
typedef enum _COMMAND_TYPE COMMAND_TYPE
 
typedef struct _PARSED_COMMAND PARSED_COMMAND
 
typedef enum _REDIR_MODE REDIR_MODE
 
typedef struct _REDIRECTION REDIRECTION
 

Enumerations

enum  _IF_OPERATOR {
  IF_ERRORLEVEL , IF_EXIST , IF_CMDEXTVERSION , IF_DEFINED ,
  IF_STRINGEQ , IF_EQU , IF_NEQ , IF_LSS ,
  IF_LEQ , IF_GTR , IF_GEQ
}
 
enum  _COMMAND_TYPE {
  C_COMMAND , C_QUIET , C_BLOCK , C_MULTI ,
  C_OR , C_AND , C_PIPE , C_FOR ,
  C_IF , C_REM
}
 
enum  _REDIR_MODE { REDIR_READ = 0 , REDIR_WRITE = 1 , REDIR_APPEND = 2 }
 

Functions

VOID ExpandAlias (LPTSTR, INT)
 
INT CommandAlias (LPTSTR)
 
INT CommandAssoc (LPTSTR)
 
INT cmd_beep (LPTSTR)
 
INT cmd_call (LPTSTR)
 
INT CommandChoice (LPTSTR)
 
INT cmd_cls (LPTSTR)
 
INT ConvertULargeInteger (ULONGLONG num, LPTSTR des, UINT len, BOOL bPutSeparator)
 
HANDLE RunFile (DWORD, LPTSTR, LPTSTR, LPTSTR, INT)
 
INT ParseCommandLine (LPTSTR)
 
INT ExecuteCommand (IN struct _PARSED_COMMAND *Cmd)
 
INT ExecuteCommandWithEcho (IN struct _PARSED_COMMAND *Cmd)
 
LPCTSTR GetEnvVarOrSpecial (LPCTSTR varName)
 
VOID AddBreakHandler (VOID)
 
VOID RemoveBreakHandler (VOID)
 
BOOL SubstituteVar (IN PCTSTR Src, OUT size_t *SrcIncLen, OUT PTCHAR Dest, IN PTCHAR DestEnd, OUT size_t *DestIncLen, IN TCHAR Delim)
 
BOOL SubstituteVars (IN PCTSTR Src, OUT PTSTR Dest, IN TCHAR Delim)
 
BOOL SubstituteForVars (IN PCTSTR Src, OUT PTSTR Dest)
 
PTSTR DoDelayedExpansion (IN PCTSTR Line)
 
INT DoCommand (LPTSTR first, LPTSTR rest, struct _PARSED_COMMAND *Cmd)
 
BOOL ReadLine (TCHAR *commandline, BOOL bMore)
 
BOOL ReadCommand (LPTSTR, INT)
 
VOID PrintCommandList (VOID)
 
LPCTSTR GetParsedEnvVar (LPCTSTR varName, UINT *varNameLen, BOOL ModeSetA)
 
INT CommandColor (LPTSTR)
 
INT cmd_copy (LPTSTR)
 
INT cmd_date (LPTSTR)
 
INT CommandDelete (LPTSTR)
 
INT CommandDelay (LPTSTR)
 
INT FormatDate (TCHAR *, LPSYSTEMTIME, BOOL)
 
INT FormatTime (TCHAR *, LPSYSTEMTIME)
 
INT CommandDir (LPTSTR)
 
VOID InitDirectoryStack (VOID)
 
VOID DestroyDirectoryStack (VOID)
 
INT GetDirectoryStackDepth (VOID)
 
INT CommandPushd (LPTSTR)
 
INT CommandPopd (LPTSTR)
 
INT CommandDirs (LPTSTR)
 
BOOL OnOffCommand (LPTSTR param, LPBOOL flag, INT message)
 
INT CommandEcho (LPTSTR)
 
INT CommandEchos (LPTSTR)
 
INT CommandEchoerr (LPTSTR)
 
INT CommandEchoserr (LPTSTR)
 
VOID ErrorMessage (IN DWORD dwErrorCode, IN PCTSTR szFormat OPTIONAL,...)
 
VOID error_no_pipe (VOID)
 
VOID error_bad_command (PCTSTR s)
 
VOID error_invalid_drive (VOID)
 
VOID error_req_param_missing (VOID)
 
VOID error_sfile_not_found (PCTSTR s)
 
VOID error_file_not_found (VOID)
 
VOID error_path_not_found (VOID)
 
VOID error_too_many_parameters (PCTSTR s)
 
VOID error_parameter_format (TCHAR ch)
 
VOID error_invalid_switch (TCHAR ch)
 
VOID error_invalid_parameter_format (PCTSTR s)
 
VOID error_out_of_memory (VOID)
 
VOID error_syntax (PCTSTR s)
 
VOID msg_pause (VOID)
 
INT cmd_for (LPTSTR)
 
INT ExecuteFor (struct _PARSED_COMMAND *Cmd)
 
INT CommandFree (LPTSTR)
 
INT cmd_goto (LPTSTR)
 
INT ExecuteIf (struct _PARSED_COMMAND *Cmd)
 
VOID InitLastPath (VOID)
 
VOID FreeLastPath (VOID)
 
INT cmd_chdir (LPTSTR)
 
INT cmd_mkdir (LPTSTR)
 
INT cmd_rmdir (LPTSTR)
 
INT CommandExit (LPTSTR)
 
INT CommandRem (LPTSTR)
 
INT CommandShowCommands (LPTSTR)
 
VOID InitLocale (VOID)
 
LPTSTR GetDateString (VOID)
 
LPTSTR GetTimeString (VOID)
 
INT CommandMemory (LPTSTR)
 
INT cmd_mklink (LPTSTR)
 
INT GetRootPath (IN LPCTSTR InPath, OUT LPTSTR OutPath, IN INT size)
 
BOOL SetRootPath (TCHAR *oldpath, TCHAR *InPath)
 
TCHAR cgetchar (VOID)
 
BOOL CheckCtrlBreak (INT)
 
BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry)
 
LPTSTRsplit (LPTSTR, LPINT, BOOL, BOOL)
 
LPTSTRsplitspace (LPTSTR, LPINT)
 
VOID freep (LPTSTR *)
 
LPTSTR _stpcpy (LPTSTR, LPCTSTR)
 
VOID StripQuotes (LPTSTR)
 
BOOL IsValidPathName (IN LPCTSTR pszPath)
 
BOOL IsExistingFile (IN LPCTSTR pszPath)
 
BOOL IsExistingDirectory (IN LPCTSTR pszPath)
 
VOID GetPathCase (TCHAR *, TCHAR *)
 
BOOL __stdcall PagePrompt (PCON_PAGER Pager, DWORD Done, DWORD Total)
 
INT FilePromptYN (UINT)
 
INT FilePromptYNA (UINT)
 
INT cmd_move (LPTSTR)
 
INT CommandMsgbox (LPTSTR)
 
PARSED_COMMANDParseCommand (IN PCTSTR Line)
 
VOID DumpCommand (IN PARSED_COMMAND *Cmd, IN ULONG SpacePad)
 
VOID EchoCommand (IN PARSED_COMMAND *Cmd)
 
PTCHAR UnparseCommand (IN PARSED_COMMAND *Cmd, OUT PTCHAR Out, IN PTCHAR OutEnd)
 
VOID FreeCommand (IN OUT PARSED_COMMAND *Cmd)
 
VOID ParseErrorEx (IN PCTSTR s)
 
INT cmd_path (LPTSTR)
 
VOID InitPrompt (VOID)
 
VOID PrintPrompt (VOID)
 
INT cmd_prompt (LPTSTR)
 
HANDLE GetHandle (UINT Number)
 
VOID SetHandle (UINT Number, HANDLE Handle)
 
BOOL PerformRedirection (REDIRECTION *)
 
VOID UndoRedirection (REDIRECTION *, REDIRECTION *End)
 
INT GetRedirection (LPTSTR, REDIRECTION **)
 
VOID FreeRedirection (REDIRECTION *)
 
INT cmd_rename (LPTSTR)
 
INT cmd_replace (LPTSTR)
 
INT CommandScreen (LPTSTR)
 
INT cmd_set (LPTSTR)
 
LPTSTR DuplicateEnvironment (VOID)
 
INT cmd_setlocal (LPTSTR)
 
INT cmd_endlocal (LPTSTR)
 
INT cmd_start (LPTSTR)
 
BOOL StringToColor (LPWORD, LPTSTR *)
 
INT cmd_time (LPTSTR)
 
INT CommandTimer (LPTSTR param)
 
INT cmd_title (LPTSTR)
 
INT cmd_type (LPTSTR)
 
VOID InitOSVersion (VOID)
 
VOID PrintOSVersion (VOID)
 
INT cmd_ver (LPTSTR)
 
INT cmd_verify (LPTSTR)
 
INT cmd_vol (LPTSTR)
 
BOOL SearchForExecutable (LPCTSTR, LPTSTR)
 
INT CommandActivate (LPTSTR)
 
INT CommandWindow (LPTSTR)
 
int cmd_if (TCHAR *)
 
int cmd_pause (TCHAR *)
 
int cmd_shift (TCHAR *)
 

Variables

LPTSTR lpOriginalEnvironment
 
WORD wColor
 
WORD wDefColor
 
BOOL bCtrlBreak
 
BOOL bIgnoreEcho
 
BOOL bExit
 
BOOL bDisableBatchEcho
 
BOOL bEnableExtensions
 
BOOL bDelayedExpansion
 
INT nErrorLevel
 
HANDLE CMD_ModuleHandle
 
TCHAR AutoCompletionChar
 
TCHAR PathCompletionChar
 
COMMAND cmds []
 
TCHAR cDateSeparator
 
INT nDateFormat
 
TCHAR cTimeSeparator
 
INT nTimeFormat
 
TCHAR cThousandSeparator
 
TCHAR cDecimalSeparator
 
INT nNumberGroups
 
BOOL bParseError
 
TCHAR ParseLine [CMDLINE_LENGTH]
 
BOOL bIgnoreParserComments
 
BOOL bHandleContinuations
 

Macro Definition Documentation

◆ BREAK_BATCHFILE

#define BREAK_BATCHFILE   1

Definition at line 34 of file cmd.h.

◆ BREAK_IGNORE

#define BREAK_IGNORE   4

Definition at line 37 of file cmd.h.

◆ BREAK_INPUT

#define BREAK_INPUT   3

Definition at line 36 of file cmd.h.

◆ BREAK_OUTOFBATCH

#define BREAK_OUTOFBATCH   2 /* aka. BREAK_ENDOFBATCHFILES */

Definition at line 35 of file cmd.h.

◆ BUFF_SIZE

#define BUFF_SIZE   16384

Definition at line 47 of file cmd.h.

◆ CMD_BATCHONLY

#define CMD_BATCHONLY   2

Definition at line 141 of file cmd.h.

◆ CMD_HIDE

#define CMD_HIDE   4

Definition at line 142 of file cmd.h.

◆ CMD_SPECIAL

#define CMD_SPECIAL   1

Definition at line 140 of file cmd.h.

◆ CMDEXTVERSION

#define CMDEXTVERSION   2

Definition at line 32 of file cmd.h.

◆ CMDLINE_LENGTH

#define CMDLINE_LENGTH   8192

Definition at line 44 of file cmd.h.

◆ D_OFF

#define D_OFF   _T("off")

Definition at line 41 of file cmd.h.

◆ D_ON

#define D_ON   _T("on")

Definition at line 40 of file cmd.h.

◆ FOR_DIRS

#define FOR_DIRS   1 /* /D */

Definition at line 234 of file cmd.h.

◆ FOR_F

#define FOR_F   2 /* /F */

Definition at line 235 of file cmd.h.

◆ FOR_LOOP

#define FOR_LOOP   4 /* /L */

Definition at line 236 of file cmd.h.

◆ FOR_RECURSIVE

#define FOR_RECURSIVE   8 /* /R */

Definition at line 237 of file cmd.h.

◆ IFFLAG_IGNORECASE

#define IFFLAG_IGNORECASE   2 /* /I - Extended */

Definition at line 261 of file cmd.h.

◆ IFFLAG_NEGATE

#define IFFLAG_NEGATE   1 /* NOT */

Definition at line 260 of file cmd.h.

◆ IS_COMPLETION_DISABLED

#define IS_COMPLETION_DISABLED (   CompletionCtrl)     ((CompletionCtrl) == 0x00 || (CompletionCtrl) == 0x0D || (CompletionCtrl) >= 0x20)

Definition at line 135 of file cmd.h.

◆ PROMPT_ALL

#define PROMPT_ALL   2

Definition at line 332 of file cmd.h.

◆ PROMPT_BREAK

#define PROMPT_BREAK   3

Definition at line 333 of file cmd.h.

◆ PROMPT_NO

#define PROMPT_NO   0

Definition at line 330 of file cmd.h.

◆ PROMPT_YES

#define PROMPT_YES   1

Definition at line 331 of file cmd.h.

◆ STANDARD_SEPS

#define STANDARD_SEPS   _T(",;=")

Definition at line 348 of file cmd.h.

Typedef Documentation

◆ COMMAND

◆ COMMAND_TYPE

◆ IF_OPERATOR

◆ LPCOMMAND

◆ PARSED_COMMAND

◆ REDIR_MODE

◆ REDIRECTION

Enumeration Type Documentation

◆ _COMMAND_TYPE

Enumerator
C_COMMAND 
C_QUIET 
C_BLOCK 
C_MULTI 
C_OR 
C_AND 
C_PIPE 
C_FOR 
C_IF 
C_REM 

Definition at line 350 of file cmd.h.

351{
352 /* Standard command */
353 C_COMMAND,
354 /* Quiet operator */
355 C_QUIET,
356 /* Parenthesized block */
357 C_BLOCK,
358 /* Operators */
360 /* Special parsed commands */
enum _COMMAND_TYPE COMMAND_TYPE
@ C_BLOCK
Definition: cmd.h:357
@ C_QUIET
Definition: cmd.h:355
@ C_OR
Definition: cmd.h:359
@ C_COMMAND
Definition: cmd.h:353
@ C_REM
Definition: cmd.h:361
@ C_AND
Definition: cmd.h:359
@ C_MULTI
Definition: cmd.h:359
@ C_IF
Definition: cmd.h:361
@ C_PIPE
Definition: cmd.h:359
@ C_FOR
Definition: cmd.h:361

◆ _IF_OPERATOR

Enumerator
IF_ERRORLEVEL 

Unary operators

IF_EXIST 
IF_CMDEXTVERSION 
IF_DEFINED 
IF_STRINGEQ 

Binary operators

IF_EQU 
IF_NEQ 
IF_LSS 
IF_LEQ 
IF_GTR 
IF_GEQ 

Definition at line 262 of file cmd.h.

263{
265 /* Standard */
267 /* Extended */
269
271 /* Standard */
272 IF_STRINGEQ, /* == */
273 /* Extended */
enum _IF_OPERATOR IF_OPERATOR
@ IF_CMDEXTVERSION
Definition: cmd.h:268
@ IF_ERRORLEVEL
Definition: cmd.h:266
@ IF_GTR
Definition: cmd.h:274
@ IF_EQU
Definition: cmd.h:274
@ IF_EXIST
Definition: cmd.h:266
@ IF_GEQ
Definition: cmd.h:274
@ IF_LSS
Definition: cmd.h:274
@ IF_LEQ
Definition: cmd.h:274
@ IF_STRINGEQ
Definition: cmd.h:272
@ IF_DEFINED
Definition: cmd.h:268
@ IF_NEQ
Definition: cmd.h:274

◆ _REDIR_MODE

Enumerator
REDIR_READ 
REDIR_WRITE 
REDIR_APPEND 

Definition at line 442 of file cmd.h.

443{
444 REDIR_READ = 0,
445 REDIR_WRITE = 1,
446 REDIR_APPEND = 2
447} REDIR_MODE;
enum _REDIR_MODE REDIR_MODE
@ REDIR_WRITE
Definition: cmd.h:445
@ REDIR_READ
Definition: cmd.h:444
@ REDIR_APPEND
Definition: cmd.h:446

Function Documentation

◆ _stpcpy()

LPTSTR _stpcpy ( LPTSTR  dest,
LPCTSTR  src 
)

Definition at line 460 of file misc.c.

461{
462 _tcscpy (dest, src);
463 return (dest + _tcslen (src));
464}
GLenum src
Definition: glext.h:6340
#define _tcscpy
Definition: tchar.h:623
static char * dest
Definition: rtl.c:135
#define _tcslen
Definition: xmlstorage.h:198

Referenced by BatchParams(), ExecuteAsync(), ForRecursive(), GetEnhancedVar(), ParseCommandPart(), ParseFor(), ParseRem(), and SubstituteForVars().

◆ add_entry()

BOOL add_entry ( LPINT  ac,
LPTSTR **  arg,
LPCTSTR  entry 
)

Definition at line 184 of file misc.c.

185{
186 LPTSTR q;
187 LPTSTR *oldarg;
188
189 q = cmd_alloc ((_tcslen(entry) + 1) * sizeof (TCHAR));
190 if (!q)
191 {
192 WARN("Cannot allocate memory for q!\n");
193 return FALSE;
194 }
195
196 _tcscpy (q, entry);
197 oldarg = *arg;
198 *arg = cmd_realloc (oldarg, (*ac + 2) * sizeof (LPTSTR));
199 if (!*arg)
200 {
201 WARN("Cannot reallocate memory for arg!\n");
202 *arg = oldarg;
203 cmd_free (q);
204 return FALSE;
205 }
206
207 /* save new entry */
208 (*arg)[*ac] = q;
209 (*arg)[++(*ac)] = NULL;
210
211 return TRUE;
212}
#define WARN(fmt,...)
Definition: debug.h:112
#define cmd_realloc(ptr, size)
Definition: cmddbg.h:30
#define cmd_free(ptr)
Definition: cmddbg.h:31
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
uint32_t entry
Definition: isohybrid.c:63
void * arg
Definition: msvc.h:10
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192

Referenced by expand(), split(), and splitspace().

◆ AddBreakHandler()

VOID AddBreakHandler ( VOID  )

Definition at line 1844 of file cmd.c.

1845{
1847}
static BOOL WINAPI BreakHandler(IN DWORD dwCtrlType)
Definition: cmd.c:1799
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, BOOL Add)
Definition: console.c:2109

Referenced by FilePromptYN(), FilePromptYNA(), Initialize(), and PagePrompt().

◆ cgetchar()

TCHAR cgetchar ( VOID  )

Definition at line 41 of file misc.c.

42{
44 INPUT_RECORD irBuffer;
45 DWORD dwRead;
46
47 do
48 {
49 ReadConsoleInput (hInput, &irBuffer, 1, &dwRead);
50 if ((irBuffer.EventType == KEY_EVENT) &&
51 (irBuffer.Event.KeyEvent.bKeyDown != FALSE))
52 {
53 if (irBuffer.Event.KeyEvent.dwControlKeyState &
55 {
56 if (irBuffer.Event.KeyEvent.wVirtualKeyCode == 'C')
57 {
59 break;
60 }
61 }
62 else if ((irBuffer.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
63 (irBuffer.Event.KeyEvent.wVirtualKeyCode == VK_MENU) ||
65 {
66 // Nothing to do
67 }
68 else
69 {
70 break;
71 }
72 }
73 }
74 while (TRUE);
75
76#ifndef _UNICODE
77 return irBuffer.Event.KeyEvent.uChar.AsciiChar;
78#else
79 return irBuffer.Event.KeyEvent.uChar.UnicodeChar;
80#endif /* _UNICODE */
81}
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
BOOL bCtrlBreak
Definition: cmd.c:154
unsigned long DWORD
Definition: ntddk_ex.h:95
union _INPUT_RECORD::@3287 Event
WORD EventType
Definition: wincon.h:273
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:275
DWORD dwControlKeyState
Definition: wincon.h:248
WORD wVirtualKeyCode
Definition: wincon.h:242
union _KEY_EVENT_RECORD::@3286 uChar
WCHAR UnicodeChar
Definition: wincon.h:245
#define STD_INPUT_HANDLE
Definition: winbase.h:267
#define LEFT_CTRL_PRESSED
Definition: wincon.h:140
#define ReadConsoleInput
Definition: wincon.h:778
#define KEY_EVENT
Definition: wincon.h:128
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:139
#define VK_CONTROL
Definition: winuser.h:2203
#define VK_SHIFT
Definition: winuser.h:2202
#define VK_MENU
Definition: winuser.h:2204

Referenced by CheckCtrlBreak(), cmd_pause(), and cmd_replace().

◆ CheckCtrlBreak()

BOOL CheckCtrlBreak ( INT  mode)

Definition at line 132 of file misc.c.

133{
134 static BOOL bLeaveAll = FALSE; /* leave all batch files */
135 TCHAR options[4]; /* Yes, No, All */
136 TCHAR c;
137
138 switch (mode)
139 {
140 case BREAK_OUTOFBATCH:
141 bLeaveAll = FALSE;
142 return FALSE;
143
144 case BREAK_BATCHFILE:
145 {
146 if (bLeaveAll)
147 return TRUE;
148
149 if (!bCtrlBreak)
150 return FALSE;
151
153
155 do
156 {
157 c = _totupper(cgetchar());
158 } while (!(_tcschr(options, c) || c == _T('\3')) || !c);
159
160 ConOutChar(_T('\n'));
161
162 if (c == options[1])
163 {
164 bCtrlBreak = FALSE; /* ignore */
165 return FALSE;
166 }
167
168 /* leave all batch files */
169 bLeaveAll = ((c == options[2]) || (c == _T('\3')));
170 break;
171 }
172
173 case BREAK_INPUT:
174 if (!bCtrlBreak)
175 return FALSE;
176 break;
177 }
178
179 /* state processed */
180 return TRUE;
181}
HANDLE CMD_ModuleHandle
Definition: cmd.c:165
#define BREAK_INPUT
Definition: cmd.h:36
#define BREAK_BATCHFILE
Definition: cmd.h:34
#define BREAK_OUTOFBATCH
Definition: cmd.h:35
VOID ConOutChar(TCHAR c)
Definition: console.c:123
#define ConOutResPuts(uID)
Definition: console.h:35
TCHAR cgetchar(VOID)
Definition: misc.c:41
#define STRING_COPY_OPTION
Definition: resource.h:20
#define STRING_CANCEL_BATCH_FILE
Definition: resource.h:240
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
unsigned int BOOL
Definition: ntddk_ex.h:94
const GLubyte * c
Definition: glext.h:8905
GLenum mode
Definition: glext.h:6217
#define _totupper
Definition: tchar.h:1509
#define _tcschr
Definition: tchar.h:1406
#define c
Definition: ke_i.h:80
#define _T(x)
Definition: vfdio.h:22
#define LoadString
Definition: winuser.h:5819

Referenced by cmd_copy(), CommandDir(), copy(), DirList(), DirPrintBareList(), DirPrintNewList(), DirPrintOldList(), DirPrintWideList(), ExitBatch(), ReadBatchLine(), ReadLine(), recReplace(), RemoveFile(), and replace().

◆ cmd_beep()

INT cmd_beep ( LPTSTR  param)

Definition at line 31 of file beep.c.

32{
33 if (_tcsncmp(param, _T("/?"), 2) == 0)
34 {
36 return 0;
37 }
38
39#if 0
40 /* check if run in batch mode */
41 if (bc == NULL)
42 return 1;
43#endif
44
46 return 0;
47}
#define StdOut
Definition: fc.c:14
PBATCH_CONTEXT bc
Definition: batch.c:67
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
VOID ConRingBell(HANDLE hOutput)
Definition: console.c:287
#define STRING_BEEP_HELP
Definition: resource.h:70
GLfloat param
Definition: glext.h:5796
#define _tcsncmp
Definition: tchar.h:1428
HANDLE ConStreamGetOSHandle(IN PCON_STREAM Stream)
Definition: stream.c:240

◆ cmd_call()

INT cmd_call ( LPTSTR  param)

Definition at line 40 of file call.c.

41{
43 BOOL bOldIgnoreParserComments;
44#ifndef MSCMD_CALL_QUIRKS
45 BOOL bOldHandleContinuations;
46#else
47 SIZE_T nNumCarets;
48#endif
50
51 TRACE("cmd_call(\'%s\')\n", debugstr_aw(param));
52
53 if (!_tcsncmp(param, _T("/?"), 2))
54 {
56 return 0;
57 }
58
59 /* Fail if no command or label has been provided */
60 if (*param == _T('\0'))
61 return (nErrorLevel = 1);
62
63 /* Ignore parser comments (starting with a colon) */
64 bOldIgnoreParserComments = bIgnoreParserComments;
66
67#ifndef MSCMD_CALL_QUIRKS
68 /* Disable parsing of escape carets */
69 bOldHandleContinuations = bHandleContinuations;
71 first = param;
72#else
73 /*
74 * As the original escape carets have been dealt with during the first
75 * command parsing step, the remaining ones need to be doubled so that
76 * they can again survive the new parsing step done below.
77 * But do it the Windows' CMD "buggy" way: **all** carets are doubled,
78 * even those inside quotes. However, this causes carets inside quotes
79 * to remain doubled after the parsing step...
80 */
81
82 /* Count all the carets */
83 nNumCarets = 0;
84 first = param;
85 while (first)
86 {
87 first = _tcschr(first, _T('^'));
88 if (first)
89 {
90 ++nNumCarets;
91 ++first;
92 }
93 }
94
95 /* Re-allocate a large enough parameter string if needed */
96 if (nNumCarets > 0)
97 {
98 PTCHAR Src, Dest, End;
99
100 // TODO: Improvement: Use the scratch TempBuf if the string is not too long.
101 first = cmd_alloc((_tcslen(param) + nNumCarets + 1) * sizeof(TCHAR));
102 if (!first)
103 {
104 WARN("Cannot allocate memory for new CALL parameter string!\n");
106 return (nErrorLevel = 1);
107 }
108
109 /* Copy the parameter string and double the escape carets */
110 Src = param;
111 Dest = first;
112 while (*Src)
113 {
114 if (*Src != _T('^'))
115 {
116 /* Copy everything before the next caret (or the end of the string) */
117 End = _tcschr(Src, _T('^'));
118 if (!End)
119 End = Src + _tcslen(Src);
120 memcpy(Dest, Src, (End - Src) * sizeof(TCHAR));
121 Dest += End - Src;
122 Src = End;
123 continue;
124 }
125
126 /* Copy the original caret and double it */
127 *Dest++ = *Src;
128 *Dest++ = *Src++;
129 }
130 *Dest = _T('\0');
131 }
132 else
133 {
134 first = param;
135 }
136#endif
137
138 /*
139 * Reparse the CALL parameter string as a command.
140 * Note that this will trigger a second round of %-variable substitutions.
141 */
143
144 /* Restore the global parsing state */
145#ifndef MSCMD_CALL_QUIRKS
146 bHandleContinuations = bOldHandleContinuations;
147#endif
148 bIgnoreParserComments = bOldIgnoreParserComments;
149
150 /*
151 * If no command is there, yet no error occurred, this means that
152 * a whitespace label was given. Do not consider this as a failure.
153 */
154 if (!Cmd && !bParseError)
155 {
156#ifdef MSCMD_CALL_QUIRKS
157 if (first != param)
159#endif
160 return (nErrorLevel = 0);
161 }
162
163 /* Reset bParseError so as to continue running afterwards */
165
166 /*
167 * Otherwise, if no command is there because a parse error occurred,
168 * or if this an unsupported command: not a standard one, including
169 * FOR and IF, fail and bail out.
170 */
171 if (!Cmd || (Cmd->Type == C_FOR) || (Cmd->Type == C_IF) ||
172 ((Cmd->Type != C_COMMAND) && (Cmd->Type != C_REM)))
173 {
174 // FIXME: Localize
175 ConErrPrintf(_T("%s was unexpected.\n"), first);
176
177#ifdef MSCMD_CALL_QUIRKS
178 if (first != param)
180#endif
181 if (Cmd) FreeCommand(Cmd);
182 return (nErrorLevel = 1);
183 }
184
185#ifdef MSCMD_CALL_QUIRKS
186 if (first != param)
188#endif
189
190 first = Cmd->Command.First;
191 param = Cmd->Command.Rest;
192
193 /* "CALL :label args ..." - Call a subroutine of the current batch file, only if extensions are enabled */
194 if (bEnableExtensions && (*first == _T(':')))
195 {
196 INT ret;
197
198 /* A batch context must be present */
199 if (!bc)
200 {
201 // FIXME: Localize
202 ConErrPuts(_T("Invalid attempt to call batch label outside of batch script.\n"));
204 return (nErrorLevel = 1);
205 }
206
208 nErrorLevel = (ret != 0 ? ret : nErrorLevel);
209 }
210 else
211 {
213 }
214
216 return nErrorLevel;
217}
INT nErrorLevel
Definition: cmd.c:158
PARSED_COMMAND * ParseCommand(IN PCTSTR Line)
Definition: parser.c:1461
BOOL bHandleContinuations
Definition: parser.c:97
BOOL bParseError
Definition: parser.c:90
BOOL bIgnoreParserComments
Definition: parser.c:96
VOID error_out_of_memory(VOID)
Definition: error.c:138
VOID FreeCommand(IN OUT PARSED_COMMAND *Cmd)
Definition: parser.c:527
#define ConErrPrintf(szStr,...)
Definition: console.h:44
#define ConErrPuts(szStr)
Definition: console.h:32
#define debugstr_aw
Definition: precomp.h:43
#define STRING_CALL_HELP
Definition: resource.h:71
static VOID DoCommand(PCONSOLE_STATE State, LPSTR line)
Definition: cmdcons.c:1082
const GLint * first
Definition: glext.h:5794
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
BOOL bEnableExtensions
Definition: more.c:53
char * PTCHAR
Definition: ntbasedef.h:476
@ Batch
Definition: ntsecapi.h:291
@ Cmd
Definition: sacdrv.h:278
#define TRACE(s)
Definition: solgame.cpp:4
TCHAR BatchFilePath[MAX_PATH]
Definition: batch.h:33
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int32_t INT
Definition: typedefs.h:58
int ret
CHAR * PTSTR
Definition: xmlstorage.h:191

◆ cmd_chdir()

INT cmd_chdir ( LPTSTR  param)

Definition at line 240 of file internal.c.

241{
242 BOOL bChangeDrive = FALSE;
243 LPTSTR tmp;
244 TCHAR szCurrent[MAX_PATH];
245
246 /* Filter out special cases first */
247
248 /* Print help */
249 if (!_tcsncmp(param, _T("/?"), 2))
250 {
252 return 0;
253 }
254
255 //
256 // FIXME: Use the split() tokenizer if bEnableExtensions == FALSE,
257 // so as to cut the parameter at the first separator (space, ',', ';'):
258 // - When bEnableExtensions == FALSE, doing
259 // CD system32;winsxs
260 // will go into system32, (but: CD "system32;winsxs" will fail as below), while
261 // - When bEnableExtensions == TRUE, it will fail because the "system32;winsxs"
262 // directory does not exist.
263 //
264
265 /* Remove extra quotes */
267
269 {
270 /* Strip trailing whitespace */
271 tmp = param + _tcslen(param) - 1;
272 while (tmp > param && _istspace(*tmp))
273 --tmp;
274 *(tmp + 1) = _T('\0');
275 }
276
277 /* Reset the error level */
278 nErrorLevel = 0;
279
280 /* Print the current directory on a disk */
281 if (_tcslen(param) == 2 && param[1] == _T(':'))
282 {
283 if (GetRootPath(param, szCurrent, ARRAYSIZE(szCurrent)))
284 {
286 return 1;
287 }
288 ConOutPrintf(_T("%s\n"), szCurrent);
289 return 0;
290 }
291
292 /* Get the current directory */
293 GetCurrentDirectory(ARRAYSIZE(szCurrent), szCurrent);
294 if (param[0] == _T('\0'))
295 {
296 ConOutPrintf(_T("%s\n"), szCurrent);
297 return 0;
298 }
299
300 /* If the input string is prefixed with the /D switch, change the drive */
301 if (!_tcsncicmp(param, _T("/D"), 2))
302 {
303 bChangeDrive = TRUE;
304 param += 2;
305 while (_istspace(*param))
306 ++param;
307 }
308
309 if (!SetRootPath(bChangeDrive ? NULL : szCurrent, param))
310 {
311 nErrorLevel = 1;
312 return 1;
313 }
314
315 return 0;
316}
VOID error_invalid_drive(VOID)
Definition: error.c:117
#define ConOutPrintf(szStr,...)
Definition: console.h:41
INT GetRootPath(IN LPCTSTR InPath, OUT LPTSTR OutPath, IN INT size)
Definition: internal.c:152
BOOL SetRootPath(TCHAR *oldpath, TCHAR *InPath)
Definition: internal.c:182
#define STRING_CD_HELP
Definition: resource.h:72
static VOID StripQuotes(LPSTR in)
Definition: cmdcons.c:116
#define MAX_PATH
Definition: compat.h:34
#define _istspace
Definition: tchar.h:1504
#define _tcsncicmp
Definition: tchar.h:1429
#define GetCurrentDirectory
Definition: winbase.h:3740

◆ cmd_cls()

INT cmd_cls ( LPTSTR  param)

Definition at line 33 of file cls.c.

34{
35 if (!_tcsncmp(param, _T("/?"), 2))
36 {
38 return 0;
39 }
40
42 return 0;
43}
CON_SCREEN StdOutScreen
Definition: attrib.c:30
#define STRING_CLS_HELP
Definition: resource.h:74
VOID ConClearScreen(IN PCON_SCREEN Screen)
Definition: screen.c:131

◆ cmd_copy()

INT cmd_copy ( LPTSTR  param)

Definition at line 332 of file copy.c.

333{
334 LPTSTR *arg;
335 INT argc, i, nFiles, nOverwrite = 0, nSrc = -1, nDes = -1;
336 /* this is the path up to the folder of the src and dest ie C:\windows\ */
337 TCHAR szDestPath[MAX_PATH];
338 TCHAR szSrcPath[MAX_PATH];
339 DWORD dwFlags = 0;
340 /* If this is the type of copy where we are adding files */
341 BOOL bAppend = FALSE;
342 WIN32_FIND_DATA findBuffer;
343 HANDLE hFile = NULL;
344 BOOL bTouch = FALSE;
345 /* Pointer to keep track of how far through the append input(file1+file2+file3) we are */
346 TCHAR * appendPointer = _T("\0");
347 /* The full path to src and dest. This has drive letter, folders, and filename */
348 TCHAR tmpDestPath[MAX_PATH];
349 TCHAR tmpSrcPath[MAX_PATH];
350 /* A bool to know whether or not the destination name will be taken from the input */
351 BOOL bSrcName = FALSE;
352 /* Seems like a waste but it is a pointer used to copy from input to PreserveName */
353 TCHAR * UseThisName;
354 /* for CMDCOPY env */
355 TCHAR *evar;
356 int size;
357 TCHAR * szTouch;
358 BOOL bHasWildcard, bDone = FALSE, bMoreFiles = FALSE;
359 /* Used for something like "copy c*.exe d*.exe" */
360 BOOL bMultipleSource = FALSE, bMultipleDest = FALSE;
361
362
363 /* Show help/usage info */
364 if (!_tcsncmp(param, _T("/?"), 2))
365 {
367 return 0;
368 }
369
370 nErrorLevel = 0;
371
372 /* Get the env variable value if it exists */
373 evar = cmd_alloc(512 * sizeof(TCHAR));
374 if (evar == NULL)
375 size = 0;
376 else
377 size = GetEnvironmentVariable (_T("COPYCMD"), evar, 512);
378
379 if (size > 512)
380 {
381 TCHAR *old_evar = evar;
382 evar = cmd_realloc(evar,size * sizeof(TCHAR) );
383 if (evar!=NULL)
384 size = GetEnvironmentVariable (_T("COPYCMD"), evar, size);
385 else
386 {
387 size=0;
388 evar = old_evar;
389 }
390 }
391
392 /* check see if we did get any env variable */
393 if (size != 0)
394 {
395 int t = 0;
396
397 /* scan and set the flags */
398 for (t = 0; t < size; t++)
399 {
400 if (_tcsncicmp(_T("/A"),&evar[t],2) == 0)
401 {
403 t++;
404 }
405 else if (_tcsncicmp(_T("/B"),&evar[t],2) == 0)
406 {
408 t++;
409 }
410 else if (_tcsncicmp(_T("/D"),&evar[t],2) == 0)
411 {
413 t++;
414 }
415 else if (_tcsncicmp(_T("/V"),&evar[t],2) == 0)
416 {
418 t++;
419 }
420 else if (_tcsncicmp(_T("/N"),&evar[t],2) == 0)
421 {
423 t++;
424 }
425 else if (_tcsncicmp(_T("/Y"),&evar[t],2) == 0)
426 {
428 t++;
429 }
430 else if (_tcsncicmp(_T("/-Y"),&evar[t],3) == 0)
431 {
433 t+=2;
434 }
435 else if (_tcsncicmp(_T("/Z"),&evar[t],2) == 0)
436 {
438 t++;
439 }
440 }
441 }
442 cmd_free(evar);
443
444
445 /* Split the user input into array */
446 arg = split(param, &argc, FALSE, TRUE);
447 nFiles = argc;
448
449 /* Read switches and count files */
450 for (i = 0; i < argc; i++)
451 {
452 if (*arg[i] == _T('/'))
453 {
454 if (_tcslen(arg[i]) >= 2)
455 {
456 switch (_totupper(arg[i][1]))
457 {
458 case _T('A'):
460 break;
461
462 case _T('B'):
464 break;
465
466 case _T('D'):
468 break;
469
470 case _T('V'):
472 break;
473
474 case _T('N'):
476 break;
477
478 case _T('Y'):
480 dwFlags &= ~COPY_PROMPT;
481 break;
482
483 case _T('-'):
484 if (_tcslen(arg[i]) >= 3)
485 {
486 if (_totupper(arg[i][2]) == _T('Y'))
487 {
488 dwFlags &= ~COPY_NO_PROMPT;
490 }
491 }
492
493 break;
494
495 case _T('Z'):
497 break;
498
499 default:
500 /* Invalid switch */
502 nErrorLevel = 1;
503 freep (arg);
504 return 1;
505 break;
506 }
507 }
508 /* If it was a switch, subtract from total arguments */
509 nFiles--;
510 }
511 else
512 {
513 /* If it isn't a switch then it is the source or destination */
514 if (nSrc == -1)
515 {
516 nSrc = i;
517 }
518 else if (*arg[i] == _T('+'))
519 {
520 /* Next file should be appended */
521 bMoreFiles = TRUE;
522 nFiles -= 1;
523 }
524 else if (bMoreFiles)
525 {
526 /* Add this file to the source string
527 this way we can do all checks
528 directly on source string later on */
529 TCHAR * ptr;
530 int length = (_tcslen(arg[nSrc]) + _tcslen(arg[i]) + 2) * sizeof(TCHAR);
532 if (ptr)
533 {
534 _tcscpy(ptr, arg[nSrc]);
535 _tcscat(ptr, _T("|"));
536 _tcscat(ptr, arg[i]);
537 cmd_free(arg[nSrc]);
538 arg[nSrc] = ptr;
539 nFiles -= 1;
540 }
541
542 bMoreFiles = FALSE;
543 }
544 else if (nDes == -1)
545 {
546 nDes = i;
547 }
548 }
549 }
550
551 /* keep quiet within batch files */
552 if (bc != NULL)
553 {
555 dwFlags &= ~COPY_PROMPT;
556 }
557
558 if (nFiles < 1)
559 {
560 /* There are not enough files, there has to be at least 1 */
562 freep(arg);
563 return 1;
564 }
565
566 if (nFiles > 2)
567 {
568 /* There are too many file names in command */
570 nErrorLevel = 1;
571 freep(arg);
572 return 1;
573 }
574
575 if ((_tcschr(arg[nSrc], _T('|')) != NULL) ||
576 (_tcschr(arg[nSrc], _T('*')) != NULL) ||
577 (_tcschr(arg[nSrc], _T('?')) != NULL) ||
579 {
580 bMultipleSource = TRUE;
581 }
582
583 /* Reuse the number of files variable */
584 nFiles = 0;
585
586 /* Check if no destination argument is passed */
587 if (nDes == -1)
588 {
589 /* If no destination was entered then just use
590 the current directory as the destination */
591 GetCurrentDirectory(ARRAYSIZE(szDestPath), szDestPath);
592 }
593 else
594 {
595 /* Check if the destination is 'x:' */
596 if ((arg[nDes][1] == _T(':')) && (arg[nDes][2] == _T('\0')))
597 {
598 GetRootPath(arg[nDes], szDestPath, ARRAYSIZE(szDestPath));
599 }
600 else
601 {
602 /* If the user entered two file names then form the full string path */
603 GetFullPathName(arg[nDes], ARRAYSIZE(szDestPath), szDestPath, NULL);
604 }
605
606 /* Make sure there is an ending slash to the path if the dest is a folder */
607 if ((_tcschr(szDestPath, _T('*')) == NULL) &&
608 IsExistingDirectory(szDestPath))
609 {
610 bMultipleDest = TRUE;
611 if (szDestPath[_tcslen(szDestPath) - 1] != _T('\\'))
612 _tcscat(szDestPath, _T("\\"));
613 }
614
615 /* Check if the destination uses wildcards */
616 if ((_tcschr(arg[nDes], _T('*')) != NULL) ||
617 (_tcschr(arg[nDes], _T('?')) != NULL))
618 {
619 bMultipleDest = TRUE;
620 }
621 }
622
623 if (nDes != -1) /* Append files only when there is a destination */
624 {
625 if (bMultipleSource && !bMultipleDest)
626 {
627 /* We have multiple source files, but not multiple destination
628 files. This means we are appending the source files. */
629 bAppend = TRUE;
630 if (_tcschr(arg[nSrc], _T('|')) != NULL)
631 appendPointer = arg[nSrc];
632 }
633 }
634
635 /* Save the name the user entered */
636 UseThisName = _tcsrchr(szDestPath,_T('\\'));
637 if (UseThisName)
638 {
639 /* Split the name from the path */
640 *UseThisName++ = _T('\0');
641
642 /* Check if the dest path ends with '\*' or '\' */
643 if (((UseThisName[0] == _T('*')) && (UseThisName[1] == _T('\0'))) ||
644 (UseThisName[0] == _T('\0')))
645 {
646 /* In this case we will be using the same name as the source file
647 for the destination file because destination is a folder */
648 bSrcName = TRUE;
649 UseThisName = NULL;
650 }
651 }
652 else
653 {
654 /* Something's seriously wrong! */
655 UseThisName = szDestPath;
656 }
657
658 do
659 {
660 /* Get the full string of the path to the source file */
661 if (_tcschr(arg[nSrc], _T('|')) != NULL)
662 {
663 /* Reset the source path */
664 szSrcPath[0] = _T('\0');
665
666 /* Loop through the source file name and copy all
667 the chars one at a time until we reach the separator */
668 while(TRUE)
669 {
670 if (appendPointer[0] == _T('|'))
671 {
672 /* Skip the | and go to the next file name */
673 appendPointer++;
674 break;
675 }
676 else if (appendPointer[0] == _T('\0'))
677 {
678 bDone = TRUE;
679 break;
680 }
681
682 _tcsncat(szSrcPath, appendPointer, 1);
683 appendPointer++;
684 }
685
686 if (_tcschr(arg[nSrc], _T(',')) != NULL)
687 {
688 /* Only time there is a , in the source is when they are using touch
689 Cant have a destination and can only have on ,, at the end of the string
690 Cant have more than one file name */
691 szTouch = _tcsstr(arg[nSrc], _T("|"));
692 if (_tcsncmp(szTouch,_T("|,,\0"), 4) || (nDes != -1))
693 {
695 nErrorLevel = 1;
696 freep (arg);
697 return 1;
698 }
699 bTouch = TRUE;
700 bDone = TRUE;
701 }
702 }
703 else
704 {
705 bDone = TRUE;
706 _tcscpy(szSrcPath, arg[nSrc]);
707 }
708
709 /* "x:" is not a valid source path format. */
710 if ((szSrcPath[1] == _T(':')) && (szSrcPath[2] == _T('\0')))
711 {
712 ConOutPrintf(_T("%s\n"), szSrcPath);
714 nErrorLevel = 1;
715 break;
716 }
717
718
719 /* From this point on, we can assume that the shortest path is
720 3 letters long and that would be [DriveLetter]:\ */
721
722 /* Check if the path has a wildcard */
723 bHasWildcard = (_tcschr(szSrcPath, _T('*')) != NULL);
724
725 /* If there is no * in the path name and it is a folder then we will
726 need to add a wildcard to the pathname so FindFirstFile comes up
727 with all the files in that folder */
728 if (!bHasWildcard && IsExistingDirectory(szSrcPath))
729 {
730 /* If it doesnt have a \ at the end already then on needs to be added */
731 if (szSrcPath[_tcslen(szSrcPath) - 1] != _T('\\'))
732 _tcscat(szSrcPath, _T("\\"));
733 _tcscat(szSrcPath, _T("*"));
734 bHasWildcard = TRUE;
735 }
736
737 /* If the path ends with '\' add a wildcard at the end */
738 if (szSrcPath[_tcslen(szSrcPath) - 1] == _T('\\'))
739 {
740 _tcscat(szSrcPath, _T("*"));
741 bHasWildcard = TRUE;
742 }
743
744 /* Get a list of all the files */
745 hFile = FindFirstFile(szSrcPath, &findBuffer);
746
747 /* If we could not open the file handle, print out the error */
749 {
750 /* only print source name when more than one file */
751 if (bMultipleSource)
752 ConOutPrintf(_T("%s\n"), szSrcPath);
753
754 ConOutFormatMessage(GetLastError(), szSrcPath);
755 freep(arg);
756 nErrorLevel = 1;
757 return 1;
758 }
759
760 /* Strip the paths back to the folder they are in */
761 for (i = (_tcslen(szSrcPath) - 1); i > -1; i--)
762 {
763 if (szSrcPath[i] != _T('\\'))
764 szSrcPath[i] = _T('\0');
765 else
766 break;
767 }
768
769 do
770 {
771 /* Check Breaker */
773 {
775 freep(arg);
776 return 1;
777 }
778
779 /* Set the override to yes each new file */
780 nOverwrite = 1;
781
782 /* Ignore the . and .. files */
783 if (!_tcscmp(findBuffer.cFileName, _T(".")) ||
784 !_tcscmp(findBuffer.cFileName, _T("..")) ||
785 findBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
786 {
787 continue;
788 }
789
790 /* Copy the base folder over to a tmp string */
791 _tcscpy(tmpDestPath, szDestPath);
792 _tcscat(tmpDestPath, _T("\\"));
793
794 /* Can't put a file into a folder that isn't there */
795 if (_tcscmp(tmpDestPath, _T("\\\\.\\")) &&
796 !IsExistingDirectory(tmpDestPath))
797 {
799 ConOutFormatMessage(GetLastError(), szSrcPath);
800 freep(arg);
801 nErrorLevel = 1;
802 return 1;
803 }
804
805 /* Copy over the destination path name */
806 if (bSrcName)
807 _tcscat(tmpDestPath, findBuffer.cFileName);
808 else
809 {
810 /* If there is no wildcard, use the name the user entered */
811 if ((_tcschr(UseThisName, _T('*')) == NULL) &&
812 (_tcschr(UseThisName, _T('?')) == NULL))
813 {
814 _tcscat(tmpDestPath, UseThisName);
815 }
816 else
817 {
818 TCHAR DoneFile[MAX_PATH];
819
820 BuildFileName(findBuffer.cFileName,
821 UseThisName,
822 DoneFile);
823
824
825 /* Add the filename to the tmp string path */
826 _tcscat(tmpDestPath, DoneFile);
827 }
828 }
829
830 /* Build the string path to the source file */
831 _tcscpy(tmpSrcPath,szSrcPath);
832 _tcscat (tmpSrcPath, findBuffer.cFileName);
833
834 /* Check to see if the file is the same file */
835 if (!bTouch && !_tcscmp(tmpSrcPath, tmpDestPath))
836 {
838
839 nErrorLevel = 1;
840 break;
841 }
842
843 /* only print source name when more than one file */
844 if (bMultipleSource)
845 ConOutPrintf(_T("%s\n"), tmpSrcPath);
846
847 /* Handle any overriding / prompting that needs to be done */
848 if (((!(dwFlags & COPY_NO_PROMPT) && IsExistingFile (tmpDestPath)) || dwFlags & COPY_PROMPT) && !bTouch)
849 nOverwrite = CopyOverwrite(tmpDestPath);
850 if (nOverwrite == PROMPT_NO || nOverwrite == PROMPT_BREAK)
851 continue;
852 if (nOverwrite == PROMPT_ALL || (nOverwrite == PROMPT_YES && bAppend))
854
855 /* Tell whether the copy was successful or not */
856 if (copy(tmpSrcPath,tmpDestPath, bAppend, dwFlags, bTouch))
857 {
858 nFiles++;
859 }
860 else
861 {
862 /* print out the error message */
864 ConOutFormatMessage (GetLastError(), szSrcPath);
865 nErrorLevel = 1;
866 }
867
868 /* Loop through all wildcard files */
869 } while (FindNextFile(hFile, &findBuffer));
870
872
873 /* Loop through all files in src string with a + */
874 } while (!bDone);
875
876 /* print out the number of files copied */
877 ConOutResPrintf(STRING_COPY_FILE, bAppend ? 1 : nFiles);
878
879 if (arg != NULL)
880 freep(arg);
881
882 return 0;
883}
static int argc
Definition: ServiceArgs.c:12
#define STRING_ERROR_INVALID_PARAM_FORMAT
Definition: resource.h:5
BOOL IsExistingDirectory(IN LPCTSTR pszPath)
Definition: misc.c:504
BOOL IsExistingFile(IN LPCTSTR pszPath)
Definition: misc.c:498
INT GetRootPath(IN LPCTSTR InPath, OUT LPTSTR OutPath, IN INT size)
Definition: internal.c:152
#define PROMPT_YES
Definition: cmd.h:331
BOOL CheckCtrlBreak(INT)
Definition: misc.c:132
#define PROMPT_NO
Definition: cmd.h:330
#define PROMPT_ALL
Definition: cmd.h:332
#define PROMPT_BREAK
Definition: cmd.h:333
#define ConOutResPrintf(uID,...)
Definition: console.h:47
#define ConErrResPrintf(uID,...)
Definition: console.h:50
#define ConOutFormatMessage(MessageId,...)
Definition: console.h:53
INT copy(TCHAR source[MAX_PATH], TCHAR dest[MAX_PATH], INT append, DWORD lpdwFlags, BOOL bTouch)
Definition: copy.c:51
static INT CopyOverwrite(LPTSTR fn)
Definition: copy.c:285
static void BuildFileName(LPTSTR pszSource, LPTSTR pszTarget, LPTSTR pszOutput)
Definition: copy.c:297
@ COPY_VERIFY
Definition: copy.c:42
@ COPY_RESTART
Definition: copy.c:46
@ COPY_SHORTNAME
Definition: copy.c:43
@ COPY_NO_PROMPT
Definition: copy.c:44
@ COPY_DECRYPT
Definition: copy.c:41
@ COPY_BINARY
Definition: copy.c:47
@ COPY_PROMPT
Definition: copy.c:45
@ COPY_ASCII
Definition: copy.c:40
#define STRING_COPY_HELP2
Definition: resource.h:94
#define STRING_COPY_ERROR2
Definition: resource.h:36
#define STRING_COPY_FILE
Definition: resource.h:208
#define STRING_ERROR_INVALID_SWITCH
Definition: resource.h:6
#define STRING_ERROR_TOO_MANY_PARAMETERS
Definition: resource.h:7
#define STRING_COPY_ERROR3
Definition: resource.h:37
#define STRING_ERROR_REQ_PARAM_MISSING
Definition: resource.h:10
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
static LPSTR * split(LPSTR s, LPINT args)
Definition: cmdcons.c:163
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
GLdouble GLdouble t
Definition: gl.h:2047
GLsizeiptr size
Definition: glext.h:5919
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define _tcscmp
Definition: tchar.h:1424
#define _tcscat
Definition: tchar.h:622
#define _tcsncat
Definition: tchar.h:1408
if(dx< 0)
Definition: linetemp.h:194
#define _tcsrchr
Definition: utility.h:116
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static PVOID ptr
Definition: dispmode.c:27
_In_ HANDLE hFile
Definition: mswsock.h:90
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define GetEnvironmentVariable
Definition: winbase.h:3749
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FindNextFile
Definition: winbase.h:3723
#define FindFirstFile
Definition: winbase.h:3717
#define GetFullPathName
Definition: winbase.h:3756
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define _tcsstr
Definition: xmlstorage.h:199

◆ cmd_date()

INT cmd_date ( LPTSTR  param)

Definition at line 176 of file date.c.

177{
178 LPTSTR* arg;
179 INT argc;
180 INT i;
181 BOOL bPrompt = TRUE;
182 INT nDateString = -1;
183 TCHAR szDate[40];
184
185 if (!_tcsncmp(param, _T("/?"), 2))
186 {
188 return 0;
189 }
190
191 nErrorLevel = 0;
192
193 /* Build the parameter array */
194 arg = split(param, &argc, FALSE, FALSE);
195
196 /* Check for options */
197 for (i = 0; i < argc; i++)
198 {
199 if (bEnableExtensions && (_tcsicmp(arg[i], _T("/T")) == 0))
200 bPrompt = FALSE;
201
202 if ((*arg[i] != _T('/')) && (nDateString == -1))
203 nDateString = i;
204 }
205
206 // TODO: Should prepend a "Current date is: " prompt, as done with TIME.
207 if (nDateString == -1)
208 ConOutPrintf(_T("%s\n"), GetDateString());
209
210 if (!bPrompt)
211 {
212 freep(arg);
213 return 0;
214 }
215
216 while (TRUE)
217 {
218 if (nDateString == -1)
219 {
221 ConInString(szDate, ARRAYSIZE(szDate));
222
223 TRACE("\'%s\'\n", debugstr_aw(szDate));
224
225 while (*szDate && szDate[_tcslen(szDate) - 1] < _T(' '))
226 szDate[_tcslen(szDate) - 1] = _T('\0');
227
228 if (ParseDate(szDate))
229 {
230 freep(arg);
231 return 0;
232 }
233 }
234 else
235 {
236 if (ParseDate(arg[nDateString]))
237 {
238 freep(arg);
239 return 0;
240 }
241
242 /* Force input the next time around */
243 nDateString = -1;
244 }
245
247 nErrorLevel = 1;
248 }
249
250 freep(arg);
251 return 0;
252}
LPTSTR GetDateString(VOID)
Definition: locale.c:58
#define ConErrResPuts(uID)
Definition: console.h:38
static BOOL ParseDate(LPTSTR s)
Definition: date.c:93
static VOID PromptDateString(VOID)
Definition: date.c:47
#define STRING_DATE_ERROR
Definition: resource.h:39
#define STRING_DATE_HELP4
Definition: resource.h:99
static VOID ConInString(LPWSTR lpInput, DWORD dwLength)
Definition: label.c:56
#define _tcsicmp
Definition: xmlstorage.h:205

Referenced by Initialize().

◆ cmd_endlocal()

INT cmd_endlocal ( LPTSTR  param)

Definition at line 110 of file setlocal.c.

111{
112 LPTSTR Environ, Name, Value;
113 PSETLOCAL Saved;
114 TCHAR drvEnvVar[] = _T("=?:");
115 TCHAR szCurrent[MAX_PATH];
116
117 if (!_tcscmp(param, _T("/?")))
118 {
119 // FIXME
120 ConOutPuts(_T("ENDLOCAL help not implemented yet!\n"));
121 return 0;
122 }
123
124 /* Pop a SETLOCAL struct off of this batch context's stack */
125 if (!bc || !(Saved = bc->setlocal))
126 return 0;
127 bc->setlocal = Saved->Prev;
128
131
132 /* First, clear out the environment. Since making any changes to the
133 * environment invalidates pointers obtained from GetEnvironmentStrings(),
134 * we must make a copy of it and get the variable names from that. */
135 Environ = DuplicateEnvironment();
136 if (Environ)
137 {
138 for (Name = Environ; *Name; Name += _tcslen(Name) + 1)
139 {
140 if (!(Value = _tcschr(Name + 1, _T('='))))
141 continue;
142 *Value++ = _T('\0');
144 Name = Value;
145 }
146 cmd_free(Environ);
147 }
148
149 /* Now, restore variables from the copy saved by cmd_setlocal() */
150 for (Name = Saved->Environment; *Name; Name += _tcslen(Name) + 1)
151 {
152 if (!(Value = _tcschr(Name + 1, _T('='))))
153 continue;
154 *Value++ = _T('\0');
156 Name = Value;
157 }
158
159 /* Restore the current drive and its current directory from the environment */
160 drvEnvVar[1] = _T('A') + Saved->CurDrive - 1;
161 if (!GetEnvironmentVariable(drvEnvVar, szCurrent, ARRAYSIZE(szCurrent)))
162 {
163 _stprintf(szCurrent, _T("%C:\\"), _T('A') + Saved->CurDrive - 1);
164 }
165 _tchdir(szCurrent); // SetRootPath(NULL, szCurrent);
166
167 cmd_free(Saved->Environment);
168 cmd_free(Saved);
169 return 0;
170}
struct NameRec_ * Name
Definition: cdprocs.h:460
BOOL bDelayedExpansion
Definition: cmd.c:162
#define ConOutPuts(szStr)
Definition: console.h:29
#define _tchdir
Definition: tchar.h:672
#define _stprintf
Definition: utility.h:124
LPTSTR DuplicateEnvironment(VOID)
Definition: setlocal.c:25
struct _SETLOCAL * setlocal
Definition: batch.h:42
struct _SETLOCAL * Prev
Definition: setlocal.c:16
INT CurDrive
Definition: setlocal.c:18
LPTSTR Environment
Definition: setlocal.c:17
BOOL DelayedExpansion
Definition: setlocal.c:20
BOOL EnableExtensions
Definition: setlocal.c:19
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
#define SetEnvironmentVariable
Definition: winbase.h:3843

Referenced by ExitBatch().

◆ cmd_for()

INT cmd_for ( LPTSTR  param)

Definition at line 41 of file for.c.

42{
43 TRACE("cmd_for(\'%s\')\n", debugstr_aw(param));
44
45 if (!_tcsncmp(param, _T("/?"), 2))
46 {
48 return 0;
49 }
50
52 return 1;
53}
VOID ParseErrorEx(IN PCTSTR s)
Definition: parser.c:227
#define STRING_FOR_HELP1
Definition: resource.h:128

◆ cmd_goto()

INT cmd_goto ( LPTSTR  param)

Definition at line 36 of file goto.c.

37{
38 LPTSTR label, tmp;
39 DWORD dwCurrPos;
40 BOOL bRetry;
41
42 TRACE("cmd_goto(\'%s\')\n", debugstr_aw(param));
43
44 /*
45 * Keep the help message handling here too.
46 * This allows us to reproduce the Windows' CMD "bug"
47 * (from a batch script):
48 *
49 * SET label=/?
50 * CALL :%%label%%
51 *
52 * calls GOTO help, due to how CALL :label functionality
53 * is internally implemented.
54 *
55 * See https://stackoverflow.com/q/31987023/13530036
56 * for more details.
57 *
58 * Note that the choice of help parsing forbids
59 * any label containing '/?' in it.
60 */
61 if (_tcsstr(param, _T("/?")))
62 {
64 return 0;
65 }
66
67 /* If not in batch, fail */
68 if (bc == NULL)
69 return 1;
70
71 /* Fail if no label has been provided */
72 if (*param == _T('\0'))
73 {
75 ExitBatch();
76 return 1;
77 }
78
79 /* Strip leading whitespace */
80 while (_istspace(*param))
81 ++param;
82
83 /* Support jumping to the end of the file, only if extensions are enabled */
85 (_tcsnicmp(param, _T(":EOF"), 4) == 0) &&
86 (!param[4] || _istspace(param[4])))
87 {
88 /* Position at the end of the batch file */
89 bc->mempos = bc->memsize;
90
91 /* Do not process any more parts of a compound command */
92 bc->current = NULL;
93 return 0;
94 }
95
96 /* Skip the first colon or plus sign */
97 if (*param == _T(':') || *param == _T('+'))
98 ++param;
99 /* Terminate the label at the first delimiter character */
100 tmp = param;
101 while (!_istcntrl(*tmp) && !_istspace(*tmp) &&
102 !_tcschr(_T(":+"), *tmp) && !_tcschr(STANDARD_SEPS, *tmp) /* &&
103 !_tcschr(_T("&|<>"), *tmp) */)
104 {
105 ++tmp;
106 }
107 *tmp = _T('\0');
108
109 /* If we don't have any label, bail out */
110 if (!*param)
111 goto NotFound;
112
113 /*
114 * Search the next label starting our position, until the end of the file.
115 * If none has been found, restart at the beginning of the file, and continue
116 * until reaching back our old current position.
117 */
118 bRetry = FALSE;
119 dwCurrPos = bc->mempos;
120
121retry:
123 {
124 if (bRetry && (bc->mempos >= dwCurrPos))
125 break;
126
127#if 0
128 /* If this is not a label, continue searching */
129 if (!_tcschr(textline, _T(':')))
130 continue;
131#endif
132
133 label = textline;
134
135 /* A bug in Windows' CMD makes it always ignore the
136 * first character of the line, unless it's a colon. */
137 if (*label != _T(':'))
138 ++label;
139
140 /* Strip any leading whitespace */
141 while (_istspace(*label))
142 ++label;
143
144 /* If this is not a label, continue searching */
145 if (*label != _T(':'))
146 continue;
147
148 /* Skip the first colon or plus sign */
149#if 0
150 if (*label == _T(':') || *label == _T('+'))
151 ++label;
152#endif
153 ++label;
154 /* Strip any whitespace between the colon and the label */
155 while (_istspace(*label))
156 ++label;
157 /* Terminate the label at the first delimiter character */
158 tmp = label;
159 while (!_istcntrl(*tmp) && !_istspace(*tmp) &&
160 !_tcschr(_T(":+"), *tmp) && !_tcschr(STANDARD_SEPS, *tmp) &&
161 !_tcschr(_T("&|<>"), *tmp))
162 {
163 /* Support the escape caret */
164 if (*tmp == _T('^'))
165 {
166 /* Move the buffer back one character */
167 memmove(tmp, tmp + 1, (_tcslen(tmp + 1) + 1) * sizeof(TCHAR));
168 /* We will ignore the new character */
169 }
170
171 ++tmp;
172 }
173 *tmp = _T('\0');
174
175 /* Jump if the labels are identical */
176 if (_tcsicmp(label, param) == 0)
177 {
178 /* Do not process any more parts of a compound command */
179 bc->current = NULL;
180 return 0;
181 }
182 }
183 if (!bRetry && (bc->mempos >= bc->memsize))
184 {
185 bRetry = TRUE;
186 bc->mempos = 0;
187 goto retry;
188 }
189
190NotFound:
192 ExitBatch();
193 return 1;
194}
TCHAR textline[BATCH_BUFFSIZE]
Definition: batch.c:76
VOID ExitBatch(VOID)
Definition: batch.c:222
BOOL BatchGetString(LPTSTR lpBuffer, INT nBufferLength)
Definition: batch.c:527
#define STANDARD_SEPS
Definition: cmd.h:348
#define STRING_GOTO_ERROR2
Definition: resource.h:52
#define STRING_GOTO_ERROR1
Definition: resource.h:51
#define STRING_GOTO_HELP1
Definition: resource.h:135
#define _istcntrl
Definition: tchar.h:739
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
static const WCHAR label[]
Definition: itemdlg.c:1546
DWORD memsize
Definition: batch.h:30
PARSED_COMMAND * current
Definition: batch.h:41
DWORD mempos
Definition: batch.h:31
#define _tcsnicmp
Definition: xmlstorage.h:207

Referenced by Batch(), and CommandExit().

◆ cmd_if()

int cmd_if ( TCHAR )

◆ cmd_mkdir()

INT cmd_mkdir ( LPTSTR  param)

Definition at line 360 of file internal.c.

361{
362 LPTSTR *p;
363 INT argc, i;
364 DWORD dwLastError;
365
366 if (!_tcsncmp (param, _T("/?"), 2))
367 {
369 return 0;
370 }
371
372 p = split (param, &argc, FALSE, FALSE);
373 if (argc == 0)
374 {
376 freep(p);
377 nErrorLevel = 1;
378 return 1;
379 }
380
381 nErrorLevel = 0;
382 for (i = 0; i < argc; i++)
383 {
384 if (!MakeFullPath(p[i]))
385 {
386 dwLastError = GetLastError();
387 switch (dwLastError)
388 {
391 break;
392
396 break;
397
398 default:
400 }
401 nErrorLevel = 1;
402 }
403 }
404
405 freep (p);
406 return nErrorLevel;
407}
static VOID ErrorMessage(_In_ DWORD dwErrorCode, _In_opt_ PCWSTR pszMsg,...)
Definition: attrib.c:33
BOOL MakeFullPath(TCHAR *DirPath)
Definition: internal.c:325
#define STRING_MD_ERROR2
Definition: resource.h:221
#define STRING_MKDIR_HELP
Definition: resource.h:139
#define STRING_MD_ERROR
Definition: resource.h:220
GLfloat GLfloat p
Definition: glext.h:8902
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
#define ERROR_FILE_EXISTS
Definition: winerror.h:165

◆ cmd_mklink()

INT cmd_mklink ( LPTSTR  param)

Definition at line 124 of file mklink.c.

125{
126 HMODULE hKernel32 = GetModuleHandle(_T("KERNEL32"));
127 DWORD Flags = 0;
128 enum { SYMBOLIC, HARD, JUNCTION } LinkType = SYMBOLIC;
129 INT NumFiles = 0;
130 LPTSTR Name[2];
131 INT argc, i;
132 LPTSTR *arg;
133
134 if (!_tcsncmp(param, _T("/?"), 2))
135 {
137 return 0;
138 }
139
140 arg = split(param, &argc, FALSE, FALSE);
141 for (i = 0; i < argc; i++)
142 {
143 if (arg[i][0] == _T('/'))
144 {
145 if (!_tcsicmp(arg[i], _T("/D")))
146 Flags |= 1; /* SYMBOLIC_LINK_FLAG_DIRECTORY */
147 else if (!_tcsicmp(arg[i], _T("/H")))
148 LinkType = HARD;
149 else if (!_tcsicmp(arg[i], _T("/J")))
150 LinkType = JUNCTION;
151 else
152 {
154 freep(arg);
155 return 1;
156 }
157 }
158 else
159 {
160 if (NumFiles == 2)
161 {
163 freep(arg);
164 return 1;
165 }
166 Name[NumFiles++] = arg[i];
167 }
168 }
169 freep(arg);
170
171 if (NumFiles != 2)
172 {
174 return 1;
175 }
176
177 nErrorLevel = 0;
178
179 if (LinkType == SYMBOLIC)
180 {
181 /* CreateSymbolicLink doesn't exist in old versions of Windows,
182 * so load dynamically */
184#ifdef UNICODE
185 = (BOOL (WINAPI *)(LPCTSTR, LPCTSTR, DWORD))GetProcAddress(hKernel32, "CreateSymbolicLinkW");
186#else
187 = (BOOL (WINAPI *)(LPCTSTR, LPCTSTR, DWORD))GetProcAddress(hKernel32, "CreateSymbolicLinkA");
188#endif
190 {
192 return 0;
193 }
194 }
195 else if (LinkType == HARD)
196 {
197 /* CreateHardLink doesn't exist in old versions of Windows,
198 * so load dynamically */
199 BOOL (WINAPI *CreateHardLink)(LPCTSTR, LPCTSTR, LPSECURITY_ATTRIBUTES)
200#ifdef UNICODE
202#else
204#endif
205 if (CreateHardLink && CreateHardLink(Name[0], Name[1], NULL))
206 {
208 return 0;
209 }
210 }
211 else
212 {
213 if (CreateJunction(Name[0], Name[1]))
214 {
216 return 0;
217 }
218 }
219
220 ErrorMessage(GetLastError(), _T("MKLINK"));
221 return 1;
222}
VOID error_too_many_parameters(PCTSTR s)
Definition: error.c:79
VOID error_req_param_missing(VOID)
Definition: error.c:110
VOID error_invalid_switch(TCHAR ch)
Definition: error.c:72
#define STRING_MKLINK_CREATED_JUNCTION
Definition: resource.h:237
#define STRING_MKLINK_CREATED_HARD
Definition: resource.h:236
#define STRING_MKLINK_CREATED_SYMBOLIC
Definition: resource.h:235
#define STRING_MKLINK_HELP
Definition: resource.h:84
struct _SECURITY_ATTRIBUTES * LPSECURITY_ATTRIBUTES
#define GetProcAddress(x, y)
Definition: compat.h:753
static LPWSTR CreateSymbolicLink(IN LPGUID InterfaceGuid, IN LPCWSTR ReferenceString, IN struct DeviceInfo *devInfo)
Definition: interface.c:295
HANDLE hKernel32
Definition: locale.c:13
wchar_t UNICODE
Definition: ms-dtyp.idl:111
#define BOOL
Definition: nt_native.h:43
#define DWORD
Definition: nt_native.h:44
#define GetModuleHandle
Definition: winbase.h:3762
#define WINAPI
Definition: msvc.h:6
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
const CHAR * LPCTSTR
Definition: xmlstorage.h:193

◆ cmd_move()

INT cmd_move ( LPTSTR  param)

Definition at line 87 of file move.c.

88{
89 LPTSTR *arg;
90 INT argc, i, nFiles;
91 LPTSTR pszDest;
92 TCHAR szDestPath[MAX_PATH];
93 TCHAR szFullDestPath[MAX_PATH];
94 TCHAR szSrcDirPath[MAX_PATH];
95 TCHAR szSrcPath[MAX_PATH];
96 TCHAR szFullSrcPath[MAX_PATH];
97 DWORD dwFlags = 0;
98 INT nOverwrite = 0;
99 WIN32_FIND_DATA findBuffer;
101
102 /* used only when source and destination directories are on different volume */
103 HANDLE hDestFile = NULL;
104 WIN32_FIND_DATA findDestBuffer;
105 TCHAR szMoveDest[MAX_PATH];
106 TCHAR szMoveSrc[MAX_PATH];
107 LPTSTR pszDestDirPointer;
108 LPTSTR pszSrcDirPointer;
109 INT nDirLevel = 0;
110
111 LPTSTR pszFile;
112 BOOL OnlyOneFile;
113 BOOL FoundFile;
114 BOOL MoveStatus;
115 DWORD dwMoveFlags = 0;
116 DWORD dwMoveStatusFlags = 0;
117
118 if (!_tcsncmp (param, _T("/?"), 2))
119 {
120#if 0
121 ConOutPuts (_T("Moves files and renames files and directories.\n\n"
122 "To move one or more files:\n"
123 "MOVE [/N][/Y|/-Y][drive:][path]filename1[,...] destination\n"
124 "\n"
125 "To rename a directory:\n"
126 "MOVE [/N][/Y|/-Y][drive:][path]dirname1 dirname2\n"
127 "\n"
128 " [drive:][path]filename1 Specifies the location and name of the file\n"
129 " or files you want to move.\n"
130 " /N Nothing. Don everthing but move files or directories.\n"
131 " /Y\n"
132 " /-Y\n"
133 "..."));
134#else
136#endif
137 return 0;
138 }
139
140 nErrorLevel = 0;
142
143 /* read options */
144 for (i = 0; i < argc; i++)
145 {
146 if (!_tcsicmp(arg[i], _T("/N")))
148 else if (!_tcsicmp(arg[i], _T("/Y")))
150 else if (!_tcsicmp(arg[i], _T("/-Y")))
152 else
153 break;
154 }
155 nFiles = argc - i;
156
157 if (nFiles < 1)
158 {
159 /* there must be at least one pathspec */
161 nErrorLevel = 1;
162 goto Quit;
163 }
164
165 if (nFiles > 2)
166 {
167 /* there are more than two pathspecs */
169 nErrorLevel = 1;
170 goto Quit;
171 }
172
173 /* If no destination is given, default to current directory */
174 pszDest = (nFiles == 1) ? _T(".") : arg[i + 1];
175
176 /* check for wildcards in source and destination */
177 if (_tcschr(pszDest, _T('*')) != NULL || _tcschr(pszDest, _T('?')) != NULL)
178 {
179 /* '*'/'?' in dest, this doesnt happen. give folder name instead*/
181 nErrorLevel = 1;
182 goto Quit;
183 }
184 if (_tcschr(arg[i], _T('*')) != NULL || _tcschr(arg[i], _T('?')) != NULL)
185 {
186 dwMoveStatusFlags |= MOVE_SOURCE_HAS_WILD;
187 }
188
189 /* get destination */
190 GetFullPathName (pszDest, MAX_PATH, szDestPath, NULL);
191 TRACE ("Destination: %s\n", debugstr_aw(szDestPath));
192
193 /* get source folder */
194 GetFullPathName(arg[i], MAX_PATH, szSrcDirPath, &pszFile);
195 if (pszFile != NULL)
196 *pszFile = _T('\0');
197 TRACE ("Source Folder: %s\n", debugstr_aw(szSrcDirPath));
198
199 hFile = FindFirstFile (arg[i], &findBuffer);
201 {
203 nErrorLevel = 1;
204 goto Quit;
205 }
206
207 /* check for special cases "." and ".." and if found skip them */
208 FoundFile = TRUE;
209 while(FoundFile &&
210 (_tcscmp(findBuffer.cFileName,_T(".")) == 0 ||
211 _tcscmp(findBuffer.cFileName,_T("..")) == 0))
212 FoundFile = FindNextFile (hFile, &findBuffer);
213
214 if (!FoundFile)
215 {
216 /* what? we don't have anything to move? */
219 nErrorLevel = 1;
220 goto Quit;
221 }
222
223 OnlyOneFile = TRUE;
224 /* check if there can be found files as files have first priority */
225 if (findBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
226 dwMoveStatusFlags |= MOVE_SOURCE_IS_DIR;
227 else
228 dwMoveStatusFlags |= MOVE_SOURCE_IS_FILE;
229 while(OnlyOneFile && FindNextFile(hFile,&findBuffer))
230 {
231 if (!(findBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
232 {
233 ConOutPrintf(_T(""));
234 if (dwMoveStatusFlags & MOVE_SOURCE_IS_FILE) OnlyOneFile = FALSE;
235 else
236 { /* this has been done this way so that we don't disturb other settings if they have been set before this */
237 dwMoveStatusFlags |= MOVE_SOURCE_IS_FILE;
238 dwMoveStatusFlags &= ~MOVE_SOURCE_IS_DIR;
239 }
240 }
241 }
243
244 TRACE ("Do we have only one file: %s\n", OnlyOneFile ? "TRUE" : "FALSE");
245
246 /* we have to start again to be sure we don't miss any files or folders*/
247 hFile = FindFirstFile (arg[i], &findBuffer);
249 {
251 nErrorLevel = 1;
252 goto Quit;
253 }
254
255 /* check for special cases "." and ".." and if found skip them */
256 FoundFile = TRUE;
257 while(FoundFile &&
258 (_tcscmp(findBuffer.cFileName,_T(".")) == 0 ||
259 _tcscmp(findBuffer.cFileName,_T("..")) == 0))
260 FoundFile = FindNextFile (hFile, &findBuffer);
261
262 if (!FoundFile)
263 {
264 /* huh? somebody removed files and/or folders which were there */
267 nErrorLevel = 1;
268 goto Quit;
269 }
270
271 /* check if source and destination paths are on different volumes */
272 if (szSrcDirPath[0] != szDestPath[0])
273 dwMoveStatusFlags |= MOVE_PATHS_ON_DIF_VOL;
274
275 /* move it */
276 do
277 {
278 TRACE ("Found file/directory: %s\n", debugstr_aw(findBuffer.cFileName));
279 nOverwrite = 1;
280 dwMoveFlags = 0;
281 dwMoveStatusFlags &= ~MOVE_DEST_IS_FILE &
282 ~MOVE_DEST_IS_DIR &
283 ~MOVE_SRC_CURRENT_IS_DIR &
284 ~MOVE_DEST_EXISTS;
285 _tcscpy(szFullSrcPath,szSrcDirPath);
286 if (szFullSrcPath[_tcslen(szFullSrcPath) - 1] != _T('\\'))
287 _tcscat (szFullSrcPath, _T("\\"));
288 _tcscat(szFullSrcPath,findBuffer.cFileName);
289 _tcscpy(szSrcPath, szFullSrcPath);
290
291 if (IsExistingDirectory(szSrcPath))
292 {
293 /* source is directory */
294 if (dwMoveStatusFlags & MOVE_SOURCE_IS_FILE)
295 {
296 dwMoveStatusFlags |= MOVE_SRC_CURRENT_IS_DIR; /* source is file but at the current round we found a directory */
297 continue;
298 }
299 TRACE ("Source is dir: %s\n", debugstr_aw(szSrcPath));
301 }
302
303 /* if source is file we don't need to do anything special */
304 if (IsExistingDirectory(szDestPath))
305 {
306 /* destination is existing directory */
307 TRACE ("Destination is directory: %s\n", debugstr_aw(szDestPath));
308
309 dwMoveStatusFlags |= MOVE_DEST_IS_DIR;
310
311 /*build the dest string(accounts for *)*/
312 _tcscpy (szFullDestPath, szDestPath);
313 /*check to see if there is an ending slash, if not add one*/
314 if (szFullDestPath[_tcslen(szFullDestPath) - 1] != _T('\\'))
315 _tcscat (szFullDestPath, _T("\\"));
316 _tcscat (szFullDestPath, findBuffer.cFileName);
317
318 if (IsExistingFile(szFullDestPath) || IsExistingDirectory(szFullDestPath))
319 dwMoveStatusFlags |= MOVE_DEST_EXISTS;
320
322 }
323 if (IsExistingFile(szDestPath))
324 {
325 /* destination is a file */
326 TRACE ("Destination is file: %s\n", debugstr_aw(szDestPath));
327
328 dwMoveStatusFlags |= MOVE_DEST_IS_FILE | MOVE_DEST_EXISTS;
329 _tcscpy (szFullDestPath, szDestPath);
330
332 }
333
334 TRACE ("Move Status Flags: 0x%X\n",dwMoveStatusFlags);
335
336 if (dwMoveStatusFlags & MOVE_SOURCE_IS_DIR &&
337 dwMoveStatusFlags & MOVE_DEST_IS_DIR &&
338 dwMoveStatusFlags & MOVE_SOURCE_HAS_WILD)
339 {
340 /* We are not allowed to have existing source and destination dir when there is wildcard in source */
343 nErrorLevel = 1;
344 goto Quit;
345 }
346 if (!(dwMoveStatusFlags & (MOVE_DEST_IS_FILE | MOVE_DEST_IS_DIR)))
347 {
348 /* destination doesn't exist */
349 _tcscpy (szFullDestPath, szDestPath);
350 if (dwMoveStatusFlags & MOVE_SOURCE_IS_FILE) dwMoveStatusFlags |= MOVE_DEST_IS_FILE;
351 if (dwMoveStatusFlags & MOVE_SOURCE_IS_DIR) dwMoveStatusFlags |= MOVE_DEST_IS_DIR;
352
354 }
355
356 if (dwMoveStatusFlags & MOVE_SOURCE_IS_FILE &&
357 dwMoveStatusFlags & MOVE_DEST_IS_FILE &&
358 !OnlyOneFile)
359 {
360 /*source has many files but there is only one destination file*/
363 nErrorLevel = 1;
364 goto Quit;
365 }
366
367 /*checks to make sure user wanted/wants the override*/
368 if ((dwFlags & MOVE_OVER_NO) &&
369 (dwMoveStatusFlags & MOVE_DEST_EXISTS))
370 continue;
371 if (!(dwFlags & MOVE_OVER_YES) &&
372 (dwMoveStatusFlags & MOVE_DEST_EXISTS))
373 nOverwrite = MoveOverwrite (szFullDestPath);
374 if (nOverwrite == PROMPT_NO || nOverwrite == PROMPT_BREAK)
375 continue;
376 if (nOverwrite == PROMPT_ALL)
378
379 ConOutPrintf (_T("%s => %s "), szSrcPath, szFullDestPath);
380
381 /* are we really supposed to do something */
382 if (dwFlags & MOVE_NOTHING)
383 continue;
384
385 /*move the file*/
386 if (!(dwMoveStatusFlags & MOVE_SOURCE_IS_DIR &&
387 dwMoveStatusFlags & MOVE_PATHS_ON_DIF_VOL))
388 /* we aren't moving source folder to different drive */
389 MoveStatus = MoveFileEx (szSrcPath, szFullDestPath, dwMoveFlags);
390 else
391 { /* we are moving source folder to different drive */
392 _tcscpy(szMoveDest, szFullDestPath);
393 _tcscpy(szMoveSrc, szSrcPath);
394 DeleteFile(szMoveDest);
395 MoveStatus = CreateDirectory(szMoveDest, NULL); /* we use default security settings */
396 if (MoveStatus)
397 {
398 _tcscat(szMoveDest,_T("\\"));
399 _tcscat(szMoveSrc,_T("\\"));
400 nDirLevel = 0;
401 pszDestDirPointer = szMoveDest + _tcslen(szMoveDest);
402 pszSrcDirPointer = szMoveSrc + _tcslen(szMoveSrc);
403 _tcscpy(pszSrcDirPointer,_T("*.*"));
404 hDestFile = FindFirstFile(szMoveSrc, &findDestBuffer);
405 if (hDestFile == INVALID_HANDLE_VALUE)
406 MoveStatus = FALSE;
407 else
408 {
409 BOOL FirstTime = TRUE;
410 FoundFile = TRUE;
411 MoveStatus = FALSE;
412 while(FoundFile)
413 {
414 if (FirstTime)
415 FirstTime = FALSE;
416 else
417 FoundFile = FindNextFile (hDestFile, &findDestBuffer);
418
419 if (!FoundFile)
420 {
421 /* Nothing to do in this folder so we stop working on it */
422 FindClose(hDestFile);
423 (pszSrcDirPointer)--;
424 (pszDestDirPointer)--;
425 _tcscpy(pszSrcDirPointer,_T(""));
426 _tcscpy(pszDestDirPointer,_T(""));
427 if (nDirLevel > 0)
428 {
430 INT_PTR nDiff;
431
432 FoundFile = TRUE; /* we need to continue our seek for files */
433 nDirLevel--;
434 RemoveDirectory(szMoveSrc);
435 GetDirectory(szMoveSrc,szTempPath,0);
436 nDiff = _tcslen(szMoveSrc) - _tcslen(szTempPath);
437 pszSrcDirPointer = pszSrcDirPointer - nDiff;
438 _tcscpy(pszSrcDirPointer,_T(""));
439 GetDirectory(szMoveDest,szTempPath,0);
440 nDiff = _tcslen(szMoveDest) - _tcslen(szTempPath);
441 pszDestDirPointer = pszDestDirPointer - nDiff;
442 _tcscpy(pszDestDirPointer,_T(""));
443 if (szMoveSrc[_tcslen(szMoveSrc) - 1] != _T('\\'))
444 _tcscat (szMoveSrc, _T("\\"));
445 if (szMoveDest[_tcslen(szMoveDest) - 1] != _T('\\'))
446 _tcscat (szMoveDest, _T("\\"));
447 pszDestDirPointer = szMoveDest + _tcslen(szMoveDest);
448 pszSrcDirPointer = szMoveSrc + _tcslen(szMoveSrc);
449 _tcscpy(pszSrcDirPointer,_T("*.*"));
450 hDestFile = FindFirstFile(szMoveSrc, &findDestBuffer);
451 if (hDestFile == INVALID_HANDLE_VALUE)
452 continue;
453 FirstTime = TRUE;
454 }
455 else
456 {
457 MoveStatus = TRUE; /* we moved everything so lets tell user about it */
458 RemoveDirectory(szMoveSrc);
459 }
460 continue;
461 }
462
463 /* if we find "." or ".." we'll skip them */
464 if (_tcscmp(findDestBuffer.cFileName,_T(".")) == 0 ||
465 _tcscmp(findDestBuffer.cFileName,_T("..")) == 0)
466 continue;
467
468 _tcscpy(pszSrcDirPointer, findDestBuffer.cFileName);
469 _tcscpy(pszDestDirPointer, findDestBuffer.cFileName);
470 if (IsExistingFile(szMoveSrc))
471 {
472 FoundFile = CopyFile(szMoveSrc, szMoveDest, FALSE);
473 if (!FoundFile) continue;
474 DeleteFile(szMoveSrc);
475 }
476 else
477 {
478 FindClose(hDestFile);
479 CreateDirectory(szMoveDest, NULL);
480 _tcscat(szMoveDest,_T("\\"));
481 _tcscat(szMoveSrc,_T("\\"));
482 nDirLevel++;
483 pszDestDirPointer = szMoveDest + _tcslen(szMoveDest);
484 pszSrcDirPointer = szMoveSrc + _tcslen(szMoveSrc);
485 _tcscpy(pszSrcDirPointer,_T("*.*"));
486 hDestFile = FindFirstFile(szMoveSrc, &findDestBuffer);
487 if (hDestFile == INVALID_HANDLE_VALUE)
488 {
489 FoundFile = FALSE;
490 continue;
491 }
492 FirstTime = TRUE;
493 }
494 }
495 }
496 }
497 }
498
499 if (MoveStatus)
500 {
502 }
503 else
504 {
506 nErrorLevel = 1;
507 }
508 }
509 while ((!OnlyOneFile || dwMoveStatusFlags & MOVE_SRC_CURRENT_IS_DIR ) &&
510 !(dwMoveStatusFlags & MOVE_SOURCE_IS_DIR) &&
511 FindNextFile (hFile, &findBuffer));
513
514 if(hDestFile && hDestFile != INVALID_HANDLE_VALUE)
515 FindClose(hDestFile);
516
517Quit:
518 freep(arg);
519 return nErrorLevel;
520}
VOID error_file_not_found(VOID)
Definition: error.c:93
LPTSTR * splitspace(LPTSTR, LPINT)
Definition: misc.c:381
VOID error_syntax(PCTSTR s)
Definition: error.c:152
VOID error_invalid_parameter_format(PCTSTR s)
Definition: error.c:145
@ MOVE_SOURCE_HAS_WILD
Definition: move.c:50
@ MOVE_PATHS_ON_DIF_VOL
Definition: move.c:53
@ MOVE_DEST_EXISTS
Definition: move.c:52
@ MOVE_DEST_IS_FILE
Definition: move.c:49
@ MOVE_SOURCE_IS_FILE
Definition: move.c:47
@ MOVE_SRC_CURRENT_IS_DIR
Definition: move.c:51
@ MOVE_DEST_IS_DIR
Definition: move.c:48
@ MOVE_SOURCE_IS_DIR
Definition: move.c:46
void GetDirectory(LPTSTR wholepath, LPTSTR directory, BOOL CheckExisting)
Definition: move.c:65
static INT MoveOverwrite(LPTSTR fn)
Definition: move.c:56
@ MOVE_OVER_YES
Definition: move.c:39
@ MOVE_OVER_NO
Definition: move.c:40
@ MOVE_NOTHING
Definition: move.c:38
#define STRING_MOVE_HELP2
Definition: resource.h:147
#define STRING_MOVE_ERROR2
Definition: resource.h:54
#define STRING_MOVE_ERROR1
Definition: resource.h:53
#define MOVEFILE_WRITE_THROUGH
Definition: filesup.h:30
#define MOVEFILE_REPLACE_EXISTING
Definition: filesup.h:28
#define MOVEFILE_COPY_ALLOWED
Definition: filesup.h:29
static char szTempPath[MAX_PATH]
Definition: data.c:16
int32_t INT_PTR
Definition: typedefs.h:64
#define RemoveDirectory
Definition: winbase.h:3830
#define CopyFile
Definition: winbase.h:3676
#define CreateDirectory
Definition: winbase.h:3681
#define DeleteFile
Definition: winbase.h:3699
#define MoveFileEx
Definition: winbase.h:3813

◆ cmd_path()

INT cmd_path ( LPTSTR  param)

Definition at line 36 of file path.c.

37{
38 INT retval = 0;
39
40 if (!_tcsncmp(param, _T("/?"), 2))
41 {
43 return 0;
44 }
45
46 /* If param is empty, display the PATH environment variable */
47 if (!param || !*param)
48 {
49 DWORD dwBuffer;
50 LPTSTR pszBuffer;
51
52 pszBuffer = (LPTSTR)cmd_alloc(ENV_BUFFER_SIZE * sizeof(TCHAR));
53 if (!pszBuffer)
54 {
55 WARN("Cannot allocate memory for pszBuffer!\n");
57 retval = 1;
58 goto Quit;
59 }
60
61 dwBuffer = GetEnvironmentVariable(_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
62 if (dwBuffer == 0)
63 {
64 cmd_free(pszBuffer);
66 retval = 0;
67 goto Quit;
68 }
69 else if (dwBuffer > ENV_BUFFER_SIZE)
70 {
71 LPTSTR pszOldBuffer = pszBuffer;
72 pszBuffer = (LPTSTR)cmd_realloc(pszBuffer, dwBuffer * sizeof (TCHAR));
73 if (!pszBuffer)
74 {
75 WARN("Cannot reallocate memory for pszBuffer!\n");
77 cmd_free(pszOldBuffer);
78 retval = 1;
79 goto Quit;
80 }
81 GetEnvironmentVariable(_T("PATH"), pszBuffer, dwBuffer);
82 }
83
84 ConOutPrintf(_T("PATH=%s\n"), pszBuffer);
85 cmd_free(pszBuffer);
86
87 retval = 0;
88 goto Quit;
89 }
90
91 /* Skip leading '=' */
92 if (*param == _T('='))
93 param++;
94
95 /* Set PATH environment variable */
96 if (!SetEnvironmentVariable(_T("PATH"), param))
97 {
98 retval = 1;
99 }
100
101Quit:
102 if (BatType != CMD_TYPE)
103 {
104 if (retval != 0)
105 nErrorLevel = retval;
106 }
107 else
108 {
109 nErrorLevel = retval;
110 }
111
112 return retval;
113}
BATCH_TYPE BatType
Definition: batch.c:66
#define ENV_BUFFER_SIZE
Definition: path.c:33
#define STRING_SET_ENV_ERROR
Definition: resource.h:55
#define STRING_PATH_HELP1
Definition: resource.h:151
@ CMD_TYPE
Definition: batch.h:19

Referenced by RunShell().

◆ cmd_pause()

int cmd_pause ( TCHAR )

◆ cmd_prompt()

INT cmd_prompt ( LPTSTR  param)

Definition at line 244 of file prompt.c.

245{
246 INT retval = 0;
247
248 if (!_tcsncmp(param, _T("/?"), 2))
249 {
251#ifdef FEATURE_DIRECTORY_STACK
253#endif
255 return 0;
256 }
257
258 /*
259 * Set the PROMPT environment variable. If 'param' is NULL or is
260 * an empty string (the user entered "prompt" only), then remove
261 * the environment variable and therefore use the default prompt.
262 * Otherwise, use the new prompt.
263 */
264 if (!SetEnvironmentVariable(_T("PROMPT"),
265 (param && param[0] != _T('\0') ? param : NULL)))
266 {
267 retval = 1;
268 }
269
270 if (BatType != CMD_TYPE)
271 {
272 if (retval != 0)
273 nErrorLevel = retval;
274 }
275 else
276 {
277 nErrorLevel = retval;
278 }
279
280 return retval;
281}
#define STRING_PROMPT_HELP2
Definition: resource.h:156
#define STRING_PROMPT_HELP1
Definition: resource.h:155
#define STRING_PROMPT_HELP3
Definition: resource.h:157

◆ cmd_rename()

INT cmd_rename ( LPTSTR  param)

Definition at line 53 of file ren.c.

54{
55 LPTSTR *arg = NULL;
56 INT args = 0;
57 INT nSlash = 0;
58 INT nEvalArgs = 0; /* number of evaluated arguments */
59 DWORD dwFlags = 0;
60 DWORD dwFiles = 0; /* number of renamed files */
61 INT i;
62
63 LPTSTR srcPattern = NULL; /* Source Argument*/
64 TCHAR srcPath[MAX_PATH]; /*Source Path Directories*/
65 LPTSTR srcFILE = NULL; /*Contains the files name(s)*/
66 TCHAR srcFinal[MAX_PATH];
67
68 LPTSTR dstPattern = NULL; /*Destiny Argument*/
69 TCHAR dstPath[MAX_PATH]; /*Source Path Directories*/
70 LPTSTR dstFILE = NULL; /*Contains the files name(s)*/
71
72 TCHAR dstLast[MAX_PATH]; /*It saves the File name after unmasked with wildcards*/
73 TCHAR dstFinal[MAX_PATH]; /*It saves the Final destiny Path*/
74
75 BOOL bDstWildcard = FALSE;
76 BOOL bPath = FALSE;
77
78 LPTSTR p,q,r;
79
82 /*If the PARAM=/? then show the help*/
83 if (!_tcsncmp(param, _T("/?"), 2))
84 {
86 return 0;
87 }
88
89 nErrorLevel = 0;
90
91 /* Split the argument list.Args will be saved in arg vector*/
93
94 if (args < 2)
95 {
96 if (!(dwFlags & REN_ERROR))
98 freep(arg);
99 return 1;
100 }
101
102 /* Read options */
103 for (i = 0; i < args; i++)
104 {
105 /* Lets check if we have a special option chosen and set the flag(s)*/
106 if (*arg[i] == _T('/'))
107 {
108 if (_tcslen(arg[i]) >= 2)
109 {
110 switch (_totupper(arg[i][1]))
111 {
112 case _T('E'):
114 break;
115
116 case _T('N'):
118 break;
119
120 case _T('P'):
122 break;
123
124 case _T('Q'):
126 break;
127
128 case _T('S'):
130 break;
131
132 case _T('T'):
134 break;
135 }
136 }
137 nEvalArgs++;//Save the number of the options.
138 }
139 }
140
141 /* keep quiet within batch files */
142 if (bc != NULL)
144
145 /* there are only options on the command line --> error!!! */
146 if (args < nEvalArgs + 2)
147 {
148 if (!(dwFlags & REN_ERROR))
150 freep(arg);
151 return 1;
152 }
153
154 /* Get destination pattern and source pattern*/
155 for (i = 0; i < args; i++)
156 {
157 if (*arg[i] == _T('/'))//We have find an Option.Jump it.
158 continue;
159 dstPattern = arg[i]; //we save the Last argument as dstPattern
160 srcPattern = arg[i-1];
161 }
162
163 if (_tcschr(srcPattern, _T('\\'))) //Checking if the Source (srcPattern) is a Path to the file
164 {
165 bPath= TRUE;
166
167 //Splitting srcPath and srcFile.
168
169 srcFILE = _tcschr(srcPattern, _T('\\'));
170 nSlash++;
171 while(_tcschr(srcFILE, _T('\\')))
172 {
173 srcFILE++;
174 if (*srcFILE==_T('\\')) nSlash++ ;
175 if (!_tcschr(srcFILE, _T('\\'))) break;
176 }
177 _tcsncpy(srcPath,srcPattern,_tcslen(srcPattern)-_tcslen(srcFILE));
178
179 if (_tcschr(dstPattern, _T('\\'))) //Checking if the Destiny (dstPattern)is also a Path.And splitting dstPattern in dstPath and srcPath.
180 {
181 dstFILE = _tcschr(dstPattern, _T('\\'));
182 nSlash=0;
183 while(_tcschr(dstFILE, _T('\\')))
184 {
185 dstFILE++;
186 if (*dstFILE==_T('\\')) nSlash++ ;
187 if (!_tcschr(dstFILE, _T('\\'))) break;
188 }
189 _tcsncpy(dstPath,dstPattern,_tcslen(dstPattern)-_tcslen(dstFILE));
190
191 if ((_tcslen(dstPath)!=_tcslen(srcPath))||(_tcsncmp(srcPath,dstPath,_tcslen(srcPath))!=0)) //If it has a Path,then MUST be equal than srcPath
192 {
193 error_syntax(dstPath);
194 freep(arg);
195 return 1;
196 }
197 }
198 else
199 { //If Destiny hasnt a Path,then (MSDN says) srcPath is its Path.
200 _tcscpy(dstPath,srcPath);
201 dstFILE=dstPattern;
202 }
203 }
204
205 if (!_tcschr(srcPattern, _T('\\'))) //If srcPattern isn't a Path but a name:
206 {
207 srcFILE=srcPattern;
208 if (_tcschr(dstPattern, _T('\\')))
209 {
210 error_syntax(dstPattern);
211 freep(arg);
212 return 1;
213 }
214 else
215 {
216 dstFILE=dstPattern;
217 }
218 }
219
220 //Checking Wildcards.
221 if (_tcschr(dstFILE, _T('*')) || _tcschr(dstFILE, _T('?')))
222 bDstWildcard = TRUE;
223
224 TRACE("\n\nSourcePattern: %s SourcePath: %s SourceFile: %s", debugstr_aw(srcPattern),debugstr_aw(srcPath),debugstr_aw(srcFILE));
225 TRACE("\n\nDestinationPattern: %s Destination Path:%s Destination File: %s\n", debugstr_aw(dstPattern),debugstr_aw(dstPath),debugstr_aw(dstFILE));
226
227 hFile = FindFirstFile(srcPattern, &f);
228
230 {
232 }
233 do
234 {
235 /* ignore "." and ".." */
236 if (!_tcscmp (f.cFileName, _T(".")) || !_tcscmp (f.cFileName, _T("..")))
237 continue;
238
239 /* do not rename hidden or system files */
240 if (f.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM))
241 continue;
242
243 /* do not rename directories when the destination pattern contains
244 * wildcards, unless option /S is used */
245 if ((f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
246 bDstWildcard && !(dwFlags & REN_SUBDIR))
247 {
248 continue;
249 }
250
251 TRACE("Found source name: %s\n", debugstr_aw(f.cFileName));
252 /* So here we have splitted the dstFILE and we have find a f.cFileName(thanks to srcPattern)
253 * Now we have to use the mask (dstFILE) (which can have Wildcards) with f.cFileName to find destination file name(dstLast) */
254 p = f.cFileName;
255 q = dstFILE;
256 r = dstLast;
257 while(*q != 0)
258 {
259 if (*q == '*')
260 {
261 q++;
262 while (*p != 0 && *p != *q)
263 {
264 *r = *p;
265 p++;
266 r++;
267 }
268 }
269 else if (*q == '?')
270 {
271 q++;
272 if (*p != 0)
273 {
274 *r = *p;
275 p++;
276 r++;
277 }
278 }
279 else
280 {
281 *r = *q;
282 if (*p != 0) p++;
283 q++;
284 r++;
285 }
286 }
287 *r = 0;
288 //Well we have splitted the Paths,so now we have to paste them again(if needed),thanks bPath.
289 if (bPath != FALSE)
290 {
291 _tcscpy(srcFinal,srcPath);
292 _tcscat(srcFinal,f.cFileName);
293 _tcscpy(dstFinal,dstPath);
294 _tcscat(dstFinal,dstLast);
295 }
296 else
297 {
298 _tcscpy(srcFinal,f.cFileName);
299 _tcscpy(dstFinal,dstLast);
300 }
301
302 TRACE("DestinationPath: %s\n", debugstr_aw(dstFinal));
303
304 if (!(dwFlags & REN_QUIET) && !(dwFlags & REN_TOTAL))
305 ConOutPrintf(_T("%s -> %s\n"),srcFinal , dstFinal);
306
307 /* Rename the file */
308 if (!(dwFlags & REN_NOTHING))
309 {
310 if (MoveFile(srcFinal, dstFinal))
311 {
312 dwFiles++;
313 }
314 else
315 {
316 if (!(dwFlags & REN_ERROR))
318 }
319 }
320 }
321 while (FindNextFile(hFile, &f));
322
323 //Closing and Printing errors.
325
326 if (!(dwFlags & REN_QUIET))
327 {
328 if (dwFiles == 1)
330 else
332 }
333
334 freep(arg);
335 return 0;
336}
#define STRING_REN_HELP3
Definition: resource.h:163
#define STRING_REN_ERROR
Definition: resource.h:56
#define STRING_REN_HELP2
Definition: resource.h:162
#define STRING_REN_HELP1
Definition: resource.h:161
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint srcPath
Definition: glext.h:11718
GLfloat f
Definition: glext.h:7540
#define _tcsncpy
Definition: tchar.h:1410
#define f
Definition: ke_i.h:83
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
@ REN_NOTHING
Definition: ren.c:42
@ REN_PROMPT
Definition: ren.c:43
@ REN_SUBDIR
Definition: ren.c:45
@ REN_QUIET
Definition: ren.c:44
@ REN_TOTAL
Definition: ren.c:46
@ REN_ERROR
Definition: ren.c:41
#define args
Definition: format.c:66
Definition: match.c:390
#define MoveFile
Definition: winbase.h:3812

◆ cmd_replace()

INT cmd_replace ( LPTSTR  param)

Definition at line 392 of file replace.c.

393{
394 LPTSTR *arg;
395 INT argc, i,filesReplaced = 0, nFiles, srcIndex = -1, destIndex = -1;
396 DWORD dwFlags = 0;
397 TCHAR szDestPath[MAX_PATH], szSrcPath[MAX_PATH], tmpSrcPath[MAX_PATH];
398 BOOL doMore = TRUE;
399
400 /* Help wanted? */
401 if (!_tcsncmp (param, _T("/?"), 2))
402 {
404 return 0;
405 }
406
407 /* Divide the argument in to an array of c-strings */
408 arg = split (param, &argc, FALSE, FALSE);
409 nFiles = argc;
410
411 /* Read options */
412 for (i = 0; i < argc; i++)
413 {
414 if (arg[i][0] == _T('/'))
415 {
416 if (_tcslen(arg[i]) == 2)
417 {
418 switch (_totupper(arg[i][1]))
419 {
420 case _T('A'):
422 break;
423 case _T('P'):
425 break;
426 case _T('R'):
428 break;
429 case _T('S'):
431 break;
432 case _T('W'):
434 break;
435 case _T('U'):
437 break;
438 default:
440 freep(arg);
441 return 0;
442 }
443 }
444 else
445 {
447 freep(arg);
448 return 0;
449 }
450 nFiles--;
451 }
452 else
453 {
454 if (srcIndex == -1)
455 {
456 srcIndex = i;
457 }
458 else if (destIndex == -1)
459 {
460 destIndex = i;
461 }
462 else
463 {
465 freep(arg);
466 return 0;
467 }
468 }
469 }
470
471 /* See so that at least source is there */
472 if (nFiles < 1)
473 {
476 freep(arg);
477 return 1;
478 }
479 /* Check so that not both update and add switch is added and subdir */
481 {
484 freep(arg);
485 return 1;
486 }
487
488 /* If we have a destination get the full path */
489 if (destIndex != -1)
490 {
491 if (_tcslen(arg[destIndex]) == 2 && arg[destIndex][1] == ':')
492 GetRootPath(arg[destIndex],szDestPath,MAX_PATH);
493 else
494 {
495 /* Check for wildcards in destination directory */
496 if (_tcschr (arg[destIndex], _T('*')) != NULL ||
497 _tcschr (arg[destIndex], _T('?')) != NULL)
498 {
501 freep(arg);
502 return 1;
503 }
504 getPath(szDestPath, arg[destIndex]);
505 /* Make sure that destination exists */
506 if (!IsExistingDirectory(szDestPath))
507 {
510 freep(arg);
511 return 1;
512 }
513 }
514 }
515 else
516 {
517 /* Dest is current dir */
518 GetCurrentDirectory(MAX_PATH,szDestPath);
519 }
520
521 /* Get the full source path */
522 if (!(_tcslen(arg[srcIndex]) == 2 && arg[srcIndex][1] == ':'))
523 getPath(szSrcPath, arg[srcIndex]);
524 else
525 _tcscpy(szSrcPath,arg[srcIndex]);
526
527 /* Source does not have wildcards */
528 if (_tcschr (arg[srcIndex], _T('*')) == NULL &&
529 _tcschr (arg[srcIndex], _T('?')) == NULL)
530 {
531 /* Check so that source is not a directory, because that is not allowed */
532 if (IsExistingDirectory(szSrcPath))
533 {
536 freep(arg);
537 return 1;
538 }
539 /* Check if the file exists */
540 if (!IsExistingFile(szSrcPath))
541 {
543 freep(arg);
544 return 1;
545 }
546 }
547 /* /w switch is set so wait for any key to be pressed */
548 if (dwFlags & REPLACE_DISK)
549 {
550 msg_pause();
551 cgetchar();
552 }
553
554 /* Add an extra \ to the destination path if needed */
555 if (szDestPath[_tcslen(szDestPath) - 1] != _T('\\'))
556 _tcscat(szDestPath, _T("\\"));
557
558 /* Save source path */
559 _tcscpy(tmpSrcPath,szSrcPath);
560 /* Replace in dest dir */
561 filesReplaced += recReplace(dwFlags, tmpSrcPath, szDestPath, &doMore);
562 /* If subdir switch is set replace in the subdirs to */
563 if (dwFlags & REPLACE_SUBDIR && doMore)
564 {
565 filesReplaced += recFindSubDirs(dwFlags, szSrcPath, szDestPath, &doMore);
566 }
567
568 /* If source == dest write no more */
569 if (filesReplaced != -1)
570 {
571 /* No files replaced */
572 if (filesReplaced==0)
573 {
574 /* Add switch dependent output */
575 if (dwFlags & REPLACE_ADD)
577 else
579 }
580 /* Some files replaced */
581 else
582 {
583 /* Add switch dependent output */
584 if (dwFlags & REPLACE_ADD)
586 else
588 }
589 }
590 /* Return memory */
591 freep(arg);
592 return 1;
593}
TCHAR cgetchar(VOID)
Definition: misc.c:41
VOID msg_pause(VOID)
Definition: error.c:167
#define STRING_REPLACE_HELP1
Definition: resource.h:223
#define STRING_REPLACE_HELP7
Definition: resource.h:229
#define STRING_REPLACE_HELP3
Definition: resource.h:225
#define STRING_REPLACE_HELP4
Definition: resource.h:226
#define STRING_REPLACE_HELP2
Definition: resource.h:224
#define STRING_REPLACE_ERROR4
Definition: resource.h:63
#define STRING_REPLACE_ERROR6
Definition: resource.h:65
#define STRING_REPLACE_ERROR2
Definition: resource.h:61
#define STRING_REPLACE_HELP8
Definition: resource.h:230
void invalid_switch(LPTSTR is)
Definition: replace.c:30
INT recReplace(DWORD dwFlags, TCHAR szSrcPath[MAX_PATH], TCHAR szDestPath[MAX_PATH], BOOL *doMore)
Definition: replace.c:215
void getPath(TCHAR *out, LPTSTR in)
Definition: replace.c:37
INT recFindSubDirs(DWORD dwFlags, TCHAR szSrcPath[MAX_PATH], TCHAR szDestPath[MAX_PATH], BOOL *doMore)
Definition: replace.c:315
@ REPLACE_UPDATE
Definition: replace.c:24
@ REPLACE_READ_ONLY
Definition: replace.c:21
@ REPLACE_SUBDIR
Definition: replace.c:22
@ REPLACE_DISK
Definition: replace.c:23
@ REPLACE_ADD
Definition: replace.c:19
@ REPLACE_CONFIRM
Definition: replace.c:20

◆ cmd_rmdir()

INT cmd_rmdir ( LPTSTR  param)

Definition at line 521 of file internal.c.

522{
523 INT nError = 0;
524 INT res;
525 LPTSTR *arg;
526 INT args;
527 INT dirCount;
528 INT i;
529 TCHAR ch;
530 BOOL bRecurseDir = FALSE;
531 BOOL bQuiet = FALSE;
532
533 if (!_tcsncmp(param, _T("/?"), 2))
534 {
536 return 0;
537 }
538
539 arg = split(param, &args, FALSE, FALSE);
540 dirCount = 0;
541
542 /* Check for options anywhere in command line */
543 for (i = 0; i < args; i++)
544 {
545 if (*arg[i] == _T('/'))
546 {
547 /* Found an option, but check to make sure it has something after it */
548 if (_tcslen(arg[i]) == 2)
549 {
550 ch = _totupper(arg[i][1]);
551
552 if (ch == _T('S'))
553 bRecurseDir = TRUE;
554 else if (ch == _T('Q'))
555 bQuiet = TRUE;
556 }
557 }
558 else
559 {
560 dirCount++;
561 }
562 }
563
564 if (dirCount == 0)
565 {
566 /* No folder to remove */
568 freep(arg);
569 return 1;
570 }
571
572 for (i = 0; i < args; i++)
573 {
574 if (*arg[i] == _T('/'))
575 continue;
576
577 if (bRecurseDir)
578 {
579 /* Ask the user whether to delete everything in the folder */
580 if (!bQuiet)
581 {
583 if (res == PROMPT_NO || res == PROMPT_BREAK)
584 {
585 nError = 1;
586 continue;
587 }
588 if (res == PROMPT_ALL)
589 bQuiet = TRUE;
590 }
591
592 res = DeleteFolder(arg[i]);
593 }
594 else
595 {
596 /* Without /S, do not force directory deletion even if it's read-only */
598 }
599
600 if (!res)
601 {
602 /* Couldn't delete the folder, print out the error */
603 nError = GetLastError();
604 ErrorMessage(nError, NULL);
605 }
606 }
607
608 freep(arg);
609 return nError;
610}
INT FilePromptYNA(UINT)
Definition: misc.c:622
BOOL DeleteFolder(LPTSTR Directory)
Definition: internal.c:414
#define STRING_RMDIR_HELP
Definition: resource.h:165
#define STRING_DEL_HELP2
Definition: resource.h:101
GLuint res
Definition: glext.h:9613

◆ cmd_set()

INT cmd_set ( LPTSTR  param)

Definition at line 72 of file set.c.

73{
74 INT retval = 0;
75 LPTSTR p;
76 LPTSTR lpEnv;
77 LPTSTR lpOutput;
78
79 if (!_tcsncmp(param, _T("/?"), 2))
80 {
82 return 0;
83 }
84
86
87 /* If no parameters, show the environment */
88 if (param[0] == _T('\0'))
89 {
91 if (lpEnv)
92 {
93 lpOutput = lpEnv;
94 while (*lpOutput)
95 {
96 /* Do not display the special '=X:' environment variables */
97 if (*lpOutput != _T('='))
98 {
99 ConOutPuts(lpOutput);
100 ConOutChar(_T('\n'));
101 }
102 lpOutput += _tcslen(lpOutput) + 1;
103 }
105 }
106
107 retval = 0;
108 goto Quit;
109 }
110
111 /* The /A does *NOT* have to be followed by a whitespace */
112 if (!_tcsnicmp(param, _T("/A"), 2))
113 {
115
116 /* Save error level since seta_eval() modifies it, as
117 * we need to set it later according to specific rules. */
118 INT nOldErrorLevel = nErrorLevel;
119
122 if (!Success)
123 {
124#if 0
125 /* Might seem random but this is what windows xp does -- This is a message ID */
126 retval = 9165;
127#endif
128 retval = nErrorLevel;
129 nErrorLevel = nOldErrorLevel;
130 }
131 else
132 {
133 retval = 0;
134 }
135 goto Quit;
136 }
137
138 if (!_tcsnicmp(param, _T("/P"), 2))
139 {
140 TCHAR value[1023];
142 p = _tcschr(param, _T('='));
143 if (!p)
144 {
146 retval = 1;
147 goto Quit;
148 }
149
150 *p++ = _T('\0');
153
155 {
156 retval = 1;
157 goto Quit;
158 }
159 retval = 0;
160 goto Quit;
161 }
162
164
165 p = _tcschr(param, _T('='));
166 if (p)
167 {
168 /* Set or remove the environment variable */
169 if (p == param)
170 {
171 /* Handle set =val case */
173 retval = 1;
174 goto Quit;
175 }
176
177 *p++ = _T('\0');
178 if (!SetEnvironmentVariable(param, *p ? p : NULL))
179 {
180 retval = 1;
181 goto Quit;
182 }
183 }
184 else
185 {
186 /* Display all the environment variables with the given prefix */
187 LPTSTR pOrgParam = param;
188 BOOLEAN bFound = FALSE;
189 BOOLEAN bRestoreSpace;
190
191 /*
192 * Trim the prefix from "special" characters (only when displaying the
193 * environment variables), so that e.g. "SET ,; ,;FOO" will display all
194 * the variables starting by "FOO".
195 * The SET command allows as well to set an environment variable whose name
196 * actually contains these characters (e.g. "SET ,; ,;FOO=42"); however,
197 * by trimming the characters, doing "SET ,; ,;FOO" would not allow seeing
198 * such variables.
199 * Thus, we also save a pointer to the original variable name prefix, that
200 * we will look it up as well below.
201 */
202 while (_istspace(*param) || *param == _T(',') || *param == _T(';'))
203 ++param;
204
205 /* Just remove the very last space, if present */
206 p = _tcsrchr(param, _T(' '));
207 bRestoreSpace = (p != NULL);
208 if (!p)
209 p = param + _tcslen(param);
210 *p = _T('\0');
211
212 lpEnv = GetEnvironmentStrings();
213 if (lpEnv)
214 {
215 lpOutput = lpEnv;
216 while (*lpOutput)
217 {
218 /* Look up for both the original and truncated variable name prefix */
219 if (!_tcsnicmp(lpOutput, pOrgParam, p - pOrgParam) ||
220 !_tcsnicmp(lpOutput, param, p - param))
221 {
222 ConOutPuts(lpOutput);
223 ConOutChar(_T('\n'));
224 bFound = TRUE;
225 }
226 lpOutput += _tcslen(lpOutput) + 1;
227 }
229 }
230
231 /* Restore the truncated space for correctly
232 * displaying the error message, if any. */
233 if (bRestoreSpace)
234 *p = _T(' ');
235
236 if (!bFound)
237 {
239 retval = 1;
240 goto Quit;
241 }
242 }
243
244Quit:
245 if (BatType != CMD_TYPE)
246 {
247 if (retval != 0)
248 nErrorLevel = retval;
249 }
250 else
251 {
252 nErrorLevel = retval;
253 }
254
255 return retval;
256}
unsigned char BOOLEAN
#define STRING_SYNTAX_COMMAND_INCORRECT
Definition: resource.h:218
#define STRING_SET_HELP
Definition: resource.h:171
@ Success
Definition: eventcreate.c:712
static BOOL seta_eval(LPCTSTR expr)
Definition: set.c:723
static LPTSTR GetQuotedString(TCHAR *p)
Definition: set.c:58
static LPCTSTR skip_ws(LPCTSTR p)
Definition: set.c:48
Definition: pdh_main.c:94
#define FreeEnvironmentStrings
Definition: winbase.h:3731
LPSTR WINAPI GetEnvironmentStrings(void)

◆ cmd_setlocal()

INT cmd_setlocal ( LPTSTR  param)

Definition at line 42 of file setlocal.c.

43{
44 PSETLOCAL Saved;
45 LPTSTR* arg;
46 INT argc, i;
47
48 if (!_tcscmp(param, _T("/?")))
49 {
50 // FIXME
51 ConOutPuts(_T("SETLOCAL help not implemented yet!\n"));
52 return 0;
53 }
54
55 /* SETLOCAL only works inside a batch context */
56 if (!bc)
57 return 0;
58
59 Saved = cmd_alloc(sizeof(SETLOCAL));
60 if (!Saved)
61 {
62 WARN("Cannot allocate memory for Saved!\n");
64 return 1;
65 }
66
68 if (!Saved->Environment)
69 {
71 cmd_free(Saved);
72 return 1;
73 }
74 /*
75 * Save the current drive; the duplicated environment
76 * contains the corresponding current directory.
77 */
78 Saved->CurDrive = _getdrive();
79
82
83 Saved->Prev = bc->setlocal;
84 bc->setlocal = Saved;
85
86 nErrorLevel = 0;
87
89 for (i = 0; i < argc; i++)
90 {
91 if (!_tcsicmp(arg[i], _T("ENABLEEXTENSIONS")))
93 else if (!_tcsicmp(arg[i], _T("DISABLEEXTENSIONS")))
95 else if (!_tcsicmp(arg[i], _T("ENABLEDELAYEDEXPANSION")))
97 else if (!_tcsicmp(arg[i], _T("DISABLEDELAYEDEXPANSION")))
99 else
100 {
102 break;
103 }
104 }
105 freep(arg);
106
107 return nErrorLevel;
108}
_Check_return_ _CRTIMP int __cdecl _getdrive(void)
Definition: getdrive.c:20

◆ cmd_shift()

int cmd_shift ( TCHAR )

◆ cmd_start()

INT cmd_start ( LPTSTR  Rest)

Definition at line 37 of file start.c.

38{
39 TCHAR szFullName[CMDLINE_LENGTH];
40 TCHAR szUnquotedName[CMDLINE_LENGTH];
41 TCHAR *param = NULL;
42 TCHAR *dot;
43 INT size;
44 LPTSTR comspec;
45 BOOL bWait = FALSE;
46 BOOL bBat = FALSE;
48 TCHAR szFullCmdLine[CMDLINE_LENGTH];
50 STARTUPINFO stui;
51#ifdef UNICODE
53#else
54 DWORD dwCreationFlags = CREATE_NEW_CONSOLE;
55#endif
56 DWORD dwAffinityMask = 0;
59 LPTSTR lpEnvironment = NULL;
60 WORD wShowWindow = SW_SHOWNORMAL;
61
62 while (1)
63 {
64 if (_istspace(*Rest))
65 {
66 Rest++;
67 }
68 else if (*Rest == _T('"') && !lpTitle)
69 {
70 lpTitle = GetParameter(&Rest);
72 }
73 else if (*Rest == _T('/'))
74 {
76 Rest++;
77 option = GetParameter(&Rest);
78 if (*option == _T('?'))
79 {
81 return 0;
82 }
83 else if (_totupper(*option) == _T('D'))
84 {
85 lpDirectory = option + 1;
86 if (!*lpDirectory)
87 {
88 while (_istspace(*Rest))
89 Rest++;
91 }
93 }
94 else if (_totupper(*option) == _T('I'))
95 {
96 /* rest of the option is apparently ignored */
97 lpEnvironment = lpOriginalEnvironment;
98 }
99 else if (!_tcsicmp(option, _T("MIN")))
100 {
101 wShowWindow = SW_MINIMIZE;
102 }
103 else if (!_tcsicmp(option, _T("MAX")))
104 {
105 wShowWindow = SW_MAXIMIZE;
106 }
107 else if (!_tcsicmp(option, _T("AFFINITY")))
108 {
109 TCHAR *end;
110 while (_istspace(*Rest))
111 Rest++;
112 option = GetParameter(&Rest);
113 /* Affinity mask is given in hexadecimal */
114 dwAffinityMask = _tcstoul(option, &end, 16);
115 if (*end != _T('\0') || dwAffinityMask == 0 ||
116 dwAffinityMask == (DWORD)-1)
117 {
119 return 1;
120 }
121 dwCreationFlags |= CREATE_SUSPENDED;
122 }
123 else if (!_tcsicmp(option, _T("B")))
124 {
125 dwCreationFlags &= ~CREATE_NEW_CONSOLE;
126 dwCreationFlags |= CREATE_NEW_PROCESS_GROUP;
127 }
128 else if (!_tcsicmp(option, _T("LOW")))
129 {
130 dwCreationFlags |= IDLE_PRIORITY_CLASS;
131 }
132 else if (!_tcsicmp(option, _T("NORMAL")))
133 {
134 dwCreationFlags |= NORMAL_PRIORITY_CLASS;
135 }
136 else if (!_tcsicmp(option, _T("HIGH")))
137 {
138 dwCreationFlags |= HIGH_PRIORITY_CLASS;
139 }
140 else if (!_tcsicmp(option, _T("REALTIME")))
141 {
142 dwCreationFlags |= REALTIME_PRIORITY_CLASS;
143 }
144 else if (!_tcsicmp(option, _T("ABOVENORMAL")))
145 {
146 dwCreationFlags |= ABOVE_NORMAL_PRIORITY_CLASS;
147 }
148 else if (!_tcsicmp(option, _T("BELOWNORMAL")))
149 {
150 dwCreationFlags |= BELOW_NORMAL_PRIORITY_CLASS;
151 }
152 else if (!_tcsicmp(option, _T("SEPARATE")))
153 {
154 dwCreationFlags |= CREATE_SEPARATE_WOW_VDM;
155 }
156 else if (!_tcsicmp(option, _T("SHARED")))
157 {
158 dwCreationFlags |= CREATE_SHARED_WOW_VDM;
159 }
160 else if (!_tcsicmp(option, _T("W")) ||
161 !_tcsicmp(option, _T("WAIT")))
162 {
163 bWait = TRUE;
164 }
165 else
166 {
168 return 0;
169 }
170 }
171 else
172 {
173 /* It's not an option - must be the beginning of
174 * the actual command. Leave the loop. */
175 break;
176 }
177 }
178
179 /* get comspec */
180 comspec = cmd_alloc ( MAX_PATH * sizeof(TCHAR));
181 if (!comspec)
182 {
183 WARN("Cannot allocate memory for start comspec!\n");
185 return 1;
186 }
187 SetLastError(0);
188 size = GetEnvironmentVariable (_T("COMSPEC"), comspec, MAX_PATH);
190 {
191 _tcscpy(comspec, _T("cmd"));
192 }
193 else
194 {
195 if (size > MAX_PATH)
196 {
197 LPTSTR Oldcomspec = comspec;
198 comspec = cmd_realloc(comspec,size * sizeof(TCHAR) );
199 if (comspec==NULL)
200 {
201 cmd_free(Oldcomspec);
202 return 1;
203 }
204 size = GetEnvironmentVariable (_T("COMSPEC"), comspec, size);
205 }
206 }
207
208 nErrorLevel = 0;
209
210 if (!*Rest)
211 {
212 Rest = _T("cmd.exe");
213 }
214 else
215 /* Parsing the command that gets called by start, and it's parameters */
216 {
217 BOOL bInside = FALSE;
218 INT i;
219 /* find the end of the command and put the arguments in param */
220 for (i = 0; Rest[i]; i++)
221 {
222 if (Rest[i] == _T('\"'))
223 bInside = !bInside;
224 if (_istspace(Rest[i]) && !bInside)
225 {
226 param = &Rest[i+1];
227 Rest[i] = _T('\0');
228 break;
229 }
230 }
231 }
232
233 _tcscpy(szUnquotedName, Rest);
234 StripQuotes(szUnquotedName);
235
236 /* get the PATH environment variable and parse it */
237 /* search the PATH environment variable for the binary */
238 if (SearchForExecutable(szUnquotedName, szFullName))
239 {
240 /* check if this is a .BAT or .CMD file */
241 dot = _tcsrchr(szFullName, _T('.'));
242 if (dot && (!_tcsicmp(dot, _T(".bat")) || !_tcsicmp(dot, _T(".cmd"))))
243 {
244 bBat = TRUE;
245 _stprintf(szFullCmdLine, _T("\"%s\" /K %s"), comspec, Rest);
246 TRACE ("[BATCH: %s %s]\n", debugstr_aw(szFullName), debugstr_aw(Rest));
247 }
248 else
249 {
250 TRACE ("[EXEC: %s %s]\n", debugstr_aw(szFullName), debugstr_aw(Rest));
251 _tcscpy(szFullCmdLine, szFullName);
252 }
253
254 /* build command line for CreateProcess() */
255 if (param != NULL)
256 {
257 _tcsncat(szFullCmdLine, _T(" "), CMDLINE_LENGTH - _tcslen(szFullCmdLine));
258 _tcsncat(szFullCmdLine, param, CMDLINE_LENGTH - _tcslen(szFullCmdLine));
259 }
260
261 /* fill startup info */
262 memset (&stui, 0, sizeof (STARTUPINFO));
263 stui.cb = sizeof (STARTUPINFO);
265 stui.lpTitle = lpTitle;
266 stui.wShowWindow = wShowWindow;
267
268 bCreate = CreateProcess(bBat ? comspec : szFullName,
269 szFullCmdLine, NULL, NULL, TRUE, dwCreationFlags,
270 lpEnvironment, lpDirectory, &stui, &prci);
271 if (bCreate)
272 {
273 if (dwAffinityMask)
274 {
275 SetProcessAffinityMask(prci.hProcess, dwAffinityMask);
276 ResumeThread(prci.hThread);
277 }
278 CloseHandle(prci.hThread);
279 }
280 }
281 else
282 {
283 /* The file name did not seem to be valid, but maybe it's actually a
284 * directory or URL, so we still want to pass it to ShellExecute. */
285 _tcscpy(szFullName, szUnquotedName);
286 }
287
288 if (!bCreate)
289 {
290 /* CreateProcess didn't work; try ShellExecute */
292 if (!(dwCreationFlags & CREATE_NEW_CONSOLE))
294 prci.hProcess = RunFile(flags, szFullName, param, lpDirectory, wShowWindow);
295 }
296
297 if (prci.hProcess != NULL)
298 {
299 if (bWait)
300 {
301 DWORD dwExitCode;
303 GetExitCodeProcess (prci.hProcess, &dwExitCode);
304 nErrorLevel = (INT)dwExitCode;
305 }
306 CloseHandle (prci.hProcess);
307
308 /* Update the local code page cache */
309 {
310 UINT uNewInputCodePage = GetConsoleCP();
311 UINT uNewOutputCodePage = GetConsoleOutputCP();
312
313 if ((InputCodePage != uNewInputCodePage) ||
314 (OutputCodePage != uNewOutputCodePage))
315 {
316 InputCodePage = uNewInputCodePage;
317 OutputCodePage = uNewOutputCodePage;
318
319 /* Reset the current thread UI language */
322 {
324 }
325 /* Update the streams cached code page */
327
328 /* Update the locale as well */
329 InitLocale();
330 }
331 }
332 }
333 else
334 {
336 _T("Error executing CreateProcess()!!\n"));
337 }
338
339 cmd_free(comspec);
340 return 0;
341}
#define StdErr
Definition: fc.c:15
#define CMDLINE_LENGTH
Definition: help.h:12
LPTSTR lpOriginalEnvironment
Definition: cmd.c:164
HANDLE RunFile(DWORD flags, LPTSTR filename, LPTSTR params, LPTSTR directory, INT show)
Definition: cmd.c:266
BOOL SearchForExecutable(LPCTSTR, LPTSTR)
Definition: where.c:142
VOID InitLocale(VOID)
Definition: locale.c:25
UINT InputCodePage
Definition: console.c:25
UINT OutputCodePage
Definition: console.c:26
#define STRING_TYPE_ERROR
Definition: resource.h:58
#define STRING_START_HELP1
Definition: resource.h:173
TCHAR lpTitle[80]
Definition: ctm.c:69
#define CloseHandle
Definition: compat.h:739
#define SetLastError(x)
Definition: compat.h:752
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleOutputCP(VOID)
Definition: console.c:2451
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleCP(VOID)
Definition: console.c:2391
BOOL WINAPI GetExitCodeProcess(IN HANDLE hProcess, IN LPDWORD lpExitCode)
Definition: proc.c:1168
BOOL WINAPI SetProcessAffinityMask(IN HANDLE hProcess, IN DWORD_PTR dwProcessAffinityMask)
Definition: proc.c:894
DWORD WINAPI ResumeThread(IN HANDLE hThread)
Definition: thread.c:567
#define INFINITE
Definition: serial.h:102
unsigned short WORD
Definition: ntddk_ex.h:93
GLuint GLuint end
Definition: gl.h:1545
GLbitfield flags
Definition: glext.h:7161
#define _tcstoul
Definition: tchar.h:595
unsigned int UINT
Definition: ndis.h:50
#define INT
Definition: polytest.cpp:20
#define IsConsoleHandle(h)
Definition: console.h:14
#define ConStdStreamsSetCacheCodePage(InputCodePage, OutputCodePage)
Definition: stream.h:152
LANGID ConSetThreadUILanguage(IN LANGID LangId OPTIONAL)
Definition: utils.c:352
#define memset(x, y, z)
Definition: compat.h:39
static TCHAR * GetParameter(TCHAR **pPointer)
Definition: start.c:20
#define SEE_MASK_NOCLOSEPROCESS
Definition: shellapi.h:31
_In_opt_ LPCSTR lpDirectory
Definition: shellapi.h:481
#define SEE_MASK_NO_CONSOLE
Definition: shellapi.h:38
_In_ int _In_ BOOL bCreate
Definition: shlobj.h:1511
LPSTR lpTitle
Definition: winbase.h:834
DWORD dwFlags
Definition: winbase.h:842
DWORD cb
Definition: winbase.h:831
WORD wShowWindow
Definition: winbase.h:843
Definition: getopt.h:109
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define CreateProcess
Definition: winbase.h:3693
#define NORMAL_PRIORITY_CLASS
Definition: winbase.h:181
#define STARTF_USESHOWWINDOW
Definition: winbase.h:491
#define REALTIME_PRIORITY_CLASS
Definition: winbase.h:184
#define BELOW_NORMAL_PRIORITY_CLASS
Definition: winbase.h:190
STARTUPINFOA STARTUPINFO
Definition: winbase.h:3654
#define CREATE_UNICODE_ENVIRONMENT
Definition: winbase.h:186
#define HIGH_PRIORITY_CLASS
Definition: winbase.h:183
#define CREATE_SHARED_WOW_VDM
Definition: winbase.h:188
#define CREATE_SEPARATE_WOW_VDM
Definition: winbase.h:187
#define CREATE_NEW_PROCESS_GROUP
Definition: winbase.h:185
#define CREATE_SUSPENDED
Definition: winbase.h:178
#define IDLE_PRIORITY_CLASS
Definition: winbase.h:182
#define CREATE_NEW_CONSOLE
Definition: winbase.h:180
#define ABOVE_NORMAL_PRIORITY_CLASS
Definition: winbase.h:191
#define ERROR_ENVVAR_NOT_FOUND
Definition: winerror.h:261
#define SW_SHOWNORMAL
Definition: winuser.h:770
#define SW_MINIMIZE
Definition: winuser.h:776
#define SW_MAXIMIZE
Definition: winuser.h:772

◆ cmd_time()

INT cmd_time ( LPTSTR  param)

Definition at line 132 of file time.c.

133{
134 LPTSTR* arg;
135 INT argc;
136 INT i;
137 INT nTimeString = -1;
138 TCHAR szTime[40];
139
140 if (!_tcsncmp(param, _T("/?"), 2))
141 {
143 return 0;
144 }
145
146 nErrorLevel = 0;
147
148 /* Build the parameter array */
149 arg = split(param, &argc, FALSE, FALSE);
150
151 /* Check for options */
152 for (i = 0; i < argc; i++)
153 {
154 if (bEnableExtensions && (_tcsicmp(arg[i], _T("/T")) == 0))
155 {
156 /* Display current time in short format */
157 SYSTEMTIME st;
158 GetLocalTime(&st);
159 FormatTime(szTime, &st);
160 ConOutPrintf(_T("%s\n"), szTime);
161 freep(arg);
162 return 0;
163 }
164
165 if ((*arg[i] != _T('/')) && (nTimeString == -1))
166 nTimeString = i;
167 }
168
169 if (nTimeString == -1)
170 {
172 ConOutPrintf(_T("%s\n"), GetTimeString());
173 }
174
175 while (TRUE)
176 {
177 if (nTimeString == -1)
178 {
181
182 TRACE("\'%s\'\n", debugstr_aw(szTime));
183
184 while (*szTime && szTime[_tcslen(szTime) - 1] < _T(' '))
185 szTime[_tcslen(szTime) - 1] = _T('\0');
186
187 if (ParseTime(szTime))
188 {
189 freep(arg);
190 return 0;
191 }
192 }
193 else
194 {
195 if (ParseTime(arg[nTimeString]))
196 {
197 freep(arg);
198 return 0;
199 }
200
201 /* Force input the next time around */
202 nTimeString = -1;
203 }
204
206 nErrorLevel = 1;
207 }
208
209 freep(arg);
210 return 0;
211}
LPTSTR GetTimeString(VOID)
Definition: locale.c:73
INT FormatTime(TCHAR *, LPSYSTEMTIME)
Definition: dir.c:704
#define STRING_TIME_ERROR
Definition: resource.h:57
#define STRING_TIME_HELP2
Definition: resource.h:178
#define STRING_TIME_HELP1
Definition: resource.h:177
#define STRING_TIME_NOW
Definition: resource.h:137
static BOOL ParseTime(LPTSTR s)
Definition: time.c:32
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:286
TCHAR szTime[64]
Definition: solitaire.cpp:20

Referenced by Initialize().

◆ cmd_title()

INT cmd_title ( LPTSTR  param)

Definition at line 18 of file title.c.

19{
20 /* Do nothing if no args */
21 if (*param == _T('\0'))
22 return 0;
23
24 /* Asking help? */
25 if (!_tcsncmp(param, _T("/?"), 2))
26 {
28 return 0;
29 }
30
31 /* Set the new console title, and tell CMD to not reset it */
33 return ConSetTitle(param);
34}
BOOL ConSetTitle(IN LPCTSTR lpConsoleTitle)
Definition: console.c:280
#define STRING_TITLE_HELP
Definition: resource.h:175
BOOL bTitleSet
Definition: cmd.c:167

◆ cmd_type()

INT cmd_type ( LPTSTR  param)

Definition at line 221 of file type.c.

222{
223 INT argc, i;
224 LPTSTR* argv;
226 HANDLE hConsoleOut;
227 BOOL bNoFileName = FALSE;
228 BOOL bPaging = FALSE;
229 BOOL bFileFound;
230 DWORD dwLastError;
231 UINT nFileSpecs = 0;
232 HANDLE hFind;
233 WIN32_FIND_DATA FindData;
234
235 if (!_tcsncmp(param, _T("/?"), 2))
236 {
238 return 0;
239 }
240
241 if (!*param)
242 {
244 return 1;
245 }
246
247 /* Parse the command line. We will manually expand any file specification present. */
249
250 /* Loop through the options, count also the specified number of file specifications */
251 for (i = 0; i < argc; ++i)
252 {
253 if (argv[i][0] == _T('/'))
254 {
255 if (_tcslen(argv[i]) == 2)
256 {
257 switch (_totupper(argv[i][1]))
258 {
259 case _T('N'):
260 bNoFileName = TRUE;
261 continue;
262
263 case _T('P'):
264 bPaging = TRUE;
265 continue;
266 }
267 }
268
269 // error_invalid_switch(argv[i] + 1);
271 nErrorLevel = 1;
272 goto Quit;
273 }
274
275 /* This should be a file specification */
276 ++nFileSpecs;
277 }
278
279 nErrorLevel = 0;
280
281 hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
282
283 /* Reset paging state */
284 if (bPaging)
286
287 /* Now loop through the files */
288 for (i = 0; i < argc; ++i)
289 {
290 /* Skip the options */
291 if (argv[i][0] == _T('/'))
292 continue;
293
294 /* If wildcards are present in this file specification, perform a file enumeration */
295 if (_tcschr(argv[i], _T('*')) || _tcschr(argv[i], _T('?')))
296 {
297 dwLastError = ERROR_SUCCESS;
298 bFileFound = FALSE;
299
300 hFind = FindFirstFile(argv[i], &FindData);
301
302 if (hFind != INVALID_HANDLE_VALUE)
303 {
304 /* Loop through all the files */
305 do
306 {
307 /* Ignore any directory silently */
308 if (!_tcscmp(FindData.cFileName, _T(".")) ||
309 !_tcscmp(FindData.cFileName, _T("..")) ||
310 (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
311 {
312 continue;
313 }
314
315 bFileFound = TRUE;
316 if (!DoTypeFile(FindData.cFileName, hConsoleOut, bNoFileName, bPaging))
317 {
318 FindClose(hFind);
319 goto Quit;
320 }
321
322 } while (FindNextFile(hFind, &FindData));
323
324 FindClose(hFind);
325 }
326
327 /*
328 * Return an error if the file specification could not be resolved,
329 * or no actual files were encountered (but only directories).
330 */
331 if (hFind == INVALID_HANDLE_VALUE)
332 dwLastError = GetLastError();
333 else if (!bFileFound)
334 dwLastError = ERROR_FILE_NOT_FOUND;
335
336 if (dwLastError != ERROR_SUCCESS)
337 {
338 // FIXME: Use ErrorMessage() ?
342 NULL,
343 dwLastError,
345 (LPTSTR)&errmsg,
346 0,
347 NULL);
348 ConErrPrintf(_T("%s - %s"), argv[i], errmsg);
350 nErrorLevel = 1;
351 }
352 }
353 else
354 {
355 if (!DoTypeFile(argv[i], hConsoleOut, (bNoFileName || (nFileSpecs <= 1)), bPaging))
356 goto Quit;
357 }
358
359 /* Continue with the next file specification */
360 }
361
362Quit:
363 freep(argv);
364 return nErrorLevel;
365}
BOOL __cdecl ConOutPrintfPaging(BOOL StartPaging, LPTSTR szFormat,...)
Definition: console.c:171
#define STRING_TYPE_HELP1
Definition: resource.h:184
static BOOL DoTypeFile(IN LPTSTR FileName, IN HANDLE hConsoleOut, IN BOOL bNoFileName, IN BOOL bPaging)
Definition: type.c:78
EXPORT int errmsg(char *msg, va_alist)
Definition: comerr.c:192
#define ERROR_SUCCESS
Definition: deptool.c:10
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define argv
Definition: mplay32.c:18
#define LANG_NEUTRAL
Definition: nls.h:22
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define FormatMessage
Definition: winbase.h:3730
#define STD_OUTPUT_HANDLE
Definition: winbase.h:268
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:420
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419

Referenced by client_dde_callback().

◆ cmd_ver()

INT cmd_ver ( LPTSTR  param)

Definition at line 126 of file ver.c.

127{
128 INT i;
129
130 nErrorLevel = 0;
131
132 if (_tcsstr(param, _T("/?")) != NULL)
133 {
135 return 0;
136 }
137
138 ConOutResPrintf(STRING_CMD_SHELLINFO, _T(KERNEL_VERSION_STR), _T(KERNEL_VERSION_BUILD_STR));
139 ConOutChar(_T('\n'));
142
143 /* Basic copyright notice */
144 if (param[0] != _T('\0'))
145 {
146 ConOutPuts(_T("\n\n"));
147 ConOutPuts(_T("Copyright (C) 1994-1998 Tim Norman and others.\n"));
148 ConOutPuts(_T("Copyright (C) 1998-") _T(COPYRIGHT_YEAR) _T(" ReactOS Team\n"));
149
150 for (i = 0; param[i]; i++)
151 {
152 /* Skip spaces */
153 if (param[i] == _T(' '))
154 continue;
155
156 if (param[i] == _T('/'))
157 {
158 /* Is this a lone '/' ? */
159 if (param[i + 1] == 0)
160 {
162 return 1;
163 }
164 continue;
165 }
166
167 if (_totupper(param[i]) == _T('W'))
168 {
169 /* Warranty notice */
171 }
172 else if (_totupper(param[i]) == _T('R'))
173 {
174 /* Redistribution notice */
176 }
177 else if (_totupper(param[i]) == _T('C'))
178 {
179 /* Developer listing */
184 }
185 else
186 {
188 return 1;
189 }
190 }
191
192 /* Bug report notice */
194 }
195
196 ConOutChar(_T('\n'));
197
198 return 0;
199}
#define STRING_VERSION_RUNNING_ON
Definition: resource.h:197
#define STRING_VERSION_HELP6
Definition: resource.h:195
#define STRING_VERSION_HELP7
Definition: resource.h:196
#define STRING_VERSION_HELP1
Definition: resource.h:190
#define STRING_VERSION_HELP3
Definition: resource.h:192
#define STRING_CMD_SHELLINFO
Definition: resource.h:90
#define STRING_FREEDOS_DEV
Definition: resource.h:243
#define STRING_REACTOS_DEV
Definition: resource.h:244
#define STRING_VERSION_HELP5
Definition: resource.h:194
#define STRING_VERSION_HELP4
Definition: resource.h:193
static void PrintOSVersion(void)
Definition: rosperf.c:291

◆ cmd_verify()

INT cmd_verify ( LPTSTR  param)

Definition at line 30 of file verify.c.

31{
32 if (!_tcsncmp (param, _T("/?"), 2))
33 {
35 return 0;
36 }
37
39 {
41 return nErrorLevel = 1;
42 }
43
44 return nErrorLevel = 0;
45}
BOOL OnOffCommand(LPTSTR param, LPBOOL flag, INT message)
Definition: echo.c:32
#define STRING_VERIFY_HELP1
Definition: resource.h:186
#define STRING_VERIFY_HELP3
Definition: resource.h:188
#define STRING_VERIFY_HELP2
Definition: resource.h:187
static BOOL bVerify
Definition: verify.c:27

◆ cmd_vol()

INT cmd_vol ( LPTSTR  param)

Definition at line 64 of file vol.c.

65{
66 TCHAR szRootPath[] = _T("A:\\");
68
69 if (!_tcsncmp(param, _T("/?"), 2))
70 {
72 return 0;
73 }
74
75 nErrorLevel = 0;
76
77 if (param[0] == _T('\0'))
78 {
80 szRootPath[0] = szPath[0];
81 }
82 else
83 {
84 _tcsupr (param);
85 if (param[1] == _T(':'))
86 {
87 szRootPath[0] = param[0];
88 }
89 else
90 {
92 nErrorLevel = 1;
93 return 1;
94 }
95 }
96
97 if (!IsValidPathName (szRootPath))
98 {
100 nErrorLevel = 1;
101 return 1;
102 }
103
104 /* print the header */
105 if (!PrintVolumeHeader (szRootPath))
106 {
107 nErrorLevel = 1;
108 return 1;
109 }
110
111 return 0;
112}
#define STRING_VOL_HELP4
Definition: resource.h:203
#define _tcsupr
Definition: tchar.h:1467
static BOOL IsValidPathName(LPCWSTR pszPath)
Definition: label.c:91
LPCWSTR szPath
Definition: env.c:37
static INT PrintVolumeHeader(LPTSTR pszRootPath)
Definition: vol.c:29

◆ CommandActivate()

INT CommandActivate ( LPTSTR  )

◆ CommandAlias()

INT CommandAlias ( LPTSTR  param)

Definition at line 174 of file alias.c.

175{
176 LPTSTR ptr;
177
178 if (!_tcsncmp (param, _T("/?"), 2))
179 {
181 return 0;
182 }
183
184 nErrorLevel = 0;
185
186 if (param[0] == _T('\0'))
187 {
188 PrintAlias ();
189 return 0;
190 }
191
192 nErrorLevel = 0;
193
194 /* error if no '=' found */
195 if ((ptr = _tcschr (param, _T('='))) == 0)
196 {
197 nErrorLevel = 1;
198 return 1;
199 }
200
201 /* Split rest into name and substitute */
202 *ptr++ = _T('\0');
203
205
206 if (ptr[0] == _T('\0'))
207 AddConsoleAlias(param, NULL, _T("cmd.exe"));
208 else
209 AddConsoleAlias(param, ptr, _T("cmd.exe"));
210
211 return 0;
212}
static VOID PrintAlias(VOID)
Definition: alias.c:54
static VOID partstrlwr(LPTSTR str)
Definition: alias.c:43
#define STRING_ALIAS_HELP
Definition: resource.h:69
#define AddConsoleAlias
Definition: wincon.h:769

◆ CommandAssoc()

INT CommandAssoc ( LPTSTR  param)

Definition at line 238 of file assoc.c.

239{
240 INT retval = 0;
241 PTCHAR pEqualSign;
242
243 /* Print help */
244 if (!_tcsncmp(param, _T("/?"), 2))
245 {
247 return 0;
248 }
249
250 /* Print all associations if no parameter has been specified */
251 if (!*param)
252 {
254 goto Quit;
255 }
256
257 pEqualSign = _tcschr(param, _T('='));
258 if (pEqualSign != NULL)
259 {
260 PTSTR pszFileType = pEqualSign + 1;
261
262 /* NULL-terminate at the equals sign */
263 *pEqualSign = 0;
264
265 /* If the equals sign is the last character
266 * in the string, delete the association. */
267 if (*pszFileType == 0)
268 {
269 retval = RemoveAssociation(param);
270 }
271 else
272 /* Otherwise, add the association and print it out */
273 {
274 retval = AddAssociation(param, pszFileType);
276 }
277
278 if (retval != ERROR_SUCCESS)
279 {
280 if (retval != ERROR_FILE_NOT_FOUND)
281 {
282 // FIXME: Localize
283 ConErrPrintf(_T("Error occurred while processing: %s.\n"), param);
284 }
285 // retval = 1; /* Fixup the error value */
286 }
287 }
288 else
289 {
290 /* No equals sign, print the association */
291 retval = PrintAssociation(param);
292 if (retval != ERROR_SUCCESS)
293 {
295 retval = 1; /* Fixup the error value */
296 }
297 }
298
299Quit:
300 if (BatType != CMD_TYPE)
301 {
302 if (retval != 0)
303 nErrorLevel = retval;
304 }
305 else
306 {
307 nErrorLevel = retval;
308 }
309
310 return retval;
311}
static LONG PrintAssociation(IN PCTSTR pszExtension)
Definition: assoc.c:87
static LONG AddAssociation(IN PCTSTR pszExtension, IN PCTSTR pszType)
Definition: assoc.c:171
static LONG PrintAllAssociations(VOID)
Definition: assoc.c:108
static LONG RemoveAssociation(IN PCTSTR pszExtension)
Definition: assoc.c:210
#define STRING_ASSOC_ERROR
Definition: resource.h:67
#define STRING_ASSOC_HELP
Definition: resource.h:83

◆ CommandChoice()

INT CommandChoice ( LPTSTR  param)

Definition at line 102 of file choice.c.

103{
104 LPTSTR lpOptions;
105 TCHAR Options[6];
106 LPTSTR lpText = NULL;
107 BOOL bNoPrompt = FALSE;
109 BOOL bTimeout = FALSE;
110 INT nTimeout = 0;
111 TCHAR cDefault = _T('\0');
112 INPUT_RECORD ir;
113 LPTSTR p, np;
114 LPTSTR *arg;
115 INT argc;
116 INT i;
117 INT val;
118
119 INT GCret;
120 TCHAR Ch;
121 DWORD amount,clk;
122
124 lpOptions = Options;
125
126 if (_tcsncmp (param, _T("/?"), 2) == 0)
127 {
129 return 0;
130 }
131
132 /* retrieve text */
133 p = param;
134
135 while (TRUE)
136 {
137 if (*p == _T('\0'))
138 break;
139
140 if (*p != _T('/'))
141 {
142 lpText = p;
143 break;
144 }
145 np = _tcschr (p, _T(' '));
146 if (!np)
147 break;
148 p = np + 1;
149 }
150
151 /* build parameter array */
152 arg = split (param, &argc, FALSE, FALSE);
153
154 /* evaluate arguments */
155 if (argc > 0)
156 {
157 for (i = 0; i < argc; i++)
158 {
159 if (_tcsnicmp (arg[i], _T("/c"), 2) == 0)
160 {
161 if (arg[i][2] == _T(':'))
162 lpOptions = &arg[i][3];
163 else
164 lpOptions = &arg[i][2];
165
166 if (_tcslen (lpOptions) == 0)
167 {
169 freep (arg);
170 return 1;
171 }
172 }
173 else if (_tcsnicmp (arg[i], _T("/n"), 2) == 0)
174 {
175 bNoPrompt = TRUE;
176 }
177 else if (_tcsnicmp (arg[i], _T("/s"), 2) == 0)
178 {
180 }
181 else if (_tcsnicmp (arg[i], _T("/t"), 2) == 0)
182 {
183 LPTSTR s;
184
185 if (arg[i][2] == _T(':'))
186 {
187 cDefault = arg[i][3];
188 s = &arg[i][4];
189 }
190 else
191 {
192 cDefault = arg[i][2];
193 s = &arg[i][3];
194 }
195
196 if (*s != _T(','))
197 {
199 freep (arg);
200 return 1;
201 }
202
203 s++;
204 nTimeout = _ttoi(s);
205 bTimeout = TRUE;
206 }
207 else if (arg[i][0] == _T('/'))
208 {
210 freep (arg);
211 return 1;
212 }
213 }
214 }
215
216 /* print text */
217 if (lpText)
218 ConOutPrintf (_T("%s"), lpText);
219
220 /* print options */
221 if (bNoPrompt == FALSE)
222 {
223 ConOutPrintf (_T("[%c"), lpOptions[0]);
224
225 for (i = 1; (unsigned)i < _tcslen (lpOptions); i++)
226 ConOutPrintf (_T(",%c"), lpOptions[i]);
227
228 ConOutPrintf (_T("]?"));
229 }
230
231 ConInFlush ();
232
233 if (!bTimeout)
234 {
235 while (TRUE)
236 {
237 ConInKey (&ir);
238
239 val = IsKeyInString (lpOptions,
240#ifdef _UNICODE
242#else
244#endif
246
247 if (val >= 0)
248 {
249 ConOutPrintf (_T("%c\n"), lpOptions[val]);
250
251 nErrorLevel = val + 1;
252
253 break;
254 }
255
256 Beep (440, 50);
257 }
258
259 freep (arg);
260 TRACE ("ErrorLevel: %d\n", nErrorLevel);
261 return 0;
262 }
263
264 clk = GetTickCount ();
265 amount = nTimeout*1000;
266
267loop:
268 GCret = GetCharacterTimeout (&Ch, amount - (GetTickCount () - clk));
269
270 switch (GCret)
271 {
272 case GC_TIMEOUT:
273 TRACE ("GC_TIMEOUT\n");
274 TRACE ("elapsed %d msecs\n", GetTickCount () - clk);
275 break;
276
277 case GC_NOKEY:
278 TRACE ("GC_NOKEY\n");
279 TRACE ("elapsed %d msecs\n", GetTickCount () - clk);
280 goto loop;
281
282 case GC_KEYREAD:
283 TRACE ("GC_KEYREAD\n");
284 TRACE ("elapsed %d msecs\n", GetTickCount () - clk);
285 TRACE ("read %c\n", Ch);
286 if ((val=IsKeyInString(lpOptions,Ch,bCaseSensitive))==-1)
287 {
288 Beep (440, 50);
289 goto loop;
290 }
291 cDefault=Ch;
292 break;
293 }
294
295 TRACE ("exiting wait loop after %d msecs\n",
296 GetTickCount () - clk);
297
298 val = IsKeyInString (lpOptions, cDefault, bCaseSensitive);
299 ConOutPrintf(_T("%c\n"), lpOptions[val]);
300
301 nErrorLevel = val + 1;
302
303 freep (arg);
304
305 TRACE ("ErrorLevel: %d\n", nErrorLevel);
306
307 return 0;
308}
VOID ConInKey(PINPUT_RECORD lpBuffer)
Definition: console.c:61
VOID ConInFlush(VOID)
Definition: console.c:56
#define STRING_CHOICE_ERROR_TXT
Definition: resource.h:25
#define STRING_CHOICE_OPTION
Definition: resource.h:19
#define STRING_CHOICE_HELP
Definition: resource.h:73
#define STRING_CHOICE_ERROR_OPTION
Definition: resource.h:26
#define STRING_CHOICE_ERROR
Definition: resource.h:24
#define GC_KEYREAD
Definition: choice.c:28
#define GC_NOKEY
Definition: choice.c:27
static INT IsKeyInString(LPTSTR lpString, TCHAR cKey, BOOL bCaseSensitive)
Definition: choice.c:75
#define GC_TIMEOUT
Definition: choice.c:26
static INT GetCharacterTimeout(LPTCH ch, DWORD dwMilliseconds)
Definition: choice.c:32
BOOL WINAPI Beep(IN DWORD dwFreq, IN DWORD dwDuration)
Definition: deviceio.c:48
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
GLdouble s
Definition: gl.h:2039
GLuint GLfloat * val
Definition: glext.h:7180
static unsigned(__cdecl *hash_bstr)(bstr_t s)
#define Ch(x, y, z)
Definition: sha2.c:141
static BOOL bCaseSensitive
Definition: systempage.cpp:56
#define _UNICODE
Definition: textw.c:5
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
Definition: wdfdevice.h:3534
#define _ttoi
Definition: xmlstorage.h:195

◆ CommandColor()

INT CommandColor ( LPTSTR  rest)

Definition at line 32 of file color.c.

33{
34 WORD wColor = 0x00;
35
36 /* The user asked for help */
37 if (_tcsncmp(rest, _T("/?"), 2) == 0)
38 {
40 return 0;
41 }
42
43 /* Let's prepare %ERRORLEVEL% */
44 nErrorLevel = 0;
45
46 /* No parameter: Set the default colors */
47 if (rest[0] == _T('\0'))
48 {
50 return 0;
51 }
52
53 /* The parameter is just one character: Set color text */
54 if (_tcslen(rest) == 1)
55 {
56 if ((rest[0] >= _T('0')) && (rest[0] <= _T('9')))
57 {
58 wColor = (WORD)_ttoi(rest);
59 }
60 else if ((rest[0] >= _T('a')) && (rest[0] <= _T('f')))
61 {
62 wColor = (WORD)(rest[0] + 10 - _T('a'));
63 }
64 else if ((rest[0] >= _T('A')) && (rest[0] <= _T('F')))
65 {
66 wColor = (WORD)(rest[0] + 10 - _T('A'));
67 }
68 else /* Invalid character */
69 {
71 nErrorLevel = 1;
72 return 1;
73 }
74 }
75 /* Color string: advanced choice: two-digits, "Color ON Color", "Foreground ON Background" */
76 else if (StringToColor(&wColor, &rest) == FALSE)
77 {
78 /* Invalid color string */
80 nErrorLevel = 1;
81 return 1;
82 }
83
84 TRACE("Color %02x\n", wColor);
85
86 /*
87 * Set the chosen color. Use also the following advanced flag:
88 * /-F to avoid changing already buffered foreground/background.
89 */
91 !_tcsstr(rest, _T("/-F")) && !_tcsstr(rest, _T("/-f"))) == FALSE)
92 {
93 /* Failed because foreground and background colors were the same */
95 nErrorLevel = 1;
96 return 1;
97 }
98
99 /* Return success */
100 return 0;
101}
WORD wDefColor
Definition: cmd.c:180
BOOL StringToColor(LPWORD, LPTSTR *)
Definition: strtoclr.c:255
WORD wColor
BOOL ConSetScreenColor(HANDLE hOutput, WORD wColor, BOOL bFill)
Definition: console.c:302
#define STRING_COLOR_HELP1
Definition: resource.h:92
#define STRING_COLOR_ERROR1
Definition: resource.h:32

◆ CommandDelay()

INT CommandDelay ( LPTSTR  param)

Definition at line 17 of file delay.c.

18{
19 DWORD val;
20 DWORD mul=1000;
21
22 if (_tcsncmp (param, _T("/?"), 2) == 0)
23 {
25 return 0;
26 }
27
28 nErrorLevel = 0;
29
30 if (*param==0)
31 {
33 return 1;
34 }
35
36 if (_tcsnicmp(param,_T("/m"),2) == 0)
37 {
38 mul = 1;
39 param += 2;
40 }
41
42 val = _ttoi(param);
43 Sleep(val * mul);
44
45 return 0;
46}
#define STRING_DELAY_HELP
Definition: resource.h:104
#define mul(aa, bb)
Definition: mvAesAlg.c:25
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790

◆ CommandDelete()

INT CommandDelete ( LPTSTR  param)

Definition at line 358 of file del.c.

359{
360 /*cmd is the command that was given, in this case it will always be "del" or "delete"
361 param is whatever is given after the command*/
362
363 LPTSTR *arg = NULL;
364 INT args;
365 INT i;
366 INT nEvalArgs = 0; /* number of evaluated arguments */
367 DWORD dwFlags = 0;
368 DWORD dwAttrFlags = 0;
369 DWORD dwFiles = 0;
370 LONG ch;
371 TCHAR szOriginalArg[MAX_PATH];
372
373 /*checks the first two chars of param to see if it is /?
374 this however allows the following command to not show help
375 "del frog.txt /?" */
376
377 if (!StringsLoaded)
378 {
379 LoadStrings();
380 }
381
382 if (!_tcsncmp (param, _T("/?"), 2))
383 {
385 return 0;
386 }
387
388 nErrorLevel = 0;
389
390 arg = split (param, &args, FALSE, FALSE);
391
392 if (args == 0)
393 {
394 /* only command given */
396 freep (arg);
397 return 1;
398 }
399 /* check for options anywhere in command line */
400 for (i = 0; i < args; i++)
401 {
402 if (*arg[i] == _T('/'))
403 {
404 /*found a command, but check to make sure it has something after it*/
405 if (_tcslen (arg[i]) >= 2)
406 {
407 ch = _totupper (arg[i][1]);
408 if (ch == _T('N'))
409 {
411 }
412 else if (ch == _T('P'))
413 {
415 }
416 else if (ch == _T('Q'))
417 {
419 }
420 else if (ch == _T('F'))
421 {
423 }
424 else if (ch == _T('S'))
425 {
427 }
428 else if (ch == _T('T'))
429 {
431 }
432 else if (ch == _T('W'))
433 {
434 dwFlags |= DEL_WIPE;
435 }
436 else if (ch == _T('Y'))
437 {
438 dwFlags |= DEL_YES;
439 }
440 else if (ch == _T('A'))
441 {
443 /*the proper syntax for /A has a min of 4 chars
444 i.e. /A:R or /A:-H */
445 if (_tcslen (arg[i]) < 4)
446 {
448 return 0;
449 }
450 ch = _totupper (arg[i][3]);
451 if (_tcslen (arg[i]) == 4)
452 {
453 if (ch == _T('A'))
454 {
455 dwAttrFlags |= ATTR_ARCHIVE;
456 }
457 if (ch == _T('H'))
458 {
459 dwAttrFlags |= ATTR_HIDDEN;
460 }
461 if (ch == _T('S'))
462 {
463 dwAttrFlags |= ATTR_SYSTEM;
464 }
465 if (ch == _T('R'))
466 {
467 dwAttrFlags |= ATTR_READ_ONLY;
468 }
469 }
470 if (_tcslen (arg[i]) == 5)
471 {
472 if (ch == _T('-'))
473 {
474 ch = _totupper (arg[i][4]);
475 if (ch == _T('A'))
476 {
477 dwAttrFlags |= ATTR_N_ARCHIVE;
478 }
479 if (ch == _T('H'))
480 {
481 dwAttrFlags |= ATTR_N_HIDDEN;
482 }
483 if (ch == _T('S'))
484 {
485 dwAttrFlags |= ATTR_N_SYSTEM;
486 }
487 if (ch == _T('R'))
488 {
489 dwAttrFlags |= ATTR_N_READ_ONLY;
490 }
491 }
492 }
493 }
494 }
495
496 nEvalArgs++;
497 }
498 }
499
500 /* there are only options on the command line --> error!!!
501 there is the same number of args as there is flags, so none of the args were filenames*/
502 if (args == nEvalArgs)
503 {
505 freep (arg);
506 return 1;
507 }
508
509 /* keep quiet within batch files */
510 if (bc != NULL) dwFlags |= DEL_QUIET;
511
512 /* check for filenames anywhere in command line */
513 for (i = 0; i < args && !(dwFiles & 0x80000000); i++)
514 {
515 /*this checks to see if it is a flag; if it isn't, we assume it is a file name*/
516 if ((*arg[i] == _T('/')) || (*arg[i] == _T('-')))
517 continue;
518
519 /* We want to make a copies of the argument */
520 if (_tcslen(arg[i]) == 2 && arg[i][1] == _T(':'))
521 {
522 /* Check for C: D: ... */
523 GetRootPath(arg[i], szOriginalArg, MAX_PATH);
524 }
525 else
526 {
527 _tcscpy(szOriginalArg,arg[i]);
528 }
529 dwFiles += ProcessDirectory(szOriginalArg, &dwFlags, dwAttrFlags);
530 }
531
532 freep (arg);
533
534 /*Based on MS cmd, we only tell what files are being deleted when /S is used */
535 if (dwFlags & DEL_TOTAL)
536 {
537 dwFiles &= 0x7fffffff;
538 if (dwFiles < 2)
539 {
541 }
542 else
543 {
545 }
546 }
547
548 return 0;
549}
#define STRING_DEL_HELP3
Definition: resource.h:102
#define STRING_DEL_HELP1
Definition: resource.h:100
#define STRING_DEL_HELP4
Definition: resource.h:103
@ DEL_PROMPT
Definition: del.c:57
@ DEL_QUIET
Definition: del.c:58
@ DEL_SUBDIR
Definition: del.c:59
@ DEL_TOTAL
Definition: del.c:60
@ DEL_ATTRIBUTES
Definition: del.c:55
@ DEL_YES
Definition: del.c:63
@ DEL_FORCE
Definition: del.c:64
@ DEL_NOTHING
Definition: del.c:56
@ DEL_WIPE
Definition: del.c:61
@ ATTR_SYSTEM
Definition: del.c:71
@ ATTR_N_ARCHIVE
Definition: del.c:73
@ ATTR_N_READ_ONLY
Definition: del.c:76
@ ATTR_READ_ONLY
Definition: del.c:72
@ ATTR_N_SYSTEM
Definition: del.c:75
@ ATTR_HIDDEN
Definition: del.c:70
@ ATTR_N_HIDDEN
Definition: del.c:74
@ ATTR_ARCHIVE
Definition: del.c:69
static VOID LoadStrings(VOID)
Definition: del.c:84
static DWORD ProcessDirectory(LPTSTR FileName, DWORD *dwFlags, DWORD dwAttrFlags)
Definition: del.c:279
static BOOLEAN StringsLoaded
Definition: del.c:82
long LONG
Definition: pedump.c:60

◆ CommandDir()

INT CommandDir ( LPTSTR  rest)

Definition at line 1843 of file dir.c.

1844{
1845 TCHAR dircmd[MAX_PATH]; /* A variable to store the DIRCMD environment variable */
1846 TCHAR prev_volume[MAX_PATH];
1847 TCHAR szFullPath[MAX_PATH];
1848 LPTSTR* params = NULL;
1849 LPTSTR pszFilePart;
1850 TCHAR cPathSep;
1851 INT entries = 0;
1852 UINT loop = 0;
1853 DIRSWITCHFLAGS stFlags;
1854 INT ret = 1;
1855 BOOL ChangedVolume;
1856
1857 /* Initialize Switch Flags < Default switches are set here! > */
1858 stFlags.b4Digit = TRUE;
1859 stFlags.bBareFormat = FALSE;
1860 stFlags.bDataStreams = FALSE;
1861 stFlags.bLowerCase = FALSE;
1862 stFlags.bNewLongList = TRUE;
1863 stFlags.bPause = FALSE;
1864 stFlags.bRecursive = FALSE;
1865 stFlags.bShortName = FALSE;
1866 stFlags.bTSeparator = TRUE;
1867 stFlags.bUser = FALSE;
1868 stFlags.bWideList = FALSE;
1869 stFlags.bWideListColSort = FALSE;
1870 stFlags.stTimeField.eTimeField = TF_MODIFIEDDATE;
1871 stFlags.stAttribs.dwAttribMask = FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM;
1872 stFlags.stAttribs.dwAttribVal = 0L;
1873 stFlags.stOrderBy.sCriteriaCount = 0;
1874
1875 nErrorLevel = 0;
1876
1877 /* Read the parameters from the DIRCMD environment variable */
1878 if (GetEnvironmentVariable (_T("DIRCMD"), dircmd, ARRAYSIZE(dircmd)))
1879 {
1880 if (!DirReadParam(dircmd, &params, &entries, &stFlags))
1881 {
1882 nErrorLevel = 1;
1883 goto cleanup;
1884 }
1885 }
1886
1887 /* Read the parameters */
1888 if (!DirReadParam(rest, &params, &entries, &stFlags) || CheckCtrlBreak(BREAK_INPUT))
1889 {
1890 nErrorLevel = 1;
1891 goto cleanup;
1892 }
1893
1894 /* Default to current directory */
1895 if (entries == 0)
1896 {
1897 if (!add_entry(&entries, &params, _T("*")))
1898 {
1899 nErrorLevel = 1;
1900 goto cleanup;
1901 }
1902 }
1903
1904 prev_volume[0] = _T('\0');
1905
1906 /* Reset paging state */
1907 if (stFlags.bPause)
1909
1910 for (loop = 0; loop < (UINT)entries; loop++)
1911 {
1913 {
1914 nErrorLevel = 1;
1915 goto cleanup;
1916 }
1917
1918 recurse_dir_cnt = 0L;
1920 recurse_bytes = 0;
1921
1922 /* <Debug :>
1923 Uncomment this to show the final state of switch flags*/
1924 {
1925 int i;
1926 TRACE("Attributes mask/value %x/%x\n",stFlags.stAttribs.dwAttribMask,stFlags.stAttribs.dwAttribVal);
1927 TRACE("(B) Bare format : %i\n", stFlags.bBareFormat);
1928 TRACE("(C) Thousand : %i\n", stFlags.bTSeparator);
1929 TRACE("(W) Wide list : %i\n", stFlags.bWideList);
1930 TRACE("(D) Wide list sort by column : %i\n", stFlags.bWideListColSort);
1931 TRACE("(L) Lowercase : %i\n", stFlags.bLowerCase);
1932 TRACE("(N) New : %i\n", stFlags.bNewLongList);
1933 TRACE("(O) Order : %i\n", stFlags.stOrderBy.sCriteriaCount);
1934 for (i =0;i<stFlags.stOrderBy.sCriteriaCount;i++)
1935 TRACE(" Order Criteria [%i]: %i (Reversed: %i)\n",i, stFlags.stOrderBy.eCriteria[i], stFlags.stOrderBy.bCriteriaRev[i]);
1936 TRACE("(P) Pause : %i\n", stFlags.bPause);
1937 TRACE("(Q) Owner : %i\n", stFlags.bUser);
1938 TRACE("(R) Data stream : %i\n", stFlags.bDataStreams);
1939 TRACE("(S) Recursive : %i\n", stFlags.bRecursive);
1940 TRACE("(T) Time field : %i\n", stFlags.stTimeField.eTimeField);
1941 TRACE("(X) Short names : %i\n", stFlags.bShortName);
1942 TRACE("Parameter : %s\n", debugstr_aw(params[loop]));
1943 }
1944
1945 /* Print the drive header if the volume changed */
1946 ChangedVolume = TRUE;
1947
1948 if (!stFlags.bBareFormat &&
1949 GetVolumePathName(params[loop], szFullPath, ARRAYSIZE(szFullPath)))
1950 {
1951 if (!_tcscmp(szFullPath, prev_volume))
1952 ChangedVolume = FALSE;
1953 else
1954 _tcscpy(prev_volume, szFullPath);
1955 }
1956
1957 /* Resolve the pattern */
1958 ResolvePattern(params[loop], ARRAYSIZE(szFullPath), szFullPath, &pszFilePart);
1959
1960 /* Print the header */
1961 cPathSep = pszFilePart[-1];
1962 pszFilePart[-1] = _T('\0'); /* Truncate to directory name only */
1963 if (ChangedVolume && !stFlags.bBareFormat &&
1964 !PrintDirectoryHeader(szFullPath, &stFlags))
1965 {
1966 nErrorLevel = 1;
1967 goto cleanup;
1968 }
1969 pszFilePart[-1] = cPathSep;
1970
1971 /* Perform the actual directory listing */
1972 if (DirList(szFullPath, pszFilePart, &stFlags) != 0)
1973 {
1974 nErrorLevel = 1;
1975 goto cleanup;
1976 }
1977
1978 /* Print the footer */
1979 pszFilePart[-1] = _T('\0'); /* Truncate to directory name only */
1980 PrintSummary(szFullPath,
1984 &stFlags,
1985 TRUE);
1986 }
1987
1988 ret = 0;
1989
1990cleanup:
1991 freep(params);
1992
1993 return ret;
1994}
static INT PrintSummary(LPCTSTR szPath, ULONG ulFiles, ULONG ulDirs, ULONGLONG u64Bytes, LPDIRSWITCHFLAGS lpFlags, BOOL TotalSummary)
Definition: dir.c:771
static ULONG recurse_dir_cnt
Definition: dir.c:221
@ TF_MODIFIEDDATE
Definition: dir.c:152
static INT DirList(IN OUT LPTSTR szFullPath, IN LPTSTR pszFilePart, LPDIRSWITCHFLAGS lpFlags)
Definition: dir.c:1365
static ULONGLONG recurse_bytes
Definition: dir.c:223
static BOOL DirReadParam(LPTSTR Line, LPTSTR **params, LPINT entries, LPDIRSWITCHFLAGS lpFlags)
Definition: dir.c:265
static VOID ResolvePattern(IN LPTSTR pszPattern, IN DWORD nBufferLength, OUT LPTSTR pszFullPath, OUT LPTSTR *ppszPatternPart OPTIONAL)
Definition: dir.c:1618
static BOOL PrintDirectoryHeader(LPCTSTR szPath, LPDIRSWITCHFLAGS lpFlags)
Definition: dir.c:598
static ULONG recurse_file_cnt
Definition: dir.c:222
BOOL add_entry(LPINT ac, LPSTR **arg, LPCSTR entry)
Definition: cmdcons.c:132
static void cleanup(void)
Definition: main.c:1335
GLenum const GLfloat * params
Definition: glext.h:5645
#define L(x)
Definition: ntvdm.h:50
BOOL bDataStreams
Definition: dir.c:180
struct _DirSwitchesFlags::@72 stOrderBy
BOOL bRecursive
Definition: dir.c:177
BOOL bNewLongList
Definition: dir.c:174
BOOL bWideListColSort
Definition: dir.c:172
BOOL bBareFormat
Definition: dir.c:169
BOOL bWideList
Definition: dir.c:171
BOOL b4Digit
Definition: dir.c:179
struct _DirSwitchesFlags::@73 stTimeField
BOOL bLowerCase
Definition: dir.c:173
struct _DirSwitchesFlags::@71 stAttribs
BOOL bShortName
Definition: dir.c:178
BOOL bPause
Definition: dir.c:175
BOOL bUser
Definition: dir.c:176
BOOL bTSeparator
Definition: dir.c:170
#define GetVolumePathName
Definition: winbase.h:3790

◆ CommandDirs()

INT CommandDirs ( LPTSTR  rest)

Definition at line 154 of file dirstack.c.

155{
156 LPDIRENTRY lpDir;
157
158 if (!_tcsncmp(rest, _T("/?"), 2))
159 {
161 return 0;
162 }
163
164 nErrorLevel = 0;
165
166 lpDir = lpStackBottom;
167
168 if (lpDir == NULL)
169 {
171 return 0;
172 }
173
174 while (lpDir != NULL)
175 {
176 ConOutPuts(lpDir->szPath);
177 lpDir = lpDir->prev;
178 }
179
180 return 0;
181}
#define STRING_DIRSTACK_HELP4
Definition: resource.h:118
#define STRING_DIRSTACK_HELP3
Definition: resource.h:117
static LPDIRENTRY lpStackBottom
Definition: dirstack.c:31
TCHAR szPath[1]
Definition: dirstack.c:25
struct tagDIRENTRY * prev
Definition: dirstack.c:23

◆ CommandEcho()

INT CommandEcho ( LPTSTR  param)

Definition at line 65 of file echo.c.

66{
67 LPTSTR p1;
68
69 TRACE ("CommandEcho: '%s'\n", debugstr_aw(param));
70
71 /* skip all spaces for the check of '/?', 'ON' and 'OFF' */
72 p1 = param;
73 while(_istspace(*p1))
74 p1++;
75
76 if (!_tcsncmp (p1, _T("/?"), 2))
77 {
79 return 0;
80 }
81
83 {
84 /* skip the first character */
85 ConOutPuts(param + 1);
86 ConOutChar(_T('\n'));
87 }
88 return 0;
89}
BOOL bEcho
Definition: batch.c:73
#define STRING_ECHO_HELP5
Definition: resource.h:124
#define STRING_ECHO_HELP4
Definition: resource.h:123
BOOL OnOffCommand(LPTSTR param, LPBOOL flag, INT message)
Definition: echo.c:32

◆ CommandEchoerr()

INT CommandEchoerr ( LPTSTR  param)

Definition at line 106 of file echo.c.

107{
108 TRACE ("CommandEchoerr: '%s'\n", debugstr_aw(param));
109
110 if (!_tcsncmp (param, _T("/?"), 2))
111 {
113 return 0;
114 }
115
117 return 0;
118}
#define STRING_ECHO_HELP2
Definition: resource.h:121

◆ CommandEchos()

INT CommandEchos ( LPTSTR  param)

Definition at line 91 of file echo.c.

92{
93 TRACE ("CommandEchos: '%s'\n", debugstr_aw(param));
94
95 if (!_tcsncmp (param, _T("/?"), 2))
96 {
98 return 0;
99 }
100
101 ConOutPrintf (_T("%s"), param);
102 return 0;
103}
#define STRING_ECHO_HELP1
Definition: resource.h:120

◆ CommandEchoserr()

INT CommandEchoserr ( LPTSTR  param)

Definition at line 121 of file echo.c.

122{
123 TRACE ("CommandEchoserr: '%s'\n", debugstr_aw(param));
124
125 if (!_tcsncmp (param, _T("/?"), 2))
126 {
128 return 0;
129 }
130
131 ConErrPrintf (_T("%s"), param);
132 return 0;
133}
#define STRING_ECHO_HELP3
Definition: resource.h:122

◆ CommandExit()

INT CommandExit ( LPTSTR  param)

Definition at line 621 of file internal.c.

622{
623 if (!_tcsncmp(param, _T("/?"), 2))
624 {
626
627 /* Just make sure we don't exit */
628 bExit = FALSE;
629 return 0;
630 }
631
632 if (_tcsnicmp(param, _T("/B"), 2) == 0)
633 {
634 param += 2;
635
636 /*
637 * If a current batch file is running, exit it,
638 * otherwise exit this command interpreter instance.
639 */
640 if (bc)
641 {
642 /* Windows' CMD compatibility: Use GOTO :EOF */
643 TCHAR EofLabel[] = _T(":EOF");
644
645#ifdef SUPPORT_EXIT_B_NO_EXTENSIONS
646 /*
647 * Temporarily enable extensions so as to support :EOF.
648 *
649 * Our GOTO implementation ensures that, when extensions are
650 * enabled and the label is ':EOF', no immediate change of batch
651 * context (done e.g. via ExitBatch() calls) is performed.
652 * This will therefore ensure that we do not spoil the extensions
653 * state when we restore it below.
654 */
655 BOOL bOldEnableExtensions = bEnableExtensions;
657#endif
658
659 cmd_goto(EofLabel);
660
661#ifdef SUPPORT_EXIT_B_NO_EXTENSIONS
662 /* Restore the original state of the extensions */
663 bEnableExtensions = bOldEnableExtensions;
664#endif
665 }
666 else
667 {
668 bExit = TRUE;
669 }
670 }
671 else
672 {
673 /* Exit this command interpreter instance */
674 bExit = TRUE;
675 }
676
677 /* Search for an optional exit code */
678 while (_istspace(*param))
679 ++param;
680
681 /* Set the errorlevel to the exit code */
682 if (_istdigit(*param))
683 {
685 // if (fSingleCommand == 1) return nErrorLevel;
686 }
687
688 return (bExit ? nErrorLevel : 0);
689}
BOOL bExit
Definition: cmd.c:152
INT cmd_goto(LPTSTR)
Definition: goto.c:36
#define STRING_EXIT_HELP
Definition: resource.h:126
#define _istdigit
Definition: tchar.h:1494

◆ CommandFree()

INT CommandFree ( LPTSTR  param)

Definition at line 86 of file free.c.

87{
88 LPTSTR szParam;
89 TCHAR szDefPath[MAX_PATH];
90 INT argc, i;
91 LPTSTR *arg;
92
93 if (!_tcsncmp (param, _T("/?"), 2))
94 {
96 return 0;
97 }
98
99 if (!param || *param == _T('\0'))
100 {
101 GetCurrentDirectory (MAX_PATH, szDefPath);
102 szDefPath[2] = _T('\0');
103 szParam = szDefPath;
104 }
105 else
106 szParam = param;
107
108 arg = split (szParam, &argc, FALSE, FALSE);
109
110 for (i = 0; i < argc; i++)
112
113 freep (arg);
114
115 return 0;
116}
#define STRING_FREE_HELP2
Definition: resource.h:131
static VOID PrintDiskInfo(LPTSTR szDisk)
Definition: free.c:19

◆ CommandMemory()

INT CommandMemory ( LPTSTR  param)

Definition at line 18 of file memory.c.

19{
20 MEMORYSTATUSEX msex;
21 TCHAR szMemoryLoad[20];
22 TCHAR szTotalPhys[40];
23 TCHAR szAvailPhys[40];
24 TCHAR szTotalPageFile[40];
25 TCHAR szAvailPageFile[40];
26 TCHAR szTotalVirtual[40];
27 TCHAR szAvailVirtual[40];
28 BOOL (WINAPI *GlobalMemoryStatusEx)(LPMEMORYSTATUSEX);
29
30 if (!_tcsncmp (param, _T("/?"), 2))
31 {
33 return 0;
34 }
35
37 = (BOOL (WINAPI *)(LPMEMORYSTATUSEX))GetProcAddress(GetModuleHandle(_T("KERNEL32")), "GlobalMemoryStatusEx");
39 {
40 msex.dwLength = sizeof(MEMORYSTATUSEX);
42 }
43 else
44 {
45 MEMORYSTATUS ms;
46 ms.dwLength = sizeof(MEMORYSTATUS);
48 msex.dwMemoryLoad = ms.dwMemoryLoad;
49 msex.ullTotalPhys = ms.dwTotalPhys;
50 msex.ullAvailPhys = ms.dwAvailPhys;
51 msex.ullTotalPageFile = ms.dwTotalPageFile;
52 msex.ullAvailPageFile = ms.dwAvailPageFile;
53 msex.ullTotalVirtual = ms.dwTotalVirtual;
54 msex.ullAvailVirtual = ms.dwAvailVirtual;
55 }
56
57 ConvertULargeInteger(msex.dwMemoryLoad, szMemoryLoad, 20, FALSE);
58 ConvertULargeInteger(msex.ullTotalPhys, szTotalPhys, 40, TRUE);
59 ConvertULargeInteger(msex.ullAvailPhys, szAvailPhys, 40, TRUE);
60 ConvertULargeInteger(msex.ullTotalPageFile, szTotalPageFile, 40, TRUE);
61 ConvertULargeInteger(msex.ullAvailPageFile, szAvailPageFile, 40, TRUE);
62 ConvertULargeInteger(msex.ullTotalVirtual, szTotalVirtual, 40, TRUE);
63 ConvertULargeInteger(msex.ullAvailVirtual, szAvailVirtual, 40, TRUE);
64
66 szMemoryLoad, szTotalPhys, szAvailPhys, szTotalPageFile,
67 szAvailPageFile, szTotalVirtual, szAvailVirtual);
68
69 return 0;
70}
INT ConvertULargeInteger(ULONGLONG num, LPTSTR des, UINT len, BOOL bPutSeparator)
Definition: cmd.c:189
#define STRING_MEMORY_HELP1
Definition: resource.h:141
#define STRING_MEMORY_HELP2
Definition: resource.h:142
VOID NTAPI GlobalMemoryStatus(LPMEMORYSTATUS lpBuffer)
Definition: heapmem.c:1365
BOOL NTAPI GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpBuffer)
Definition: heapmem.c:1272
SIZE_T dwTotalPhys
Definition: winbase.h:1218
DWORD dwLength
Definition: winbase.h:1216
DWORD dwMemoryLoad
Definition: winbase.h:1217
SIZE_T dwAvailPageFile
Definition: winbase.h:1221
SIZE_T dwAvailVirtual
Definition: winbase.h:1223
SIZE_T dwAvailPhys
Definition: winbase.h:1219
SIZE_T dwTotalPageFile
Definition: winbase.h:1220
SIZE_T dwTotalVirtual
Definition: winbase.h:1222
struct _MEMORYSTATUS MEMORYSTATUS

◆ CommandMsgbox()

INT CommandMsgbox ( LPTSTR  )

◆ CommandPopd()

INT CommandPopd ( LPTSTR  rest)

Definition at line 132 of file dirstack.c.

133{
134 INT ret = 0;
135 if (!_tcsncmp(rest, _T("/?"), 2))
136 {
138 return 0;
139 }
140
141 if (nStackDepth == 0)
142 return 1;
143
144 ret = _tchdir(lpStackTop->szPath) != 0;
145 PopDirectory ();
146
147 return ret;
148}
#define STRING_DIRSTACK_HELP2
Definition: resource.h:116
static VOID PopDirectory(VOID)
Definition: dirstack.c:62
static LPDIRENTRY lpStackTop
Definition: dirstack.c:30
static INT nStackDepth
Definition: dirstack.c:29

◆ CommandPushd()

INT CommandPushd ( LPTSTR  rest)

Definition at line 107 of file dirstack.c.

108{
109 TCHAR curPath[MAX_PATH];
110
111 if (!_tcsncmp (rest, _T("/?"), 2))
112 {
114 return 0;
115 }
116
117 GetCurrentDirectory (MAX_PATH, curPath);
118
119 if (rest[0] != _T('\0'))
120 {
121 if (!SetRootPath(NULL, rest))
122 return 1;
123 }
124
125 return PushDirectory(curPath);
126}
BOOL SetRootPath(TCHAR *oldpath, TCHAR *InPath)
Definition: internal.c:182
#define STRING_DIRSTACK_HELP1
Definition: resource.h:115
static INT PushDirectory(LPTSTR pszPath)
Definition: dirstack.c:35

◆ CommandRem()

INT CommandRem ( LPTSTR  param)

Definition at line 695 of file internal.c.

696{
697 if (_tcsstr(param, _T("/?")) == param)
698 {
700 }
701
702 return 0;
703}
#define STRING_REM_HELP
Definition: resource.h:159

◆ CommandScreen()

INT CommandScreen ( LPTSTR  param)

Definition at line 18 of file screen.c.

19{
20 SHORT x, y;
22 BOOL bSkipText = FALSE;
23
24 if (_tcsncmp(param, _T("/?"), 2) == 0)
25 {
27 return 0;
28 }
29
30 nErrorLevel = 0;
31
32 /* Retrieve the screen dimensions */
34
35 /* Get row */
36 while (_istspace(*param))
37 param++;
38
39 if (!*param)
40 {
42 return 1;
43 }
44
45 y = _ttoi(param);
46 if (y < 0 || y > (maxy-1))
47 {
49 return 1;
50 }
51
52 /* Get column */
53 if (!(param = _tcschr(param, _T(' '))))
54 {
56 return 1;
57 }
58
59 while (_istspace(*param))
60 param++;
61
62 if (!*param)
63 {
65 return 1;
66 }
67
68 x = _ttoi(param);
69 if (x < 0 || x > (maxx-1))
70 {
72 return 1;
73 }
74
75 /* Get text */
76 if (!(param = _tcschr(param, _T(' '))))
77 {
78 bSkipText = TRUE;
79 }
80 else
81 {
82 while (_istspace(*param))
83 param++;
84
85 if (!*param)
86 bSkipText = TRUE;
87 }
88
90
91 if (bSkipText)
92 x = 0;
93
94 SetCursorXY(x, y);
95
96 if (!bSkipText)
98
99 return 0;
100}
BOOL bIgnoreEcho
Definition: cmd.c:155
VOID SetCursorXY(SHORT x, SHORT y)
Definition: console.c:191
VOID GetScreenSize(PSHORT maxx, PSHORT maxy)
Definition: console.c:236
#define STRING_SCREEN_HELP
Definition: resource.h:167
#define STRING_SCREEN_COL
Definition: resource.h:211
#define STRING_SCREEN_ROW
Definition: resource.h:212
SHORT maxx
Definition: cmdinput.c:115
SHORT maxy
Definition: cmdinput.c:116
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
short SHORT
Definition: pedump.c:59

◆ CommandShowCommands()

INT CommandShowCommands ( LPTSTR  param)

Definition at line 707 of file internal.c.

708{
710 return 0;
711}
VOID PrintCommandList(VOID)
Definition: cmdtable.c:234

◆ CommandTimer()

INT CommandTimer ( LPTSTR  param)

Definition at line 59 of file timer.c.

60{
61 // all timers are kept
62 static DWORD clksT[10];
63
64 // timers status
65 // set all the clocks off by default
66 static BOOL clksS[10]={FALSE,FALSE,FALSE,FALSE,
68
69 // TRUE if /S in command line
70 BOOL bS = FALSE;
71
72 // avoid to set clk_n more than once
73 BOOL bCanNSet = TRUE;
74
75 INT NewClkStatus = NCS_NOT_SPECIFIED;
76
77 // the clock number specified on the command line
78 // 1 by default
79 INT clk_n=1;
80
81 // output format
82 INT iFormat=1;
83
84
85 // command line parsing variables
86 INT argc;
87 LPTSTR *p;
88
89 INT i;
90
91 if (_tcsncmp (param, _T("/?"), 2) == 0)
92 {
94 return 0;
95 }
96
97 nErrorLevel = 0;
98
99 p = split (param, &argc, FALSE, FALSE);
100
101 //read options
102 for (i = 0; i < argc; i++)
103 {
104 //set timer on
105 if (!(_tcsicmp(&p[i][0],_T("on"))) && NewClkStatus == NCS_NOT_SPECIFIED)
106 {
107 NewClkStatus = NCS_ON;
108 continue;
109 }
110
111 //set timer off
112 if (!(_tcsicmp(&p[i][0],_T("off"))) && NewClkStatus == NCS_NOT_SPECIFIED)
113 {
114 NewClkStatus = NCS_OFF;
115 continue;
116 }
117
118 // other options
119 if (p[i][0] == _T('/'))
120 {
121 // set timer number
122 if (_istdigit(p[i][1]) && bCanNSet)
123 {
124 clk_n = p[i][1] - _T('0');
125 bCanNSet = FALSE;
126 continue;
127 }
128
129 // set s(plit) option
130 if (_totupper(p[i][1]) == _T('S'))
131 {
132 bS = TRUE;
133 continue;
134 }
135
136 // specify format
137 if (_totupper(p[i][1]) == _T('F'))
138 {
139 iFormat = p[i][2] - _T('0');
140 continue;
141 }
142 }
143 }
144
145 // do stuff (start/stop/read timer)
146 if (NewClkStatus == NCS_ON)
147 {
149 cS=TRUE;
150
151 ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
153 freep(p);
154 return 0;
155 }
156
157 if (bS)
158 {
159 if (cS)
160 {
161 ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
162 ConOutPrintf(_T("%s\n"), GetTimeString());
164 freep(p);
165 return 0;
166 }
167
169 cS=TRUE;
170 ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
172 freep(p);
173 return 0;
174 }
175
176 if (NewClkStatus == NCS_NOT_SPECIFIED)
177 {
178 if (cS)
179 {
180 cS=FALSE;
181 ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
182 ConOutPrintf(_T("%s\n"), GetTimeString());
184 freep(p);
185 return 0;
186 }
187
189 cS=TRUE;
190 ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
192 freep(p);
193 return 0;
194 }
195
196
197 if (NewClkStatus == NCS_OFF)
198 {
199 if (cS)
200 {
201 cS=FALSE;
202 ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
203 ConOutPrintf(_T("%s\n"), GetTimeString());
205 freep(p);
206 return 0;
207 }
208 ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF"));
210 freep(p);
211 return 0;
212 }
213
214 freep(p);
215 return 0;
216}
TCHAR cTimeSeparator
Definition: locale.c:17
TCHAR cDecimalSeparator
Definition: locale.c:19
#define STRING_TIMER_HELP3
Definition: resource.h:182
#define STRING_TIMER_TIME
Definition: resource.h:213
#define NCS_OFF
Definition: timer.c:17
#define NCS_NOT_SPECIFIED
Definition: timer.c:15
#define cS
Definition: timer.c:27
static VOID PrintElapsedTime(DWORD time, INT format)
Definition: timer.c:31
#define cT
Definition: timer.c:24
#define NCS_ON
Definition: timer.c:16
_In_ SIZEL _In_ ULONG iFormat
Definition: winddi.h:3468

◆ CommandWindow()

INT CommandWindow ( LPTSTR  )

◆ ConvertULargeInteger()

INT ConvertULargeInteger ( ULONGLONG  num,
LPTSTR  des,
UINT  len,
BOOL  bPutSeparator 
)

Definition at line 189 of file cmd.c.

190{
191 TCHAR temp[39]; /* maximum length with nNumberGroups == 1 */
192 UINT n, iTarget;
193
194 if (len <= 1)
195 return 0;
196
197 n = 0;
198 iTarget = nNumberGroups;
199 if (!nNumberGroups)
200 bPutSeparator = FALSE;
201
202 do
203 {
204 if (iTarget == n && bPutSeparator)
205 {
206 iTarget += nNumberGroups + 1;
207 temp[38 - n++] = cThousandSeparator;
208 }
209 temp[38 - n++] = (TCHAR)(num % 10) + _T('0');
210 num /= 10;
211 } while (num > 0);
212 if (n > len-1)
213 n = len-1;
214
215 memcpy(des, temp + 39 - n, n * sizeof(TCHAR));
216 des[n] = _T('\0');
217
218 return n;
219}
INT nNumberGroups
Definition: locale.c:22
TCHAR cThousandSeparator
Definition: locale.c:18
static const WCHAR des[]
Definition: oid.c:1212
GLdouble n
Definition: glext.h:7729
GLuint GLuint num
Definition: glext.h:9618
GLenum GLsizei len
Definition: glext.h:6722
static calc_node_t temp
Definition: rpn_ieee.c:38

Referenced by CommandMemory(), DirPrintNewList(), DirPrintOldList(), PrintDiskInfo(), and PrintSummary().

◆ DestroyDirectoryStack()

VOID DestroyDirectoryStack ( VOID  )

Definition at line 91 of file dirstack.c.

92{
93 while (nStackDepth)
94 PopDirectory ();
95}

Referenced by Cleanup().

◆ DoCommand()

INT DoCommand ( LPTSTR  first,
LPTSTR  rest,
struct _PARSED_COMMAND Cmd 
)

Definition at line 557 of file cmd.c.

558{
559 TCHAR *com;
560 TCHAR *cp;
561 LPTSTR param; /* Pointer to command's parameters */
562 INT cl;
563 LPCOMMAND cmdptr;
564 BOOL nointernal = FALSE;
565 INT ret;
566
567 TRACE ("DoCommand: (\'%s\' \'%s\')\n", debugstr_aw(first), debugstr_aw(rest));
568
569 /* Full command line */
570 com = cmd_alloc((_tcslen(first) + _tcslen(rest) + 2) * sizeof(TCHAR));
571 if (com == NULL)
572 {
574 return 1;
575 }
576
577 /* If present in the first word, these characters end the name of an
578 * internal command and become the beginning of its parameters. */
579 cp = first + _tcscspn(first, _T("\t +,/;=[]"));
580
581 for (cl = 0; cl < (cp - first); cl++)
582 {
583 /* These characters do it too, but if one of them is present,
584 * then we check to see if the word is a file name and skip
585 * checking for internal commands if so.
586 * This allows running programs with names like "echo.exe" */
587 if (_tcschr(_T(".:\\"), first[cl]))
588 {
589 TCHAR tmp = *cp;
590 *cp = _T('\0');
591 nointernal = IsExistingFile(first);
592 *cp = tmp;
593 break;
594 }
595 }
596
597 /* Scan internal command table */
598 for (cmdptr = cmds; !nointernal && cmdptr->name; cmdptr++)
599 {
600 if (!_tcsnicmp(first, cmdptr->name, cl) && cmdptr->name[cl] == _T('\0'))
601 {
602 _tcscpy(com, first);
603 _tcscat(com, rest);
604 param = &com[cl];
605
606 /* Skip over whitespace to rest of line, exclude 'echo' command */
607 if (_tcsicmp(cmdptr->name, _T("echo")) != 0)
608 {
609 while (_istspace(*param))
610 param++;
611 }
612
613 /* Set the new console title */
614 SetConTitle(com);
615
616 ret = cmdptr->func(param);
617
618 /* Restore the original console title */
620
621 cmd_free(com);
622 return ret;
623 }
624 }
625
626 ret = Execute(com, first, rest, Cmd);
627 cmd_free(com);
628 return ret;
629}
COMMAND cmds[]
Definition: main.c:21
static INT Execute(LPTSTR Full, LPTSTR First, LPTSTR Rest, PARSED_COMMAND *Cmd)
Definition: cmd.c:347
static VOID SetConTitle(LPCTSTR pszTitle)
Definition: cmd.c:309
static VOID ResetConTitle(VOID)
Definition: cmd.c:329
#define _tcscspn
Definition: tchar.h:1407
POINT cp
Definition: magnifier.c:59
INT(* func)(PCONSOLE_STATE, LPSTR)
Definition: cmdcons.c:29
LPSTR name
Definition: cmdcons.c:27

Referenced by ExecuteCommand().

◆ DoDelayedExpansion()

PTSTR DoDelayedExpansion ( IN PCTSTR  Line)

Definition at line 1640 of file cmd.c.

1642{
1643 TCHAR Buf1[CMDLINE_LENGTH];
1644 TCHAR Buf2[CMDLINE_LENGTH];
1645 PTCHAR Src, Dst;
1646 PTCHAR DestEnd = Buf2 + CMDLINE_LENGTH - 1;
1647 size_t SrcIncLen, DestIncLen;
1648
1649 /* First, substitute FOR variables */
1650 if (!SubstituteForVars(Line, Buf1))
1651 return NULL;
1652
1653 if (!bDelayedExpansion || !_tcschr(Buf1, _T('!')))
1654 return cmd_dup(Buf1);
1655
1656 /*
1657 * Delayed substitutions are not actually completely the same as
1658 * immediate substitutions. In particular, it is possible to escape
1659 * the exclamation point using the escape caret.
1660 */
1661
1662 /*
1663 * Perform delayed expansion: expand variables around '!',
1664 * and reparse escape carets.
1665 */
1666
1667#define APPEND1(Char) \
1668do { \
1669 if (Dst >= DestEnd) \
1670 goto too_long; \
1671 *Dst++ = (Char); \
1672} while (0)
1673
1674 Src = Buf1;
1675 Dst = Buf2;
1676 while (*Src && (Src < &Buf1[CMDLINE_LENGTH]))
1677 {
1678 if (*Src == _T('^'))
1679 {
1680 ++Src;
1681 if (!*Src || !(Src < &Buf1[CMDLINE_LENGTH]))
1682 break;
1683
1684 APPEND1(*Src++);
1685 }
1686 else if (*Src == _T('!'))
1687 {
1688 if (!SubstituteVar(Src, &SrcIncLen, Dst, DestEnd, &DestIncLen, _T('!')))
1689 {
1690 return NULL; // Got an error during parsing.
1691 }
1692 else
1693 {
1694 Src += SrcIncLen;
1695 Dst += DestIncLen;
1696 }
1697 }
1698 else
1699 {
1700 APPEND1(*Src++);
1701 }
1702 continue;
1703 }
1704 APPEND1(_T('\0'));
1705
1706 return cmd_dup(Buf2);
1707
1708too_long:
1710 nErrorLevel = 9023;
1711 return NULL;
1712
1713#undef APPEND1
1714}
BOOL SubstituteForVars(IN PCTSTR Src, OUT PTSTR Dest)
Definition: cmd.c:1596
#define APPEND1(Char)
BOOL SubstituteVar(IN PCTSTR Src, OUT size_t *SrcIncLen, OUT PTCHAR Dest, IN PTCHAR DestEnd, OUT size_t *DestIncLen, IN TCHAR Delim)
Definition: cmd.c:1326
#define STRING_ALIAS_ERROR
Definition: resource.h:22
#define cmd_dup(str)
Definition: cmddbg.h:32
#define Dst
Definition: mesh.h:153
Definition: ncftp.h:79

Referenced by Batch(), ExecuteCommand(), ExecuteFor(), ExecuteIf(), and PerformRedirection().

◆ DumpCommand()

VOID DumpCommand ( IN PARSED_COMMAND Cmd,
IN ULONG  SpacePad 
)

Definition at line 1533 of file parser.c.

1536{
1537/*
1538 * This macro is like DumpCommand(Cmd, Pad);
1539 * but avoids an extra recursive level.
1540 * Note that it can be used ONLY for terminating commands!
1541 */
1542#define DUMP(Command, Pad) \
1543do { \
1544 Cmd = (Command); \
1545 SpacePad = (Pad); \
1546 goto dump; \
1547} while (0)
1548
1549 PARSED_COMMAND* Sub;
1550
1551dump:
1552 if (!Cmd)
1553 return;
1554
1555 /* Space padding */
1556 ConOutPrintf(_T("%*s"), SpacePad, _T(""));
1557
1558 switch (Cmd->Type)
1559 {
1560 case C_COMMAND:
1561 case C_REM:
1562 {
1563 /* Generic command name, and Type */
1564#ifndef MSCMD_ECHO_COMMAND_COMPAT
1565 ConOutPrintf(_T("Cmd: %s Type: %x"),
1566 Cmd->Command.First, Cmd->Type);
1567#else
1568 ConOutPrintf(_T("Cmd: %s Type: %x "),
1569 Cmd->Command.First, Cmd->Type);
1570#endif
1571 /* Arguments */
1572 if (Cmd->Command.Rest && *(Cmd->Command.Rest))
1573#ifndef MSCMD_ECHO_COMMAND_COMPAT
1574 ConOutPrintf(_T(" Args: `%s'"), Cmd->Command.Rest);
1575#else
1576 ConOutPrintf(_T("Args: `%s' "), Cmd->Command.Rest);
1577#endif
1578 /* Redirections */
1579 DumpRedir(Cmd->Redirections);
1580
1581 ConOutChar(_T('\n'));
1582 return;
1583 }
1584
1585 case C_QUIET:
1586 {
1587#ifndef MSCMD_ECHO_COMMAND_COMPAT
1588 ConOutChar(_T('@'));
1589#else
1590 ConOutPuts(_T("@ "));
1591#endif
1592 DumpRedir(Cmd->Redirections); // FIXME: Can we have leading redirections??
1593 ConOutChar(_T('\n'));
1594
1595 /*DumpCommand*/DUMP(Cmd->Subcommands, SpacePad + 2);
1596 return;
1597 }
1598
1599 case C_BLOCK:
1600 {
1601#ifndef MSCMD_ECHO_COMMAND_COMPAT
1602 ConOutChar(_T('('));
1603#else
1604 ConOutPuts(_T("( "));
1605#endif
1606 DumpRedir(Cmd->Redirections);
1607 ConOutChar(_T('\n'));
1608
1609 SpacePad += 2;
1610
1611 for (Sub = Cmd->Subcommands; Sub; Sub = Sub->Next)
1612 {
1613#if defined(MSCMD_ECHO_COMMAND_COMPAT) && defined(MSCMD_PARSER_BUGS)
1614 /*
1615 * We will emulate Windows' CMD handling of "CRLF" and "&" multi-command
1616 * enumeration within parenthesized command blocks.
1617 */
1618
1619 if (!Sub->Next)
1620 {
1621 DumpCommand(Sub, SpacePad);
1622 continue;
1623 }
1624
1625 if (Sub->Type != C_MULTI)
1626 {
1627 ConOutPrintf(_T("%*s"), SpacePad, _T(""));
1628 ConOutPuts(_T("CRLF \n"));
1629 DumpCommand(Sub, SpacePad);
1630 continue;
1631 }
1632
1633 /* Now, Sub->Type == C_MULTI */
1634
1635 Cmd = Sub;
1636
1637 ConOutPrintf(_T("%*s"), SpacePad, _T(""));
1638 ConOutPrintf(_T("%s \n"), OpString[Cmd->Type - C_OP_LOWEST]);
1639 // FIXME: Can we have redirections on these operator-type commands?
1640
1641 SpacePad += 2;
1642
1643 Cmd = Cmd->Subcommands;
1644 DumpCommand(Cmd, SpacePad);
1645 ConOutPrintf(_T("%*s"), SpacePad, _T(""));
1646 ConOutPuts(_T("CRLF \n"));
1647 DumpCommand(Cmd->Next, SpacePad);
1648
1649 // NOTE: Next commands will remain indented.
1650
1651#else
1652
1653 /*
1654 * If this command is followed by another one, first display "CRLF".
1655 * This also emulates the CRLF placement "bug" of Windows' CMD
1656 * for the last two commands.
1657 */
1658 if (Sub->Next)
1659 {
1660 ConOutPrintf(_T("%*s"), SpacePad, _T(""));
1661#ifndef MSCMD_ECHO_COMMAND_COMPAT
1662 ConOutPuts(_T("CRLF\n"));
1663#else
1664 ConOutPuts(_T("CRLF \n"));
1665#endif
1666 }
1667 DumpCommand(Sub, SpacePad);
1668
1669#endif // defined(MSCMD_ECHO_COMMAND_COMPAT) && defined(MSCMD_PARSER_BUGS)
1670 }
1671
1672 return;
1673 }
1674
1675 case C_MULTI:
1676 case C_OR:
1677 case C_AND:
1678 case C_PIPE:
1679 {
1680#ifndef MSCMD_ECHO_COMMAND_COMPAT
1681 ConOutPrintf(_T("%s\n"), OpString[Cmd->Type - C_OP_LOWEST]);
1682#else
1683 ConOutPrintf(_T("%s \n"), OpString[Cmd->Type - C_OP_LOWEST]);
1684#endif
1685 // FIXME: Can we have redirections on these operator-type commands?
1686
1687 SpacePad += 2;
1688
1689 Sub = Cmd->Subcommands;
1690 DumpCommand(Sub, SpacePad);
1691 /*DumpCommand*/DUMP(Sub->Next, SpacePad);
1692 return;
1693 }
1694
1695 case C_FOR:
1696 {
1697 ConOutPuts(_T("for"));
1698 /* NOTE: FOR cannot have leading redirections */
1699
1700 if (Cmd->For.Switches & FOR_DIRS) ConOutPuts(_T(" /D"));
1701 if (Cmd->For.Switches & FOR_F) ConOutPuts(_T(" /F"));
1702 if (Cmd->For.Switches & FOR_LOOP) ConOutPuts(_T(" /L"));
1703 if (Cmd->For.Switches & FOR_RECURSIVE) ConOutPuts(_T(" /R"));
1704 if (Cmd->For.Params)
1705 ConOutPrintf(_T(" %s"), Cmd->For.Params);
1706 ConOutPrintf(_T(" %%%c in (%s) do\n"), Cmd->For.Variable, Cmd->For.List);
1707 /*DumpCommand*/DUMP(Cmd->Subcommands, SpacePad + 2);
1708 return;
1709 }
1710
1711 case C_IF:
1712 {
1713 ConOutPuts(_T("if"));
1714 /* NOTE: IF cannot have leading redirections */
1715
1716 if (Cmd->If.Flags & IFFLAG_IGNORECASE)
1717 ConOutPuts(_T(" /I"));
1718
1719 ConOutChar(_T('\n'));
1720
1721 SpacePad += 2;
1722
1723 /*
1724 * Show the IF command condition as a command.
1725 * If it is negated, indent the command more.
1726 */
1727 if (Cmd->If.Flags & IFFLAG_NEGATE)
1728 {
1729 ConOutPrintf(_T("%*s"), SpacePad, _T(""));
1730 ConOutPuts(_T("not\n"));
1731 SpacePad += 2;
1732 }
1733
1734 ConOutPrintf(_T("%*s"), SpacePad, _T(""));
1735
1736 /*
1737 * Command name:
1738 * - Unary operator: its name is the command name, and its argument is the command argument.
1739 * - Binary operator: its LHS is the command name, its RHS is the command argument.
1740 *
1741 * Type:
1742 * Windows' CMD (Win2k3 / Win7-10) values are as follows:
1743 * CMDEXTVERSION Type: 0x32 / 0x34
1744 * ERRORLEVEL Type: 0x33 / 0x35
1745 * DEFINED Type: 0x34 / 0x36
1746 * EXIST Type: 0x35 / 0x37
1747 * == Type: 0x37 / 0x39 (String Comparison)
1748 *
1749 * For the following command:
1750 * NOT Type: 0x36 / 0x38
1751 * Windows only prints it without any type / redirection.
1752 *
1753 * For the following command:
1754 * EQU, NEQ, etc. Type: 0x38 / 0x3a (Generic Comparison)
1755 * Windows displays it as command of unknown type.
1756 */
1757#ifndef MSCMD_ECHO_COMMAND_COMPAT
1758 ConOutPrintf(_T("Cmd: %s Type: %x"),
1759 (Cmd->If.Operator <= IF_MAX_UNARY) ?
1760 IfOperatorString[Cmd->If.Operator] :
1761 Cmd->If.LeftArg,
1762 Cmd->If.Operator);
1763#else
1764 ConOutPrintf(_T("Cmd: %s Type: %x "),
1765 (Cmd->If.Operator <= IF_MAX_UNARY) ?
1766 IfOperatorString[Cmd->If.Operator] :
1767 Cmd->If.LeftArg,
1768 Cmd->If.Operator);
1769#endif
1770 /* Arguments */
1771#ifndef MSCMD_ECHO_COMMAND_COMPAT
1772 ConOutPrintf(_T(" Args: `%s'"), Cmd->If.RightArg);
1773#else
1774 ConOutPrintf(_T("Args: `%s' "), Cmd->If.RightArg);
1775#endif
1776
1777 ConOutChar(_T('\n'));
1778
1779 if (Cmd->If.Flags & IFFLAG_NEGATE)
1780 {
1781 SpacePad -= 2;
1782 }
1783
1784 Sub = Cmd->Subcommands;
1785 DumpCommand(Sub, SpacePad);
1786 if (Sub->Next)
1787 {
1788 ConOutPrintf(_T("%*s"), SpacePad - 2, _T(""));
1789 ConOutPuts(_T("else\n"));
1790 DumpCommand(Sub->Next, SpacePad);
1791 }
1792 return;
1793 }
1794
1795 default:
1796 ConOutPrintf(_T("*** Unknown type: %x\n"), Cmd->Type);
1797 break;
1798 }
1799
1800#undef DUMP
1801}
#define IFFLAG_IGNORECASE
Definition: cmd.h:261
#define IFFLAG_NEGATE
Definition: cmd.h:260
#define FOR_F
Definition: cmd.h:235
#define FOR_LOOP
Definition: cmd.h:236
#define FOR_DIRS
Definition: cmd.h:234
#define FOR_RECURSIVE
Definition: cmd.h:237
#define DUMP(Command, Pad)
static const TCHAR *const IfOperatorString[]
Definition: parser.c:44
static VOID DumpRedir(IN REDIRECTION *Redirections)
Definition: parser.c:1514
VOID DumpCommand(IN PARSED_COMMAND *Cmd, IN ULONG SpacePad)
Definition: parser.c:1533
#define C_OP_LOWEST
Definition: parser.c:38
static const TCHAR OpString[][3]
Definition: parser.c:40
#define IF_MAX_UNARY
static void dump(const void *ptr, unsigned len)
Definition: msc.c:95
#define C_BLOCK
Definition: rsym.h:130
COMMAND_TYPE Type
Definition: cmd.h:374
struct _PARSED_COMMAND * Next
Definition: cmd.h:372

Referenced by DumpCommand(), and ParseCommand().

◆ DuplicateEnvironment()

LPTSTR DuplicateEnvironment ( VOID  )

Definition at line 25 of file setlocal.c.

26{
27 LPTSTR Environ = GetEnvironmentStrings();
28 LPTSTR End, EnvironCopy;
29
30 if (!Environ) return NULL;
31
32 for (End = Environ; *End; End += _tcslen(End) + 1) ;
33 EnvironCopy = cmd_alloc((End + 1 - Environ) * sizeof(TCHAR));
34
35 if (EnvironCopy)
36 memcpy(EnvironCopy, Environ, (End + 1 - Environ) * sizeof(TCHAR));
37
39 return EnvironCopy;
40}

Referenced by _tmain(), cmd_endlocal(), and cmd_setlocal().

◆ EchoCommand()

VOID EchoCommand ( IN PARSED_COMMAND Cmd)

Definition at line 1808 of file parser.c.

1810{
1811 PARSED_COMMAND* Sub;
1812 REDIRECTION* Redir;
1813
1814 if (!Cmd)
1815 return;
1816
1817 switch (Cmd->Type)
1818 {
1819 case C_COMMAND:
1820 case C_REM:
1821 {
1822 if (SubstituteForVars(Cmd->Command.First, TempBuf))
1823 ConOutPrintf(_T("%s"), TempBuf);
1824 if (SubstituteForVars(Cmd->Command.Rest, TempBuf))
1825 {
1826 ConOutPrintf(_T("%s"), TempBuf);
1827#ifdef MSCMD_ECHO_COMMAND_COMPAT
1828 /* NOTE: For Windows compatibility, add a trailing space after printing the command parameter, if present */
1829 if (*TempBuf) ConOutChar(_T(' '));
1830#endif
1831 }
1832 break;
1833 }
1834
1835 case C_QUIET:
1836 return;
1837
1838 case C_BLOCK:
1839 {
1840 BOOLEAN bIsFirstCmdCRLF;
1841
1842 ConOutChar(_T('('));
1843
1844 Sub = Cmd->Subcommands;
1845
1846 bIsFirstCmdCRLF = (Sub && Sub->Next);
1847
1848#if defined(MSCMD_ECHO_COMMAND_COMPAT) && defined(MSCMD_PARSER_BUGS)
1849 /*
1850 * We will emulate Windows' CMD handling of "CRLF" and "&" multi-command
1851 * enumeration within parenthesized command blocks.
1852 */
1853 bIsFirstCmdCRLF = bIsFirstCmdCRLF && (Sub->Type != C_MULTI);
1854#endif
1855
1856 /*
1857 * Single-command block: display all on one line.
1858 * Multi-command block: display commands on separate lines.
1859 */
1860 if (bIsFirstCmdCRLF)
1861 ConOutChar(_T('\n'));
1862
1863 for (; Sub; Sub = Sub->Next)
1864 {
1865 EchoCommand(Sub);
1866 if (Sub->Next)
1867#ifdef MSCMD_ECHO_COMMAND_COMPAT
1868 ConOutPuts(_T(" \n "));
1869#else
1870 ConOutChar(_T('\n'));
1871#endif
1872 }
1873
1874 if (bIsFirstCmdCRLF)
1875 ConOutChar(_T('\n'));
1876
1877#ifdef MSCMD_ECHO_COMMAND_COMPAT
1878 /* NOTE: For Windows compatibility, add a trailing space after printing the closing parenthesis */
1879 ConOutPuts(_T(") "));
1880#else
1881 ConOutChar(_T(')'));
1882#endif
1883 break;
1884 }
1885
1886 case C_MULTI:
1887 case C_OR:
1888 case C_AND:
1889 case C_PIPE:
1890 {
1891 Sub = Cmd->Subcommands;
1892 EchoCommand(Sub);
1893 ConOutPrintf(_T(" %s "), OpString[Cmd->Type - C_OP_LOWEST]);
1894 EchoCommand(Sub->Next);
1895 break;
1896 }
1897
1898 case C_FOR:
1899 {
1900 ConOutPuts(_T("for"));
1901 if (Cmd->For.Switches & FOR_DIRS) ConOutPuts(_T(" /D"));
1902 if (Cmd->For.Switches & FOR_F) ConOutPuts(_T(" /F"));
1903 if (Cmd->For.Switches & FOR_LOOP) ConOutPuts(_T(" /L"));
1904 if (Cmd->For.Switches & FOR_RECURSIVE) ConOutPuts(_T(" /R"));
1905 if (Cmd->For.Params)
1906 ConOutPrintf(_T(" %s"), Cmd->For.Params);
1907 if (Cmd->For.List && SubstituteForVars(Cmd->For.List, TempBuf))
1908 ConOutPrintf(_T(" %%%c in (%s) do "), Cmd->For.Variable, TempBuf);
1909 else
1910 ConOutPrintf(_T(" %%%c in (%s) do "), Cmd->For.Variable, Cmd->For.List);
1911 EchoCommand(Cmd->Subcommands);
1912 break;
1913 }
1914
1915 case C_IF:
1916 {
1917 ConOutPuts(_T("if"));
1918 if (Cmd->If.Flags & IFFLAG_IGNORECASE)
1919 ConOutPuts(_T(" /I"));
1920 if (Cmd->If.Flags & IFFLAG_NEGATE)
1921 ConOutPuts(_T(" not"));
1922 if (Cmd->If.LeftArg && SubstituteForVars(Cmd->If.LeftArg, TempBuf))
1923 ConOutPrintf(_T(" %s"), TempBuf);
1924 ConOutPrintf(_T(" %s"), IfOperatorString[Cmd->If.Operator]);
1925 if (SubstituteForVars(Cmd->If.RightArg, TempBuf))
1926 ConOutPrintf(_T(" %s "), TempBuf);
1927 Sub = Cmd->Subcommands;
1928 EchoCommand(Sub);
1929 if (Sub->Next)
1930 {
1931 ConOutPuts(_T(" else "));
1932 EchoCommand(Sub->Next);
1933 }
1934 break;
1935 }
1936
1937 default:
1938 ASSERT(FALSE);
1939 break;
1940 }
1941
1942 for (Redir = Cmd->Redirections; Redir; Redir = Redir->Next)
1943 {
1944 if (SubstituteForVars(Redir->Filename, TempBuf))
1945 {
1946#ifdef MSCMD_ECHO_COMMAND_COMPAT
1947 ConOutPrintf(_T("%c%s%s "),
1948 _T('0') + Redir->Number,
1949 RedirString[Redir->Mode], TempBuf);
1950#else
1951 ConOutPrintf(_T(" %c%s%s"),
1952 _T('0') + Redir->Number,
1953 RedirString[Redir->Mode], TempBuf);
1954#endif
1955 }
1956 }
1957}
VOID EchoCommand(IN PARSED_COMMAND *Cmd)
Definition: parser.c:1808
static TCHAR TempBuf[CMDLINE_LENGTH]
Definition: parser.c:88
static const TCHAR RedirString[][3]
Definition: parser.c:42
#define ASSERT(a)
Definition: mode.c:44
REDIR_MODE Mode
Definition: cmd.h:453
BYTE Number
Definition: cmd.h:452
TCHAR Filename[]
Definition: cmd.h:454
struct _REDIRECTION * Next
Definition: cmd.h:450

Referenced by EchoCommand(), and ExecuteCommandWithEcho().

◆ error_bad_command()

VOID error_bad_command ( PCTSTR  s)

Definition at line 124 of file error.c.

125{
127 nErrorLevel = 9009;
128}
#define STRING_ERROR_BADCOMMAND
Definition: resource.h:13

Referenced by Execute(), and ForF().

◆ error_file_not_found()

VOID error_file_not_found ( VOID  )

Definition at line 93 of file error.c.

94{
96 nErrorLevel = 1;
97}
#define STRING_ERROR_FILE_NOT_FOUND
Definition: resource.h:9

Referenced by cmd_move(), cmd_rename(), and PrintSummary().

◆ error_invalid_drive()

VOID error_invalid_drive ( VOID  )

Definition at line 117 of file error.c.

118{
120 nErrorLevel = 1;
121}
#define STRING_ERROR_INVALID_DRIVE
Definition: resource.h:13

Referenced by cmd_chdir(), and cmd_vol().

◆ error_invalid_parameter_format()

VOID error_invalid_parameter_format ( PCTSTR  s)

Definition at line 145 of file error.c.

Referenced by cmd_move(), cmd_setlocal(), and CommandDelete().

◆ error_invalid_switch()

VOID error_invalid_switch ( TCHAR  ch)

Definition at line 72 of file error.c.

Referenced by cmd_mklink(), cmd_shift(), cmd_ver(), and DirReadParam().

◆ error_no_pipe()

VOID error_no_pipe ( VOID  )

Definition at line 131 of file error.c.

132{
134 nErrorLevel = 1;
135}
#define STRING_ERROR_CANNOTPIPE
Definition: resource.h:15

Referenced by ExecutePipeline().

◆ error_out_of_memory()

VOID error_out_of_memory ( VOID  )

Definition at line 138 of file error.c.

139{
141 nErrorLevel = 1;
142}
#define STRING_ERROR_OUT_OF_MEMORY
Definition: resource.h:14

Referenced by BatchParams(), cmd_call(), cmd_path(), cmd_setlocal(), cmd_start(), DoCommand(), ExecuteAsync(), ForF(), and PushDirectory().

◆ error_parameter_format()

VOID error_parameter_format ( TCHAR  ch)

Definition at line 65 of file error.c.

66{
68 nErrorLevel = 1;
69}
#define STRING_ERROR_PARAMETERF_ERROR
Definition: resource.h:5

Referenced by DirReadParam().

◆ error_path_not_found()

VOID error_path_not_found ( VOID  )

Definition at line 86 of file error.c.

87{
89 nErrorLevel = 1;
90}
#define STRING_ERROR_PATH_NOT_FOUND
Definition: resource.h:8

◆ error_req_param_missing()

VOID error_req_param_missing ( VOID  )

◆ error_sfile_not_found()

VOID error_sfile_not_found ( PCTSTR  s)

Definition at line 100 of file error.c.

101{
103
105 ConErrPrintf(_T("%s - %s\n"), szMsg, s);
106 nErrorLevel = 1;
107}
#define RC_STRING_MAX_SIZE
Definition: resource.h:3

Referenced by DeleteFiles(), and ForF().

◆ error_syntax()

VOID error_syntax ( PCTSTR  s)

Definition at line 152 of file error.c.

153{
155
157
158 if (s)
159 ConErrPrintf(_T("%s - %s\n"), szMsg, s);
160 else
161 ConErrPrintf(_T("%s.\n"), szMsg);
162
163 nErrorLevel = 1;
164}
#define STRING_ERROR_ERROR2
Definition: resource.h:44

Referenced by cmd_move(), cmd_rename(), ExecuteIf(), ForF(), and ParseErrorEx().

◆ error_too_many_parameters()

VOID error_too_many_parameters ( PCTSTR  s)

Definition at line 79 of file error.c.

Referenced by cmd_mklink(), cmd_move(), and ExecutePipeline().

◆ ErrorMessage()

VOID ErrorMessage ( IN DWORD  dwErrorCode,
IN PCTSTR szFormat  OPTIONAL,
  ... 
)

Definition at line 26 of file error.c.

30{
31 va_list arg_ptr;
32 PTSTR szError;
34 TCHAR szMessage[1024];
35
36 if (dwErrorCode == ERROR_SUCCESS)
37 return;
38
39 *szMessage = 0;
40 if (szFormat)
41 {
42 va_start(arg_ptr, szFormat);
43 _vstprintf(szMessage, szFormat, arg_ptr);
44 va_end(arg_ptr);
45 }
46
49 (PTSTR)&szError, 0, NULL))
50 {
51 ConErrPrintf(_T("%s%s%s"), szError, szMessage, (*szMessage ? _T("\n") : _T("")));
52 if (szError)
53 LocalFree(szError);
54 return;
55 }
56
57 /* Fall back just in case the error is not defined */
59 if (szFormat)
60 ConErrPrintf(_T("%s -- %s\n"), szMsg, szMessage);
61 else
62 ConErrPrintf(_T("%s\n"), szMsg);
63}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define STRING_CONSOLE_ERROR
Definition: resource.h:6
#define _vstprintf
Definition: tchar.h:540

Referenced by IopLogWorker().

◆ ExecuteCommand()

INT ExecuteCommand ( IN struct _PARSED_COMMAND Cmd)

◆ ExecuteCommandWithEcho()

INT ExecuteCommandWithEcho ( IN struct _PARSED_COMMAND Cmd)

◆ ExecuteFor()

INT ExecuteFor ( struct _PARSED_COMMAND Cmd)

Definition at line 604 of file for.c.

605{
606 INT Ret;
607 LPTSTR List;
608 PFOR_CONTEXT lpNew;
609 TCHAR Buffer[CMDLINE_LENGTH]; /* Buffer to hold the variable value */
610 LPTSTR BufferPtr = Buffer;
611
612 List = DoDelayedExpansion(Cmd->For.List);
613 if (!List)
614 return 1;
615
616 /* Create our FOR context */
617 lpNew = cmd_alloc(sizeof(FOR_CONTEXT));
618 if (!lpNew)
619 {
620 WARN("Cannot allocate memory for lpNew!\n");
621 cmd_free(List);
622 return 1;
623 }
624 lpNew->prev = fc;
625 lpNew->firstvar = Cmd->For.Variable;
626 lpNew->varcount = 1;
627 lpNew->values = &BufferPtr;
628
629 Cmd->For.Context = lpNew;
630 fc = lpNew;
631
632 /* Run the extended FOR syntax only if extensions are enabled */
634 {
635 if (Cmd->For.Switches & FOR_F)
636 {
637 Ret = ForF(Cmd, List, Buffer);
638 }
639 else if (Cmd->For.Switches & FOR_LOOP)
640 {
641 Ret = ForLoop(Cmd, List, Buffer);
642 }
643 else if (Cmd->For.Switches & FOR_RECURSIVE)
644 {
645 DWORD Len = GetFullPathName(Cmd->For.Params ? Cmd->For.Params : _T("."),
647 Ret = ForRecursive(Cmd, List, Buffer, &Buffer[Len]);
648 }
649 else
650 {
651 Ret = ForDir(Cmd, List, Buffer, Buffer);
652 }
653 }
654 else
655 {
656 Ret = ForDir(Cmd, List, Buffer, Buffer);
657 }
658
659 /* Remove our context, unless someone already did that */
660 if (fc == lpNew)
661 fc = lpNew->prev;
662
663 cmd_free(lpNew);
664 cmd_free(List);
665 return Ret;
666}
PTSTR DoDelayedExpansion(IN PCTSTR Line)
Definition: cmd.c:1640
Definition: bufpool.h:45
#define Len
Definition: deflate.h:82
static INT ForLoop(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer)
Definition: for.c:482
static INT ForDir(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer, TCHAR *BufPos)
Definition: for.c:513
static INT ForF(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer)
Definition: for.c:125
PFOR_CONTEXT fc
Definition: for.c:57
static INT ForRecursive(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer, TCHAR *BufPos)
Definition: for.c:561
LPTSTR * values
Definition: batch.h:50
UINT varcount
Definition: batch.h:49
TCHAR firstvar
Definition: batch.h:48
struct _FOR_CONTEXT * prev
Definition: batch.h:47
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550

Referenced by ExecuteCommand().

◆ ExecuteIf()

INT ExecuteIf ( struct _PARSED_COMMAND Cmd)

Definition at line 66 of file if.c.

67{
68 INT result = FALSE; /* when set cause 'then' clause to be executed */
70 LPTSTR Left = NULL, Right;
71
72 if (Cmd->If.LeftArg)
73 {
74 Left = DoDelayedExpansion(Cmd->If.LeftArg);
75 if (!Left)
76 return 1;
77 }
78 Right = DoDelayedExpansion(Cmd->If.RightArg);
79 if (!Right)
80 {
81 if (Left) cmd_free(Left);
82 return 1;
83 }
84
85 if (bEnableExtensions && (Cmd->If.Operator == IF_CMDEXTVERSION))
86 {
87 /* IF CMDEXTVERSION n: check if Command Extensions
88 * version is greater or equal to n. */
89 DWORD n = _tcstoul(Right, &param, 10);
90 if (*param != _T('\0'))
91 {
92 error_syntax(Right);
93 goto fail;
94 }
95 result = (CMDEXTVERSION >= n);
96 }
97 else if (bEnableExtensions && (Cmd->If.Operator == IF_DEFINED))
98 {
99 /* IF DEFINED var: check if environment variable exists */
100 result = (GetEnvVarOrSpecial(Right) != NULL);
101 }
102 else if (Cmd->If.Operator == IF_ERRORLEVEL)
103 {
104 /* IF ERRORLEVEL n: check if last exit code is greater or equal to n */
105 INT n = _tcstol(Right, &param, 10);
106 if (*param != _T('\0'))
107 {
108 error_syntax(Right);
109 goto fail;
110 }
111 result = (nErrorLevel >= n);
112 }
113 else if (Cmd->If.Operator == IF_EXIST)
114 {
115 BOOL IsDir;
116 SIZE_T Size;
118 HANDLE hFind;
119 DWORD attrs;
120
121 /* IF EXIST filename: check if file exists (wildcards allowed) */
122 StripQuotes(Right);
123
124 Size = _tcslen(Right);
125 IsDir = (Right[Size - 1] == '\\');
126 if (IsDir)
127 Right[Size - 1] = 0;
128
129 hFind = FindFirstFile(Right, &f);
130 if (hFind != INVALID_HANDLE_VALUE)
131 {
132 attrs = f.dwFileAttributes;
133 FindClose(hFind);
134 }
135 else
136 {
137 /* FindFirstFile fails at the root directory. */
138 attrs = GetFileAttributes(Right);
139 }
140
141 if (attrs == INVALID_FILE_ATTRIBUTES)
142 result = FALSE;
143 else if (IsDir)
145 else
146 result = TRUE;
147
148 if (IsDir)
149 Right[Size - 1] = '\\';
150 }
151 else
152 {
153 /*
154 * Do case-insensitive string comparisons if /I specified.
155 *
156 * Since both strings are user-specific, use kernel32!lstrcmp(i)
157 * instead of CRT!_tcs(i)cmp, so as to use the correct
158 * current thread locale information.
159 */
160 INT (WINAPI *StringCmp)(LPCTSTR, LPCTSTR) =
161 (Cmd->If.Flags & IFFLAG_IGNORECASE) ? lstrcmpi : lstrcmp;
162
163 if (Cmd->If.Operator == IF_STRINGEQ)
164 {
165 /* IF str1 == str2 */
166 result = (StringCmp(Left, Right) == 0);
167 }
168 else if (bEnableExtensions)
169 {
170 result = GenericCmp(StringCmp, Left, Right);
171 switch (Cmd->If.Operator)
172 {
173 case IF_EQU: result = (result == 0); break;
174 case IF_NEQ: result = (result != 0); break;
175 case IF_LSS: result = (result < 0); break;
176 case IF_LEQ: result = (result <= 0); break;
177 case IF_GTR: result = (result > 0); break;
178 case IF_GEQ: result = (result >= 0); break;
179 default: goto unknownOp;
180 }
181 }
182 else
183 {
184unknownOp:
185 ERR("Unknown IF operator 0x%x\n", Cmd->If.Operator);
186 ASSERT(FALSE);
187 goto fail;
188 }
189 }
190
191 if (Left) cmd_free(Left);
192 cmd_free(Right);
193
194 if (result ^ ((Cmd->If.Flags & IFFLAG_NEGATE) != 0))
195 {
196 /* Full condition was true, do the command */
197 return ExecuteCommand(Cmd->Subcommands);
198 }
199 else
200 {
201 /* Full condition was false, do the "else" command if there is one */
202 return ExecuteCommand(Cmd->Subcommands->Next);
203 }
204
205fail:
206 if (Left) cmd_free(Left);
207 cmd_free(Right);
208 return 1;
209}
INT ExecuteCommand(IN PARSED_COMMAND *Cmd)
Definition: cmd.c:782
LPCTSTR GetEnvVarOrSpecial(LPCTSTR varName)
Definition: cmd.c:904
#define CMDEXTVERSION
Definition: cmd.h:32
static INT GenericCmp(INT(WINAPI *StringCmp)(LPCTSTR, LPCTSTR), LPCTSTR Left, LPCTSTR Right)
Definition: if.c:35
#define ERR(fmt,...)
Definition: debug.h:110
GLuint64EXT * result
Definition: glext.h:11304
#define _tcstol
Definition: tchar.h:594
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define GetFileAttributes
Definition: winbase.h:3750
#define lstrcmp
Definition: winbase.h:3807
#define lstrcmpi
Definition: winbase.h:3808

Referenced by ExecuteCommand().

◆ ExpandAlias()

VOID ExpandAlias ( LPTSTR  cmd,
INT  maxlen 
)

Definition at line 89 of file alias.c.

90{
92 TCHAR *position, *in, *out;
94 LPTSTR tmp;
95
96 tmp = cmd_dup(cmd);
97 if (!tmp)
98 return;
99
100 /* first part is the macro name */
101 position = tmp + _tcscspn(tmp, _T(" \n"));
102 if (position == tmp)
103 {
104 cmd_free(tmp);
105 return;
106 }
107 *position++ = _T('\0');
108 position += _tcsspn(position, _T(" "));
109
110 buffer = cmd_alloc(maxlen);
111 if (!buffer)
112 {
113 WARN("Cannot allocate memory for alias buffer!\n");
114 cmd_free(tmp);
115 return;
116 }
117
118 if (GetConsoleAlias(tmp, buffer, maxlen, _T("cmd.exe")) == 0)
119 {
120 cmd_free(tmp);
122 return;
123 }
124
125 in = buffer;
126 out = cmd;
127 while (*in)
128 {
129 if (*in == _T('$'))
130 {
131 Token = position;
132 if (in[1] >= _T('1') && in[1] <= _T('9'))
133 {
134 /* Copy a single space-delimited token from the input line */
135 INT num;
136 for (num = in[1] - _T('1'); num > 0; num--)
137 {
138 Token += _tcscspn(Token, _T(" \n"));
139 Token += _tcsspn(Token, _T(" "));
140 }
141 while (!_tcschr(_T(" \n"), *Token))
142 {
143 if (out >= &cmd[maxlen - 1])
144 break;
145 *out++ = *Token++;
146 }
147 in += 2;
148 continue;
149 }
150 else if (in[1] == _T('*'))
151 {
152 /* Copy the entire remainder of the line */
153 while (*Token && *Token != _T('\n'))
154 {
155 if (out >= &cmd[maxlen - 1])
156 break;
157 *out++ = *Token++;
158 }
159 in += 2;
160 continue;
161 }
162 }
163 if (out >= &cmd[maxlen - 1])
164 break;
165 *out++ = *in++;
166 }
167 *out++ = _T('\n');
168 *out = _T('\0');
169
171 cmd_free(tmp);
172}
GLuint buffer
Definition: glext.h:5915
GLuint in
Definition: glext.h:9616
#define _tcsspn
Definition: tchar.h:1414
static FILE * out
Definition: regtests2xml.c:44
Definition: ftp_var.h:139
#define GetConsoleAlias
Definition: wincon.h:770

Referenced by ReadCommand().

◆ FilePromptYN()

INT FilePromptYN ( UINT  resID)

Definition at line 559 of file misc.c.

560{
562// TCHAR cKey = 0;
563// LPTSTR szKeys = _T("yna");
564
565 TCHAR szIn[10];
566 LPTSTR p;
567
568 if (resID != 0)
569 ConOutResPrintf (resID);
570
571 /* preliminary fix */
572 ConInString(szIn, 10);
573
574 _tcsupr (szIn);
575 for (p = szIn; _istspace (*p); p++)
576 ;
577
579
580 if (_tcsncmp(p, &szMsg[0], 1) == 0)
581 return PROMPT_YES;
582 else if (_tcsncmp(p, &szMsg[1], 1) == 0)
583 return PROMPT_NO;
584#if 0
585 else if (*p == _T('\03'))
586 return PROMPT_BREAK;
587#endif
588
589 return PROMPT_NO;
590
591 /* unfinished solution */
592#if 0
594 ConInDisable();
595
596 do
597 {
598 ConInKey (&ir);
599 cKey = _totlower (ir.Event.KeyEvent.uChar.AsciiChar);
600 if (_tcschr (szKeys, cKey[0]) == NULL)
601 cKey = 0;
602
603
604 }
605 while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
606 (ir.Event.KeyEvent.wVirtualKeyCode == VK_MENU) ||
607 (ir.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL));
608
610 ConInEnable();
611
612 if ((ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
613 ((ir.Event.KeyEvent.wVirtualKeyCode == 'C') &&
614 (ir.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))))
615 return PROMPT_BREAK;
616
617 return PROMPT_YES;
618#endif
619}
VOID AddBreakHandler(VOID)
Definition: cmd.c:1844
VOID RemoveBreakHandler(VOID)
Definition: cmd.c:1850
VOID ConInDisable(VOID)
Definition: console.c:36
VOID ConInEnable(VOID)
Definition: console.c:46
#define _totlower
Definition: tchar.h:1511
#define VK_ESCAPE
Definition: winuser.h:2214

Referenced by DeleteFiles().

◆ FilePromptYNA()

INT FilePromptYNA ( UINT  resID)

Definition at line 622 of file misc.c.

623{
625// TCHAR cKey = 0;
626// LPTSTR szKeys = _T("yna");
627
628 TCHAR szIn[10];
629 LPTSTR p;
630
631 if (resID != 0)
632 ConOutResPrintf (resID);
633
634 /* preliminary fix */
635 ConInString(szIn, 10);
636
637 _tcsupr (szIn);
638 for (p = szIn; _istspace (*p); p++)
639 ;
640
642
643 if (_tcsncmp(p, &szMsg[0], 1) == 0)
644 return PROMPT_YES;
645 else if (_tcsncmp(p, &szMsg[1], 1) == 0)
646 return PROMPT_NO;
647 else if (_tcsncmp(p, &szMsg[2], 1) == 0)
648 return PROMPT_ALL;
649#if 0
650 else if (*p == _T('\03'))
651 return PROMPT_BREAK;
652#endif
653
654 return PROMPT_NO;
655
656 /* unfinished solution */
657#if 0
659 ConInDisable();
660
661 do
662 {
663 ConInKey (&ir);
664 cKey = _totlower (ir.Event.KeyEvent.uChar.AsciiChar);
665 if (_tcschr (szKeys, cKey[0]) == NULL)
666 cKey = 0;
667 }
668 while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
669 (ir.Event.KeyEvent.wVirtualKeyCode == VK_MENU) ||
670 (ir.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL));
671
673 ConInEnable();
674
675 if ((ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
676 ((ir.Event.KeyEvent.wVirtualKeyCode == _T('C')) &&
677 (ir.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))))
678 return PROMPT_BREAK;
679
680 return PROMPT_YES;
681#endif
682}

Referenced by cmd_rmdir(), CopyOverwrite(), DeleteFiles(), MoveOverwrite(), and replace().

◆ FormatDate()

INT FormatDate ( TCHAR lpDate,
LPSYSTEMTIME  dt,
BOOL  b4Digit 
)

Definition at line 675 of file dir.c.

676{
677 /* Format date */
678 WORD wYear = b4Digit ? dt->wYear : dt->wYear%100;
679 switch (nDateFormat)
680 {
681 case 0: /* mmddyy */
682 default:
683 return _stprintf(lpDate, _T("%02d%c%02d%c%0*d"),
685 dt->wDay, cDateSeparator,
686 b4Digit?4:2, wYear);
687 break;
688
689 case 1: /* ddmmyy */
690 return _stprintf(lpDate, _T("%02d%c%02d%c%0*d"),
691 dt->wDay, cDateSeparator, dt->wMonth,
692 cDateSeparator, b4Digit?4:2, wYear);
693 break;
694
695 case 2: /* yymmdd */
696 return _stprintf(lpDate, _T("%0*d%c%02d%c%02d"),
697 b4Digit?4:2, wYear, cDateSeparator,
698 dt->wMonth, cDateSeparator, dt->wDay);
699 break;
700 }
701}
TCHAR cDateSeparator
Definition: locale.c:16
INT nDateFormat
Definition: locale.c:20
WORD wYear
Definition: winbase.h:905
WORD wMonth
Definition: winbase.h:906
WORD wDay
Definition: winbase.h:908

Referenced by DirPrintFileDateTime(), GetDateString(), and GetEnhancedVar().

◆ FormatTime()

INT FormatTime ( TCHAR lpTime,
LPSYSTEMTIME  dt 
)

Definition at line 704 of file dir.c.

705{
706 /* Format Time */
707 switch (nTimeFormat)
708 {
709 case 0: /* 12 hour format */
710 default:
711 return _stprintf(lpTime,_T("%02d%c%02u %cM"),
712 (dt->wHour == 0 ? 12 : (dt->wHour <= 12 ? dt->wHour : dt->wHour - 12)),
714 dt->wMinute, (dt->wHour <= 11 ? _T('A') : _T('P')));
715 break;
716
717 case 1: /* 24 hour format */
718 return _stprintf(lpTime, _T("%02d%c%02u"),
719 dt->wHour, cTimeSeparator, dt->wMinute);
720 break;
721 }
722}
INT nTimeFormat
Definition: locale.c:21
WORD wHour
Definition: winbase.h:909
WORD wMinute
Definition: winbase.h:910

Referenced by cmd_time(), DirPrintFileDateTime(), and GetEnhancedVar().

◆ FreeCommand()

VOID FreeCommand ( IN OUT PARSED_COMMAND Cmd)

Definition at line 527 of file parser.c.

529{
530 if (Cmd->Subcommands)
531 FreeCommand(Cmd->Subcommands);
532 if (Cmd->Next)
533 FreeCommand(Cmd->Next);
534 FreeRedirection(Cmd->Redirections);
535 if (Cmd->Type == C_FOR)
536 {
537 cmd_free(Cmd->For.Params);
538 cmd_free(Cmd->For.List);
539 }
540 else if (Cmd->Type == C_IF)
541 {
542 cmd_free(Cmd->If.LeftArg);
543 cmd_free(Cmd->If.RightArg);
544 }
545 cmd_free(Cmd);
546}
VOID FreeRedirection(REDIRECTION *)
Definition: redir.c:153
VOID FreeCommand(IN OUT PARSED_COMMAND *Cmd)
Definition: parser.c:527

Referenced by Batch(), cmd_call(), FreeCommand(), ParseBlock(), ParseCommand(), ParseCommandBinaryOp(), ParseCommandLine(), ParseFor(), ParseIf(), and ProcessInput().

◆ FreeLastPath()

VOID FreeLastPath ( VOID  )

◆ freep()

VOID freep ( LPTSTR p)

Definition at line 446 of file misc.c.

447{
448 LPTSTR *q;
449
450 if (!p)
451 return;
452
453 q = p;
454 while (*q)
455 cmd_free(*q++);
456
457 cmd_free(p);
458}

Referenced by split(), and splitspace().

◆ FreeRedirection()

VOID FreeRedirection ( REDIRECTION Redir)

Definition at line 153 of file redir.c.

154{
155 REDIRECTION *Next;
156 for (; Redir; Redir = Next)
157 {
158 Next = Redir->Next;
160 cmd_free(Redir);
161 }
162}
HANDLE OldHandle
Definition: cmd.h:451

Referenced by ExitBatch(), FreeCommand(), ParsePrimary(), and ParseRedirection().

◆ GetDateString()

LPTSTR GetDateString ( VOID  )

Definition at line 58 of file locale.c.

59{
60 static TCHAR szDate[32];
62 INT len;
64
65 len = GetDateFormat(LOCALE_USER_DEFAULT, 0, &t, _T("ddd"), szDate, ARRAYSIZE(szDate));
66 szDate[len - 1] = _T(' ');
67 FormatDate(&szDate[len], &t, TRUE);
68 return szDate;
69}
INT FormatDate(TCHAR *, LPSYSTEMTIME, BOOL)
Definition: dir.c:675
#define LOCALE_USER_DEFAULT
#define GetDateFormat
Definition: winnls.h:1184

Referenced by cmd_date(), GetEnvVarOrSpecial(), and PrintPrompt().

◆ GetDirectoryStackDepth()

INT GetDirectoryStackDepth ( VOID  )

Definition at line 98 of file dirstack.c.

99{
100 return nStackDepth;
101}

Referenced by PrintPrompt().

◆ GetEnvVarOrSpecial()

LPCTSTR GetEnvVarOrSpecial ( LPCTSTR  varName)

Definition at line 904 of file cmd.c.

905{
906 static TCHAR ret[MAX_PATH];
907
908 LPTSTR var = GetEnvVar(varName);
909 if (var)
910 return var;
911
912 /* The environment variable doesn't exist, look for
913 * a "special" one only if extensions are enabled. */
915 return NULL;
916
917 /* %CD% */
918 if (_tcsicmp(varName, _T("CD")) == 0)
919 {
921 return ret;
922 }
923 /* %DATE% */
924 else if (_tcsicmp(varName, _T("DATE")) == 0)
925 {
926 return GetDateString();
927 }
928 /* %TIME% */
929 else if (_tcsicmp(varName, _T("TIME")) == 0)
930 {
931 return GetTimeString();
932 }
933 /* %RANDOM% */
934 else if (_tcsicmp(varName, _T("RANDOM")) == 0)
935 {
936 /* Get random number */
937 _itot(rand(), ret, 10);
938 return ret;
939 }
940 /* %CMDCMDLINE% */
941 else if (_tcsicmp(varName, _T("CMDCMDLINE")) == 0)
942 {
943 return GetCommandLine();
944 }
945 /* %CMDEXTVERSION% */
946 else if (_tcsicmp(varName, _T("CMDEXTVERSION")) == 0)
947 {
948 /* Set Command Extensions version number to CMDEXTVERSION */
949 _itot(CMDEXTVERSION, ret, 10);
950 return ret;
951 }
952 /* %ERRORLEVEL% */
953 else if (_tcsicmp(varName, _T("ERRORLEVEL")) == 0)
954 {
955 _itot(nErrorLevel, ret, 10);
956 return ret;
957 }
958#if (NTDDI_VERSION >= NTDDI_WIN7)
959 /* Available in Win7+, even if the underlying API is available in Win2003+ */
960 /* %HIGHESTNUMANODENUMBER% */
961 else if (_tcsicmp(varName, _T("HIGHESTNUMANODENUMBER")) == 0)
962 {
963 ULONG NumaNodeNumber = 0;
964 GetNumaHighestNodeNumber(&NumaNodeNumber);
965 _itot(NumaNodeNumber, ret, 10);
966 return ret;
967 }
968#endif
969
970 return NULL;
971}
LPTSTR GetEnvVar(LPCTSTR varName)
Definition: cmd.c:886
BOOL bEnableExtensions
Definition: cmd.c:161
BOOL WINAPI GetNumaHighestNodeNumber(OUT PULONG HighestNodeNumber)
Definition: sysinfo.c:265
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10
#define _itot
Definition: tchar.h:608
const char * var
Definition: shader.c:5666
uint32_t ULONG
Definition: typedefs.h:59
#define GetCommandLine
Definition: winbase.h:3734

Referenced by ExecuteIf(), seta_identval(), and SubstituteVar().

◆ GetHandle()

HANDLE GetHandle ( UINT  Number)

Definition at line 39 of file redir.c.

40{
41 if (Number < 3)
43 // return GetStdHandle(STD_INPUT_HANDLE - Number);
44 else if (Number < ARRAYSIZE(ExtraHandles) + 3)
45 return ExtraHandles[Number - 3];
46 else
48}
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:207
static HANDLE ExtraHandles[10 - 3]
Definition: redir.c:37
static const PCON_STREAM StdStreams[]
Definition: redir.c:36

◆ GetParsedEnvVar()

LPCTSTR GetParsedEnvVar ( LPCTSTR  varName,
UINT varNameLen,
BOOL  ModeSetA 
)

◆ GetPathCase()

VOID GetPathCase ( TCHAR Path,
TCHAR OutPath 
)

Definition at line 86 of file misc.c.

87{
88 UINT i = 0;
89 TCHAR TempPath[MAX_PATH];
90 WIN32_FIND_DATA FindFileData;
91 HANDLE hFind;
92 _tcscpy(TempPath, _T(""));
93 _tcscpy(OutPath, _T(""));
94
95 for(i = 0; i < _tcslen(Path); i++)
96 {
97 if (Path[i] != _T('\\'))
98 {
99 _tcsncat(TempPath, &Path[i], 1);
100 if (i != _tcslen(Path) - 1)
101 continue;
102 }
103 /* Handle the base part of the path different.
104 Because if you put it into findfirstfile, it will
105 return your current folder */
106 if (_tcslen(TempPath) == 2 && TempPath[1] == _T(':'))
107 {
108 _tcscat(OutPath, TempPath);
109 _tcscat(OutPath, _T("\\"));
110 _tcscat(TempPath, _T("\\"));
111 }
112 else
113 {
114 hFind = FindFirstFile(TempPath,&FindFileData);
115 if (hFind == INVALID_HANDLE_VALUE)
116 {
117 _tcscpy(OutPath, Path);
118 return;
119 }
120 _tcscat(TempPath, _T("\\"));
121 _tcscat(OutPath, FindFileData.cFileName);
122 _tcscat(OutPath, _T("\\"));
123 FindClose(hFind);
124 }
125 }
126}
PRTL_UNICODE_STRING_BUFFER Path

Referenced by replace(), and SetRootPath().

◆ GetRedirection()

INT GetRedirection ( LPTSTR  ,
REDIRECTION **   
)

◆ GetRootPath()

INT GetRootPath ( IN LPCTSTR  InPath,
OUT LPTSTR  OutPath,
IN INT  size 
)

Definition at line 152 of file internal.c.

156{
157 if (InPath[0] && InPath[1] == _T(':'))
158 {
159 INT t = 0;
160
161 if ((InPath[0] >= _T('0')) && (InPath[0] <= _T('9')))
162 {
163 t = (InPath[0] - _T('0')) + 28;
164 }
165 else if ((InPath[0] >= _T('a')) && (InPath[0] <= _T('z')))
166 {
167 t = (InPath[0] - _T('a')) + 1;
168 }
169 else if ((InPath[0] >= _T('A')) && (InPath[0] <= _T('Z')))
170 {
171 t = (InPath[0] - _T('A')) + 1;
172 }
173
174 return (_tgetdcwd(t, OutPath, size) == NULL);
175 }
176
177 /* Get current directory */
178 return !GetCurrentDirectory(size, OutPath);
179}
#define _tgetdcwd
Definition: tchar.h:674

Referenced by cmd_chdir(), cmd_copy(), cmd_replace(), CommandDelete(), GetDirectory(), and getPath().

◆ GetTimeString()

LPTSTR GetTimeString ( VOID  )

Definition at line 73 of file locale.c.

74{
75 static TCHAR szTime[12];
78 _stprintf(szTime, _T("%2d%c%02d%c%02d%c%02d"),
79 t.wHour, cTimeSeparator, t.wMinute, cTimeSeparator,
80 t.wSecond, cDecimalSeparator, t.wMilliseconds / 10);
81 return szTime;
82}
TCHAR cTimeSeparator
Definition: locale.c:17
TCHAR cDecimalSeparator
Definition: locale.c:19

Referenced by cmd_time(), CommandTimer(), GetEnvVarOrSpecial(), and PrintPrompt().

◆ InitDirectoryStack()

VOID InitDirectoryStack ( VOID  )

Definition at line 80 of file dirstack.c.

81{
82 nStackDepth = 0;
85}

Referenced by Initialize().

◆ InitLastPath()

VOID InitLastPath ( VOID  )

◆ InitLocale()

VOID InitLocale ( VOID  )

Definition at line 25 of file locale.c.

26{
27 TCHAR szBuffer[256];
28
29 /* date settings */
31 cDateSeparator = szBuffer[0];
32 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDATE | LOCALE_RETURN_NUMBER, (LPTSTR)&nDateFormat, sizeof(nDateFormat) / sizeof(TCHAR));
33
34 /* time settings */
36 cTimeSeparator = szBuffer[0];
37 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ITIME | LOCALE_RETURN_NUMBER, (LPTSTR)&nTimeFormat, sizeof(nTimeFormat) / sizeof(TCHAR));
38
39 /* number settings */
41 cThousandSeparator = szBuffer[0];
43 cDecimalSeparator = szBuffer[0];
45 nNumberGroups = _ttoi(szBuffer);
46#if 0
47 /* days of week */
48 for (i = 0; i < 7; i++)
49 {
51 _tcscpy(aszDayNames[(i+1)%7], szBuffer); /* little hack */
52 }
53#endif
54}
TCHAR cDateSeparator
Definition: locale.c:16
INT nTimeFormat
Definition: locale.c:21
INT nDateFormat
Definition: locale.c:20
INT nNumberGroups
Definition: locale.c:22
TCHAR cThousandSeparator
Definition: locale.c:18
#define LOCALE_SDATE
Definition: winnls.h:58
#define LOCALE_SGROUPING
Definition: winnls.h:44
#define LOCALE_SDECIMAL
Definition: winnls.h:42
#define LOCALE_IDATE
Definition: winnls.h:63
#define GetLocaleInfo
Definition: winnls.h:1186
#define LOCALE_ITIME
Definition: winnls.h:65
#define LOCALE_STHOUSAND
Definition: winnls.h:43
#define LOCALE_SABBREVDAYNAME1
Definition: winnls.h:84
#define LOCALE_STIME
Definition: winnls.h:59

Referenced by cmd_start(), Execute(), and Initialize().

◆ InitOSVersion()

VOID InitOSVersion ( VOID  )

Definition at line 32 of file ver.c.

33{
34 LONG lResult;
35 HKEY hKey;
36
37 /* Get version information */
38 ZeroMemory(&osvi, sizeof(osvi));
41
42 /* Build OS version string */
43
44 /* Open registry key */
46 _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
47 0,
49 &hKey);
50 if (lResult == ERROR_SUCCESS)
51 {
52 DWORD dwSize, dwType;
53
54 /* Retrieve the ProductName value */
55 dwSize = sizeof(szOSName);
56 lResult = RegQueryValueEx(hKey,
57 _T("ProductName"),
58 NULL,
59 &dwType,
61 &dwSize);
62
63 /* If we have failed or the data type is unsupported... */
64 if (lResult != ERROR_SUCCESS || dwType != REG_SZ)
65 {
66 /* ... reserve size for one NULL character only! */
67 dwSize = sizeof(TCHAR);
68
69 /* Set an error code (anything != ERROR_SUCCESS) */
71 }
72
73 /* NULL-terminate the string */
74 szOSName[(dwSize / sizeof(TCHAR)) - 1] = _T('\0');
75
76 /* Close the key */
78 }
79
80 /*
81 * If the registry key somehow doesn't exist or cannot be loaded, then
82 * determine at least whether the version of Windows is either 9x or NT.
83 */
84 if (lResult != ERROR_SUCCESS)
85 {
86 switch (osvi.dwPlatformId)
87 {
89 {
90 if (osvi.dwMajorVersion == 4)
91 {
92 if (osvi.dwMinorVersion == 0)
93 _tcscpy(szOSName, _T("Windows 95"));
94 else if (osvi.dwMinorVersion == 1)
95 _tcscpy(szOSName, _T("Windows 98"));
96 else if (osvi.dwMinorVersion == 9)
97 _tcscpy(szOSName, _T("Windows ME"));
98 else
99 _tcscpy(szOSName, _T("Windows 9x"));
100 }
101 break;
102 }
103
105 {
106 _tcscpy(szOSName, _T("Windows NT"));
107 break;
108 }
109 }
110 }
111}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
FxAutoRegKey hKey
#define REG_SZ
Definition: layer.c:22
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define VER_PLATFORM_WIN32_NT
Definition: rtltypes.h:238
#define VER_PLATFORM_WIN32_WINDOWS
Definition: rtltypes.h:237
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
ULONG dwPlatformId
Definition: rtltypes.h:241
ULONG dwOSVersionInfoSize
Definition: rtltypes.h:237
ULONG dwMajorVersion
Definition: rtltypes.h:238
ULONG dwMinorVersion
Definition: rtltypes.h:239
unsigned char * LPBYTE
Definition: typedefs.h:53
TCHAR szOSName[50]
Definition: ver.c:29
OSVERSIONINFO osvi
Definition: ver.c:28
#define ZeroMemory
Definition: winbase.h:1712
#define GetVersionEx
Definition: winbase.h:3787
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegOpenKeyEx
Definition: winreg.h:520
#define RegQueryValueEx
Definition: winreg.h:524
OSVERSIONINFOA OSVERSIONINFO
Definition: rtltypes.h:293

Referenced by Initialize().

◆ InitPrompt()

VOID InitPrompt ( VOID  )

Definition at line 57 of file prompt.c.

58{
59 TCHAR Buffer[2];
60
61 /*
62 * Set the PROMPT environment variable if it doesn't exist already.
63 * You can change the PROMPT environment variable before cmd starts.
64 */
65 if (GetEnvironmentVariable(_T("PROMPT"), Buffer, _countof(Buffer)) == 0)
67}
static TCHAR DefaultPrompt[]
Definition: prompt.c:52
#define _countof(array)
Definition: sndvol32.h:68

Referenced by Initialize().

◆ IsExistingDirectory()

BOOL IsExistingDirectory ( IN LPCTSTR  pszPath)

◆ IsExistingFile()

BOOL IsExistingFile ( IN LPCTSTR  pszPath)

◆ IsValidPathName()

BOOL IsValidPathName ( IN LPCTSTR  pszPath)

Definition at line 482 of file misc.c.

483{
484 BOOL bResult;
485 TCHAR szOldPath[MAX_PATH];
486
487 GetCurrentDirectory(ARRAYSIZE(szOldPath), szOldPath);
488 bResult = SetCurrentDirectory(pszPath);
489
490 SetCurrentDirectory(szOldPath);
491
492 return bResult;
493}
#define SetCurrentDirectory
Definition: winbase.h:3838

◆ msg_pause()

VOID msg_pause ( VOID  )

Definition at line 167 of file error.c.

168{
170}
#define STRING_ERROR_D_PAUSEMSG
Definition: resource.h:16

Referenced by cmd_pause(), and cmd_replace().

◆ OnOffCommand()

BOOL OnOffCommand ( LPTSTR  param,
LPBOOL  flag,
INT  message 
)

Definition at line 32 of file echo.c.

33{
34 TCHAR *p2;
35 if (_tcsnicmp(param, D_OFF, sizeof(D_OFF)/sizeof(TCHAR) - 1) == 0)
36 {
37 p2 = param + sizeof(D_OFF)/sizeof(TCHAR) - 1;
38 while (_istspace(*p2))
39 p2++;
40 if (*p2 == _T('\0'))
41 {
42 *flag = FALSE;
43 return TRUE;
44 }
45 }
46 else if (_tcsnicmp(param, D_ON, sizeof(D_ON)/sizeof(TCHAR) - 1) == 0)
47 {
48 p2 = param + sizeof(D_ON)/sizeof(TCHAR) - 1;
49 while (_istspace(*p2))
50 p2++;
51 if (*p2 == _T('\0'))
52 {
53 *flag = TRUE;
54 return TRUE;
55 }
56 }
57 else if (*param == _T('\0'))
58 {
60 return TRUE;
61 }
62 return FALSE;
63}
#define D_OFF
Definition: cmd.h:41
#define D_ON
Definition: cmd.h:40
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean flag
Definition: glfuncs.h:52
Definition: tftpd.h:60

Referenced by cmd_verify(), and CommandEcho().

◆ PagePrompt()

BOOL __stdcall PagePrompt ( PCON_PAGER  Pager,
DWORD  Done,
DWORD  Total 
)

Definition at line 512 of file misc.c.

513{
514 SHORT iScreenWidth, iCursorY;
515 INPUT_RECORD ir;
516
518
520 ConInDisable();
521
522 do
523 {
524 ConInKey(&ir);
525 }
526 while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
529
531 ConInEnable();
532
533 /*
534 * Get the screen width, erase the full line where the cursor is,
535 * and move the cursor back to the beginning of the line.
536 */
537 GetScreenSize(&iScreenWidth, NULL);
538 iCursorY = GetCursorY();
539 SetCursorXY(0, iCursorY);
540 while (iScreenWidth-- > 0) // Or call FillConsoleOutputCharacter ?
541 ConOutChar(_T(' '));
542 SetCursorXY(0, iCursorY);
543
545 ((ir.Event.KeyEvent.wVirtualKeyCode == _T('C')) &&
547 {
548 /* We break, output a newline */
549 ConOutChar(_T('\n'));
550
552 return FALSE;
553 }
554
555 return TRUE;
556}
SHORT GetCursorY(VOID)
Definition: console.c:218
#define STRING_MISC_HELP1
Definition: resource.h:144

◆ ParseCommand()

PARSED_COMMAND * ParseCommand ( IN PCTSTR  Line)

Definition at line 1461 of file parser.c.

1463{
1465
1466 if (Line)
1467 {
1468 if (!SubstituteVars(Line, ParseLine, _T('%')))
1469 return NULL;
1471 }
1472 else
1473 {
1474 if (!ReadLine(ParseLine, FALSE))
1475 return NULL;
1477 }
1478
1479 InitParser();
1480
1482 if (Cmd)
1483 {
1485
1486 if ((CurrentTokenType != TOK_END) &&
1487 (_tcscmp(CurrentToken, _T("\n")) != 0))
1488 {
1489 ParseError();
1490 }
1491 if (bParseError)
1492 {
1494 return NULL;
1495 }
1496
1497 /* Debugging support */
1498 if (fDumpParse)
1499 DumpCommand(Cmd, 0);
1500 }
1501 else
1502 {
1503 bIgnoreEcho = TRUE;
1504 }
1505 return Cmd;
1506}
BOOL SubstituteVars(IN PCTSTR Src, OUT PTSTR Dest, IN TCHAR Delim)
Definition: cmd.c:1514
BOOL ReadLine(TCHAR *commandline, BOOL bMore)
Definition: cmd.c:1721
static __inline PARSED_COMMAND * ParseCommandOp(IN COMMAND_TYPE OpType)
Definition: parser.c:1447
static TOK_TYPE CurrentTokenType
Definition: parser.c:100
BOOL bParseError
Definition: parser.c:90
static __inline VOID ParseError(VOID)
Definition: parser.c:235
static TCHAR CurrentToken[CMDLINE_LENGTH]
Definition: parser.c:99
static VOID InitParser(VOID)
Definition: parser.c:173
static BOOL bLineContinuations
Definition: parser.c:91
TCHAR ParseLine[CMDLINE_LENGTH]
Definition: parser.c:92
BOOLEAN fDumpParse
Definition: parser.c:36
@ TOK_END
Definition: parser.c:79

Referenced by Batch(), cmd_call(), ParseCommandLine(), and ProcessInput().

◆ ParseCommandLine()

INT ParseCommandLine ( LPTSTR  cmd)

Definition at line 636 of file cmd.c.

637{
638 INT Ret = 0;
640
642 if (!Cmd)
643 {
644 /* Return an adequate error code */
645 return (!bParseError ? 0 : 1);
646 }
647
648 Ret = ExecuteCommand(Cmd);
650 return Ret;
651}

Referenced by _tmain(), Cleanup(), ExecuteAutoRunFile(), and Initialize().

◆ ParseErrorEx()

VOID ParseErrorEx ( IN PCTSTR  s)

Definition at line 227 of file parser.c.

228{
229 /* Only display the first error we encounter */
230 if (!bParseError)
233}

Referenced by cmd_for(), cmd_if(), GetBatchVar(), ParseCommandPart(), and ParseError().

◆ PerformRedirection()

BOOL PerformRedirection ( REDIRECTION RedirList)

Definition at line 63 of file redir.c.

64{
65 REDIRECTION *Redir;
67 HANDLE hNew;
68 UINT DupNumber;
69
70 static SECURITY_ATTRIBUTES SecAttr = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
71
72 /* Some parameters used for read, write, and append, respectively */
73 static struct REDIR_PARAMS
74 {
75 DWORD dwDesiredAccess;
76 DWORD dwShareMode;
77 DWORD dwCreationDisposition;
78 } RedirParams[] =
79 {
82 {GENERIC_WRITE, FILE_SHARE_READ , OPEN_ALWAYS } // REDIR_APPEND
83 };
84
85 for (Redir = RedirList; Redir; Redir = Redir->Next)
86 {
88 if (!Filename)
89 goto redir_error;
91
92 if (*Filename == _T('&'))
93 {
94 DupNumber = Filename[1] - _T('0');
95 if (DupNumber >= 10 ||
97 GetHandle(DupNumber),
99 &hNew,
100 0,
101 TRUE,
103 {
105 }
106 }
107 else
108 {
109 hNew = CreateFile(Filename,
110 RedirParams[Redir->Mode].dwDesiredAccess,
111 RedirParams[Redir->Mode].dwShareMode,
112 &SecAttr,
113 RedirParams[Redir->Mode].dwCreationDisposition,
114 0,
115 NULL);
116 }
117
118 if (hNew == INVALID_HANDLE_VALUE)
119 {
120 /* TODO: Print a more detailed message */
122 Filename);
124redir_error:
125 /* Undo all the redirections before this one */
126 UndoRedirection(RedirList, Redir);
127 return FALSE;
128 }
129
130 if (Redir->Mode == REDIR_APPEND)
131 SetFilePointer(hNew, 0, NULL, FILE_END);
132 Redir->OldHandle = GetHandle(Redir->Number);
133 SetHandle(Redir->Number, hNew);
134
135 TRACE("%d redirected to: %s\n", Redir->Number, debugstr_aw(Filename));
137 }
138 return TRUE;
139}
#define STRING_CMD_ERROR3
Definition: resource.h:29
#define STRING_CMD_ERROR1
Definition: resource.h:27
struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES
#define OPEN_EXISTING
Definition: compat.h:775
#define SetFilePointer
Definition: compat.h:743
#define GetCurrentProcess()
Definition: compat.h:759
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
Definition: handle.c:149
IN PVCB IN PBCB OUT PDIRENT IN USHORT IN POEM_STRING Filename
Definition: fatprocs.h:939
#define CREATE_ALWAYS
Definition: disk.h:72
#define OPEN_ALWAYS
Definition: disk.h:70
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_WRITE
Definition: nt_native.h:90
VOID SetHandle(UINT Number, HANDLE Handle)
Definition: redir.c:50
VOID UndoRedirection(REDIRECTION *Redir, REDIRECTION *End)
Definition: redir.c:142
#define GetHandle(h)
Definition: treelist.c:116
#define FILE_END
Definition: winbase.h:114
#define CreateFile
Definition: winbase.h:3684
#define DUPLICATE_SAME_ACCESS

Referenced by ExecuteCommand().

◆ PrintCommandList()

VOID PrintCommandList ( VOID  )

Definition at line 234 of file cmdtable.c.

235{
236 LPCOMMAND cmdptr;
237 INT y;
238
239 y = 0;
240 cmdptr = cmds;
241 while (cmdptr->name)
242 {
243 if (!(cmdptr->flags & CMD_HIDE))
244 {
245 if (++y == 8)
246 {
247 ConOutPuts(cmdptr->name);
248 ConOutChar(_T('\n'));
249 y = 0;
250 }
251 else
252 {
253 ConOutPrintf (_T("%-10s"), cmdptr->name);
254 }
255 }
256
257 cmdptr++;
258 }
259
260 if (y != 0)
261 ConOutChar(_T('\n'));
262}
#define CMD_HIDE
Definition: cmd.h:142
COMMAND cmds[]
Definition: cmdtable.c:28
INT flags
Definition: cmdcons.c:28

Referenced by CommandShowCommands().

◆ PrintOSVersion()

VOID PrintOSVersion ( VOID  )

Definition at line 114 of file ver.c.

◆ PrintPrompt()

VOID PrintPrompt ( VOID  )

Definition at line 109 of file prompt.c.

110{
111 LPTSTR pr, Prompt;
112 TCHAR szPrompt[256];
114
115 if (GetEnvironmentVariable(_T("PROMPT"), szPrompt, _countof(szPrompt)))
116 Prompt = szPrompt;
117 else
118 Prompt = DefaultPrompt;
119
120 /*
121 * Special pre-handling for $I: If the information line is displayed
122 * on top of the screen, ensure that the prompt won't be hidden below it.
123 */
124 for (pr = Prompt; *pr;)
125 {
126 if (*pr++ != _T('$'))
127 continue;
128 if (!*pr || _totupper(*pr++) != _T('I'))
129 continue;
130
131 if (GetCursorY() == 0)
132 ConOutChar(_T('\n'));
133 break;
134 }
135
136 /* Parse the prompt string */
137 for (pr = Prompt; *pr; ++pr)
138 {
139 if (*pr != _T('$'))
140 {
141 ConOutChar(*pr);
142 }
143 else
144 {
145 ++pr;
146 if (!*pr) break;
147 switch (_totupper(*pr))
148 {
149 case _T('A'):
150 ConOutChar(_T('&'));
151 break;
152
153 case _T('B'):
154 ConOutChar(_T('|'));
155 break;
156
157 case _T('C'):
158 ConOutChar(_T('('));
159 break;
160
161 case _T('D'):
162 ConOutPrintf(_T("%s"), GetDateString());
163 break;
164
165 case _T('E'):
166 ConOutChar(_T('\x1B'));
167 break;
168
169 case _T('F'):
170 ConOutChar(_T(')'));
171 break;
172
173 case _T('G'):
174 ConOutChar(_T('>'));
175 break;
176
177 case _T('H'):
178 ConOutPuts(_T("\x08 \x08"));
179 break;
180
181 case _T('I'):
183 break;
184
185 case _T('L'):
186 ConOutChar(_T('<'));
187 break;
188
189 case _T('N'):
190 {
192 ConOutChar(szPath[0]);
193 break;
194 }
195
196 case _T('P'):
197 {
199 ConOutPrintf(_T("%s"), szPath);
200 break;
201 }
202
203 case _T('Q'):
204 ConOutChar(_T('='));
205 break;
206
207 case _T('S'):
208 ConOutChar(_T(' '));
209 break;
210
211 case _T('T'):
212 ConOutPrintf(_T("%s"), GetTimeString());
213 break;
214
215 case _T('V'):
217 break;
218
219 case _T('_'):
220 ConOutChar(_T('\n'));
221 break;
222
223 case _T('$'):
224 ConOutChar(_T('$'));
225 break;
226
227#ifdef FEATURE_DIRECTORY_STACK
228 case _T('+'):
229 {
230 INT i;
231 for (i = 0; i < GetDirectoryStackDepth(); i++)
232 ConOutChar(_T('+'));
233 break;
234 }
235#endif
236 }
237 }
238 }
239}
INT GetDirectoryStackDepth(VOID)
Definition: dirstack.c:98
VOID PrintInfoLine(VOID)
Definition: prompt.c:72

Referenced by Batch(), ExecuteCommandWithEcho(), ReadCommand(), and ReadLine().

◆ ReadCommand()

BOOL ReadCommand ( LPTSTR  str,
INT  maxlen 
)

Definition at line 138 of file cmdinput.c.

139{
141 SHORT orgx; /* origin x/y */
142 SHORT orgy;
143 SHORT curx; /*current x/y cursor position*/
144 SHORT cury;
145 SIZE_T tempscreen;
146 INT count; /*used in some for loops*/
147 INT current = 0; /*the position of the cursor in the string (str)*/
148 INT charcount = 0;/*chars in the string (str)*/
149 INPUT_RECORD ir;
150 DWORD dwControlKeyState;
151#ifdef FEATURE_UNIX_FILENAME_COMPLETION
152 WORD wLastKey = 0;
153#endif
154 TCHAR ch;
155 BOOL bReturn = FALSE;
156 BOOL bCharInput;
157#ifdef FEATURE_4NT_FILENAME_COMPLETION
159#endif
160#ifdef FEATURE_HISTORY
161 //BOOL bContinue=FALSE;/*is TRUE the second case will not be executed*/
162 TCHAR PreviousChar;
163#endif
164
166 {
167 /* No console */
169 DWORD dwRead;
170 CHAR chr;
171 do
172 {
173 if (!ReadFile(hStdin, &chr, 1, &dwRead, NULL) || !dwRead)
174 return FALSE;
175#ifdef _UNICODE
176 MultiByteToWideChar(InputCodePage, 0, &chr, 1, &str[charcount++], 1);
177#endif
178 } while (chr != '\n' && charcount < maxlen);
179 str[charcount] = _T('\0');
180 return TRUE;
181 }
182
183 /* get screen size */
184 maxx = csbi.dwSize.X;
185 maxy = csbi.dwSize.Y;
186
187 curx = orgx = csbi.dwCursorPosition.X;
188 cury = orgy = csbi.dwCursorPosition.Y;
189
190 memset (str, 0, maxlen * sizeof (TCHAR));
191
193
194 do
195 {
196 bReturn = FALSE;
197 ConInKey (&ir);
198
199 dwControlKeyState = ir.Event.KeyEvent.dwControlKeyState;
200
201 if (dwControlKeyState &
204 {
205 switch (ir.Event.KeyEvent.wVirtualKeyCode)
206 {
207#ifdef FEATURE_HISTORY
208 case _T('K'):
209 /* add the current command line to the history */
210 if (dwControlKeyState &
212 {
213 if (str[0])
214 History(0,str);
215
216 ClearCommandLine (str, maxlen, orgx, orgy);
217 current = charcount = 0;
218 curx = orgx;
219 cury = orgy;
220 //bContinue=TRUE;
221 }
222 break;
223
224 case _T('D'):
225 /* delete current history entry */
226 if (dwControlKeyState &
228 {
229 ClearCommandLine (str, maxlen, orgx, orgy);
231 current = charcount = _tcslen (str);
232 ConOutPrintf (_T("%s"), str);
233 GetCursorXY (&curx, &cury);
234 //bContinue=TRUE;
235 }
236 break;
237#endif /*FEATURE_HISTORY*/
238
239 case _T('M'):
240 /* ^M does the same as return */
241 if (dwControlKeyState &
243 {
244 /* end input, return to main */
245#ifdef FEATURE_HISTORY
246 /* add to the history */
247 if (str[0])
248 History(0, str);
249#endif /*FEATURE_HISTORY*/
250 str[charcount++] = _T('\n');
251 str[charcount] = _T('\0');
252 ConOutChar (_T('\n'));
253 bReturn = TRUE;
254 }
255 break;
256
257 case _T('H'): /* ^H does the same as VK_BACK */
258 if (dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
259 {
260 bCharInput = FALSE;
261 goto DoBackSpace;
262 }
263 break;
264 }
265 }
266
267 bCharInput = FALSE;
268
269 switch (ir.Event.KeyEvent.wVirtualKeyCode)
270 {
271 case VK_BACK:
272 DoBackSpace:
273 /* <BACKSPACE> - delete character to left of cursor */
274 if (current > 0 && charcount > 0)
275 {
276 if (current == charcount)
277 {
278 /* if at end of line */
279 str[current - 1] = _T('\0');
280 if (GetCursorX () != 0)
281 {
282 ConOutPrintf (_T("\b \b"));
283 curx--;
284 }
285 else
286 {
287 SetCursorXY ((SHORT)(maxx - 1), (SHORT)(GetCursorY () - 1));
288 ConOutChar (_T(' '));
289 SetCursorXY ((SHORT)(maxx - 1), (SHORT)(GetCursorY () - 1));
290 cury--;
291 curx = maxx - 1;
292 }
293 }
294 else
295 {
296 for (count = current - 1; count < charcount; count++)
297 str[count] = str[count + 1];
298 if (GetCursorX () != 0)
299 {
300 SetCursorXY ((SHORT)(GetCursorX () - 1), GetCursorY ());
301 curx--;
302 }
303 else
304 {
305 SetCursorXY ((SHORT)(maxx - 1), (SHORT)(GetCursorY () - 1));
306 cury--;
307 curx = maxx - 1;
308 }
309 GetCursorXY (&curx, &cury);
310 ConOutPrintf (_T("%s "), &str[current - 1]);
311 SetCursorXY (curx, cury);
312 }
313 charcount--;
314 current--;
315 }
316 break;
317
318 case VK_INSERT:
319 /* toggle insert/overstrike mode */
320 bInsert ^= TRUE;
322 break;
323
324 case VK_DELETE:
325 /* delete character under cursor */
326 if (current != charcount && charcount > 0)
327 {
328 for (count = current; count < charcount; count++)
329 str[count] = str[count + 1];
330 charcount--;
331 GetCursorXY (&curx, &cury);
332 ConOutPrintf (_T("%s "), &str[current]);
333 SetCursorXY (curx, cury);
334 }
335 break;
336
337 case VK_HOME:
338 /* goto beginning of string */
339 if (current != 0)
340 {
341 SetCursorXY (orgx, orgy);
342 curx = orgx;
343 cury = orgy;
344 current = 0;
345 }
346 break;
347
348 case VK_END:
349 /* goto end of string */
350 if (current != charcount)
351 {
352 SetCursorXY (orgx, orgy);
353 ConOutPrintf (_T("%s"), str);
354 GetCursorXY (&curx, &cury);
355 current = charcount;
356 }
357 break;
358
359 case VK_TAB:
360#ifdef FEATURE_UNIX_FILENAME_COMPLETION
361 /* expand current file name */
362 if ((current == charcount) ||
363 (current == charcount - 1 &&
364 str[current] == _T('"'))) /* only works at end of line*/
365 {
366 if (wLastKey != VK_TAB)
367 {
368 /* if first TAB, complete filename*/
369 tempscreen = charcount;
370 CompleteFilename (str, charcount);
371 charcount = _tcslen (str);
372 current = charcount;
373
374 SetCursorXY (orgx, orgy);
375 ConOutPrintf (_T("%s"), str);
376
377 if (tempscreen > charcount)
378 {
379 GetCursorXY (&curx, &cury);
380 for (count = tempscreen - charcount; count--; )
381 ConOutChar (_T(' '));
382 SetCursorXY (curx, cury);
383 }
384 else
385 {
386 if (((charcount + orgx) / maxx) + orgy > maxy - 1)
387 orgy += maxy - ((charcount + orgx) / maxx + orgy + 1);
388 }
389
390 /* set cursor position */
391 SetCursorXY ((orgx + current) % maxx,
392 orgy + (orgx + current) / maxx);
393 GetCursorXY (&curx, &cury);
394 }
395 else
396 {
397 /*if second TAB, list matches*/
398 if (ShowCompletionMatches (str, charcount))
399 {
400 PrintPrompt();
401 GetCursorXY(&orgx, &orgy);
402 ConOutPrintf(_T("%s"), str);
403
404 /* set cursor position */
405 SetCursorXY((orgx + current) % maxx,
406 orgy + (orgx + current) / maxx);
407 GetCursorXY(&curx, &cury);
408 }
409
410 }
411 }
412 else
413 {
414 MessageBeep(-1);
415 }
416#endif
417#ifdef FEATURE_4NT_FILENAME_COMPLETION
418 /* used to later see if we went down to the next line */
419 tempscreen = charcount;
420 szPath[0]=_T('\0');
421
422 /* str is the whole things that is on the current line
423 that is and and out. arg 2 is weather it goes back
424 one file or forward one file */
426 /* Attempt to clear the line */
427 ClearCommandLine (str, maxlen, orgx, orgy);
428 curx = orgx;
429 cury = orgy;
430 current = charcount = 0;
431
432 /* Everything is deleted, lets add it back in */
434
435 /* Figure out where cusor is going to be after we print it */
436 charcount = _tcslen(str);
437 current = charcount;
438
439 SetCursorXY(orgx, orgy);
440 /* Print out what we have now */
441 ConOutPrintf(_T("%s"), str);
442
443 /* Move cursor accordingly */
444 if (tempscreen > charcount)
445 {
446 GetCursorXY(&curx, &cury);
447 for(count = tempscreen - charcount; count--; )
448 ConOutChar(_T(' '));
449 SetCursorXY(curx, cury);
450 }
451 else
452 {
453 if (((charcount + orgx) / maxx) + orgy > maxy - 1)
454 orgy += maxy - ((charcount + orgx) / maxx + orgy + 1);
455 }
456 SetCursorXY((short)(((int)orgx + current) % maxx), (short)((int)orgy + ((int)orgx + current) / maxx));
457 GetCursorXY(&curx, &cury);
458#endif
459 break;
460
461 case _T('C'):
462 if ((ir.Event.KeyEvent.dwControlKeyState &
464 {
465 /* Ignore the Ctrl-C key event if it has already been handled */
466 if (!bCtrlBreak)
467 break;
468
469 /*
470 * Fully print the entered string
471 * so the command prompt would not overwrite it.
472 */
473 SetCursorXY(orgx, orgy);
474 ConOutPrintf(_T("%s"), str);
475
476 /*
477 * A Ctrl-C. Do not clear the command line,
478 * but return an empty string in str.
479 */
480 str[0] = _T('\0');
481 curx = orgx;
482 cury = orgy;
483 current = charcount = 0;
484 bReturn = TRUE;
485 }
486 else
487 {
488 /* Just a normal 'C' character */
489 bCharInput = TRUE;
490 }
491 break;
492
493 case VK_RETURN:
494 /* end input, return to main */
495#ifdef FEATURE_HISTORY
496 /* add to the history */
497 if (str[0])
498 History(0, str);
499#endif
500 str[charcount++] = _T('\n');
501 str[charcount] = _T('\0');
502 ConOutChar(_T('\n'));
503 bReturn = TRUE;
504 break;
505
506 case VK_ESCAPE:
507 /* clear str Make this callable! */
508 ClearCommandLine (str, maxlen, orgx, orgy);
509 curx = orgx;
510 cury = orgy;
511 current = charcount = 0;
512 break;
513
514#ifdef FEATURE_HISTORY
515 case VK_F3:
517#endif
518 case VK_UP:
519#ifdef FEATURE_HISTORY
520 /* get previous command from buffer */
521 ClearCommandLine (str, maxlen, orgx, orgy);
522 History(-1, str);
523 current = charcount = _tcslen (str);
524 if (((charcount + orgx) / maxx) + orgy > maxy - 1)
525 orgy += maxy - ((charcount + orgx) / maxx + orgy + 1);
526 ConOutPrintf (_T("%s"), str);
527 GetCursorXY (&curx, &cury);
528#endif
529 break;
530
531 case VK_DOWN:
532#ifdef FEATURE_HISTORY
533 /* get next command from buffer */
534 ClearCommandLine (str, maxlen, orgx, orgy);
535 History(1, str);
536 current = charcount = _tcslen (str);
537 if (((charcount + orgx) / maxx) + orgy > maxy - 1)
538 orgy += maxy - ((charcount + orgx) / maxx + orgy + 1);
539 ConOutPrintf (_T("%s"), str);
540 GetCursorXY (&curx, &cury);
541#endif
542 break;
543
544 case VK_LEFT:
545 if (dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
546 {
547 /* move cursor to the previous word */
548 if (current > 0)
549 {
550 while (current > 0 && str[current - 1] == _T(' '))
551 {
552 current--;
553 if (curx == 0)
554 {
555 cury--;
556 curx = maxx -1;
557 }
558 else
559 {
560 curx--;
561 }
562 }
563
564 while (current > 0 && str[current -1] != _T(' '))
565 {
566 current--;
567 if (curx == 0)
568 {
569 cury--;
570 curx = maxx -1;
571 }
572 else
573 {
574 curx--;
575 }
576 }
577
578 SetCursorXY(curx, cury);
579 }
580 }
581 else
582 {
583 /* move cursor left */
584 if (current > 0)
585 {
586 current--;
587 if (GetCursorX () == 0)
588 {
589 SetCursorXY ((SHORT)(maxx - 1), (SHORT)(GetCursorY () - 1));
590 curx = maxx - 1;
591 cury--;
592 }
593 else
594 {
595 SetCursorXY ((SHORT)(GetCursorX () - 1), GetCursorY ());
596 curx--;
597 }
598 }
599 else
600 {
601 MessageBeep (-1);
602 }
603 }
604 break;
605
606 case VK_RIGHT:
607 if (dwControlKeyState & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
608 {
609 /* move cursor to the next word */
610 if (current != charcount)
611 {
612 while (current != charcount && str[current] != _T(' '))
613 {
614 current++;
615 if (curx == maxx - 1)
616 {
617 cury++;
618 curx = 0;
619 }
620 else
621 {
622 curx++;
623 }
624 }
625
626 while (current != charcount && str[current] == _T(' '))
627 {
628 current++;
629 if (curx == maxx - 1)
630 {
631 cury++;
632 curx = 0;
633 }
634 else
635 {
636 curx++;
637 }
638 }
639
640 SetCursorXY(curx, cury);
641 }
642 }
643 else
644 {
645 /* move cursor right */
646 if (current != charcount)
647 {
648 current++;
649 if (GetCursorX () == maxx - 1)
650 {
651 SetCursorXY (0, (SHORT)(GetCursorY () + 1));
652 curx = 0;
653 cury++;
654 }
655 else
656 {
657 SetCursorXY ((SHORT)(GetCursorX () + 1), GetCursorY ());
658 curx++;
659 }
660 }
661#ifdef FEATURE_HISTORY
662 else
663 {
665 if (last && charcount < (INT)_tcslen (last))
666 {
667 PreviousChar = last[current];
668 ConOutChar(PreviousChar);
669 GetCursorXY(&curx, &cury);
670 str[current++] = PreviousChar;
671 charcount++;
672 }
673 }
674#endif
675 }
676 break;
677
678 default:
679 /* This input is just a normal char */
680 bCharInput = TRUE;
681
682 }
683#ifdef _UNICODE
685 if (ch >= 32 && (charcount != (maxlen - 2)) && bCharInput)
686#else
688 if ((UCHAR)ch >= 32 && (charcount != (maxlen - 2)) && bCharInput)
689#endif /* _UNICODE */
690 {
691 /* insert character into string... */
692 if (bInsert && current != charcount)
693 {
694 /* If this character insertion will cause screen scrolling,
695 * adjust the saved origin of the command prompt. */
696 tempscreen = _tcslen(str + current) + curx;
697 if ((tempscreen % maxx) == (maxx - 1) &&
698 (tempscreen / maxx) + cury == (maxy - 1))
699 {
700 orgy--;
701 cury--;
702 }
703
704 for (count = charcount; count > current; count--)
705 str[count] = str[count - 1];
706 str[current++] = ch;
707 if (curx == maxx - 1)
708 curx = 0, cury++;
709 else
710 curx++;
711 ConOutPrintf (_T("%s"), &str[current - 1]);
712 SetCursorXY (curx, cury);
713 charcount++;
714 }
715 else
716 {
717 if (current == charcount)
718 charcount++;
719 str[current++] = ch;
720 if (GetCursorX () == maxx - 1 && GetCursorY () == maxy - 1)
721 orgy--, cury--;
722 if (GetCursorX () == maxx - 1)
723 curx = 0, cury++;
724 else
725 curx++;
726 ConOutChar (ch);
727 }
728 }
729
730 //wLastKey = ir.Event.KeyEvent.wVirtualKeyCode;
731 }
732 while (!bReturn);
733
735
736#ifdef FEATURE_ALIASES
737 /* expand all aliases */
738 ExpandAlias (str, maxlen);
739#endif /* FEATURE_ALIAS */
740 return TRUE;
741}
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:595
VOID ExpandAlias(LPTSTR cmd, INT maxlen)
Definition: alias.c:89
VOID PrintPrompt(VOID)
Definition: prompt.c:109
SHORT GetCursorX(VOID)
Definition: console.c:210
VOID GetCursorXY(PSHORT x, PSHORT y)
Definition: console.c:200
VOID SetCursorType(BOOL bInsert, BOOL bVisible)
Definition: console.c:226
VOID History_move_to_bottom(VOID)
Definition: history.c:280
VOID History(INT dir, LPTSTR commandline)
Definition: history.c:326
VOID History_del_current_entry(LPTSTR str)
Definition: history.c:175
LPCTSTR PeekHistory(INT dir)
Definition: history.c:287
static BOOL bInsert
Definition: cmdinput.c:121
static VOID ClearCommandLine(LPTSTR str, INT maxlen, SHORT orgx, SHORT orgy)
Definition: cmdinput.c:125
HANDLE hStdin
Definition: ctm.c:55
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define MultiByteToWideChar
Definition: compat.h:110
VOID CompleteFilename(LPTSTR strIN, BOOL bNext, LPTSTR strOut, UINT cusor)
Definition: filecomp.c:545
GLuint GLuint GLsizei count
Definition: gl.h:1545
struct task_struct * current
Definition: linux.c:32
static UINT UINT last
Definition: font.c:45
const WCHAR * str
SHORT Y
Definition: blue.h:27
SHORT X
Definition: blue.h:26
#define SHIFT_PRESSED
Definition: wincon.h:141
#define RIGHT_ALT_PRESSED
Definition: wincon.h:137
#define LEFT_ALT_PRESSED
Definition: wincon.h:138
#define VK_TAB
Definition: winuser.h:2199
#define VK_UP
Definition: winuser.h:2225
BOOL WINAPI MessageBeep(_In_ UINT uType)
#define VK_RETURN
Definition: winuser.h:2201
#define VK_END
Definition: winuser.h:2222
#define VK_HOME
Definition: winuser.h:2223
#define VK_BACK
Definition: winuser.h:2198
#define VK_F3
Definition: winuser.h:2257
#define VK_LEFT
Definition: winuser.h:2224
#define VK_RIGHT
Definition: winuser.h:2226
#define VK_DOWN
Definition: winuser.h:2227
#define VK_DELETE
Definition: winuser.h:2233
#define VK_INSERT
Definition: winuser.h:2232
unsigned char UCHAR
Definition: xmlstorage.h:181
char CHAR
Definition: xmlstorage.h:175

◆ ReadLine()

BOOL ReadLine ( TCHAR commandline,
BOOL  bMore 
)

Definition at line 1721 of file cmd.c.

1722{
1724 LPTSTR ip;
1725
1726 /* if no batch input then... */
1727 if (bc == NULL)
1728 {
1729 if (bMore)
1730 {
1732 }
1733 else
1734 {
1735 /* JPP 19980807 - if echo off, don't print prompt */
1736 if (bEcho)
1737 {
1738 if (!bIgnoreEcho)
1739 ConOutChar(_T('\n'));
1740 PrintPrompt();
1741 }
1742 }
1743
1745 {
1746 bExit = TRUE;
1747 return FALSE;
1748 }
1749
1750 if (readline[0] == _T('\0'))
1751 ConOutChar(_T('\n'));
1752
1754 return FALSE;
1755
1756 if (readline[0] == _T('\0'))
1757 return FALSE;
1758
1759 ip = readline;
1760 }
1761 else
1762 {
1763 ip = ReadBatchLine();
1764 if (!ip)
1765 return FALSE;
1766 }
1767
1768 return SubstituteVars(ip, commandline, _T('%'));
1769}
static logline * readline(FILE *inf, adns_state adns, int opts)
Definition: adnslogres.c:145
LPTSTR ReadBatchLine(VOID)
Definition: batch.c:564
#define STRING_MORE
Definition: resource.h:239
static BOOL ReadCommand(PCONSOLE_STATE State, LPSTR str, INT maxlen)
Definition: cmdcons.c:735
Definition: dhcpd.h:62

Referenced by ParseChar(), and ParseCommand().

◆ RemoveBreakHandler()

VOID RemoveBreakHandler ( VOID  )

Definition at line 1850 of file cmd.c.

Referenced by Cleanup(), FilePromptYN(), FilePromptYNA(), and PagePrompt().

◆ RunFile()

HANDLE RunFile ( DWORD  flags,
LPTSTR  filename,
LPTSTR  params,
LPTSTR  directory,
INT  show 
)

Definition at line 266 of file cmd.c.

268{
271 MYEX hShExt;
272 BOOL ret;
273
274 TRACE ("RunFile(%s)\n", debugstr_aw(filename));
275 hShell32 = LoadLibrary(_T("SHELL32.DLL"));
276 if (!hShell32)
277 {
278 WARN ("RunFile: couldn't load SHELL32.DLL!\n");
279 return NULL;
280 }
281
283 if (!hShExt)
284 {
285 WARN ("RunFile: couldn't find ShellExecuteExA/W in SHELL32.DLL!\n");
287 return NULL;
288 }
289
290 TRACE ("RunFile: ShellExecuteExA/W is at %x\n", hShExt);
291
292 memset(&sei, 0, sizeof sei);
293 sei.cbSize = sizeof sei;
294 sei.fMask = flags;
295 sei.lpFile = filename;
296 sei.lpParameters = params;
298 sei.nShow = show;
299 ret = hShExt(&sei);
300
301 TRACE ("RunFile: ShellExecuteExA/W returned 0x%p\n", ret);
302
304 return ret ? sei.hProcess : NULL;
305}
BOOL(WINAPI * MYEX)(LPSHELLEXECUTEINFO lpExecInfo)
Definition: cmd.c:264
#define SHELLEXECUTETEXT
Definition: cmd.c:261
int(* FARPROC)()
Definition: compat.h:36
#define FreeLibrary(x)
Definition: compat.h:748
const char * filename
Definition: ioapi.h:137
static HMODULE hShell32
Definition: string.c:34
LPCSTR lpParameters
Definition: shellapi.h:313
LPCSTR lpDirectory
Definition: shellapi.h:314
#define LoadLibrary
Definition: winbase.h:3797

Referenced by cmd_start(), and Execute().

◆ SearchForExecutable()

BOOL SearchForExecutable ( LPCTSTR  pFileName,
LPTSTR  pFullName 
)

Definition at line 142 of file where.c.

143{
144 static TCHAR pszDefaultPathExt[] = _T(".com;.exe;.bat;.cmd");
145 LPTSTR pszPathExt, pszPath;
146 LPTSTR pCh;
147 DWORD dwBuffer;
148 TRACE ("SearchForExecutable: \'%s\'\n", debugstr_aw(pFileName));
149
150 /* load environment variable PATHEXT */
151 pszPathExt = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
152 if (!pszPathExt)
153 {
154 WARN("Cannot allocate memory for pszPathExt!\n");
155 return FALSE;
156 }
157
158 dwBuffer = GetEnvironmentVariable (_T("PATHEXT"), pszPathExt, ENV_BUFFER_SIZE);
159 if (dwBuffer > ENV_BUFFER_SIZE)
160 {
161 LPTSTR pszOldPathExt = pszPathExt;
162 pszPathExt = (LPTSTR)cmd_realloc (pszPathExt, dwBuffer * sizeof (TCHAR));
163 if (!pszPathExt)
164 {
165 WARN("Cannot reallocate memory for pszPathExt!\n");
166 cmd_free(pszOldPathExt);
167 return FALSE;
168 }
169 GetEnvironmentVariable (_T("PATHEXT"), pszPathExt, dwBuffer);
170 _tcslwr(pszPathExt);
171 }
172 else if (0 == dwBuffer)
173 {
174 _tcscpy(pszPathExt, pszDefaultPathExt);
175 }
176 else
177 {
178 _tcslwr(pszPathExt);
179 }
180
181 /* Check if valid directly on specified path */
182 if (SearchForExecutableSingle(pFileName, pFullName, pszPathExt, NULL))
183 {
184 cmd_free(pszPathExt);
185 return TRUE;
186 }
187
188 /* If an explicit directory was given, stop here - no need to search PATH. */
189 if (pFileName[1] == _T(':') || _tcschr(pFileName, _T('\\')))
190 {
191 cmd_free(pszPathExt);
192 return FALSE;
193 }
194
195 /* load environment variable PATH into buffer */
196 pszPath = (LPTSTR)cmd_alloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
197 if (!pszPath)
198 {
199 WARN("Cannot allocate memory for pszPath!\n");
200 return FALSE;
201 }
202
203 dwBuffer = GetEnvironmentVariable (_T("PATH"), pszPath, ENV_BUFFER_SIZE);
204 if (dwBuffer > ENV_BUFFER_SIZE)
205 {
206 LPTSTR pszOldPath = pszPath;
207 pszPath = (LPTSTR)cmd_realloc (pszPath, dwBuffer * sizeof (TCHAR));
208 if (!pszPath)
209 {
210 WARN("Cannot reallocate memory for pszPath!\n");
211 cmd_free(pszOldPath);
212 cmd_free(pszPathExt);
213 return FALSE;
214 }
215 GetEnvironmentVariable (_T("PATH"), pszPath, dwBuffer);
216 }
217
218 TRACE ("SearchForExecutable(): Loaded PATH: %s\n", debugstr_aw(pszPath));
219
220 /* search in PATH */
221 pCh = _tcstok(pszPath, _T(";"));
222 while (pCh)
223 {
224 if (SearchForExecutableSingle(pFileName, pFullName, pszPathExt, pCh))
225 {
226 cmd_free(pszPath);
227 cmd_free(pszPathExt);
228 return TRUE;
229 }
230 pCh = _tcstok(NULL, _T(";"));
231 }
232
233 cmd_free(pszPath);
234 cmd_free(pszPathExt);
235 return FALSE;
236}
#define ENV_BUFFER_SIZE
Definition: where.c:80
BOOL SearchForExecutableSingle(LPCTSTR pFileName, LPTSTR pFullName, LPTSTR pPathExt, LPTSTR pDirectory)
Definition: where.c:86
#define _tcslwr
Definition: tchar.h:1465
#define _tcstok
Definition: tchar.h:1416

Referenced by cmd_start(), Execute(), and GetCmdLineCommand().

◆ SetHandle()

VOID SetHandle ( UINT  Number,
HANDLE  Handle 
)

Definition at line 50 of file redir.c.

51{
52 if (Number < 3)
53 {
55 /* Synchronize the associated Win32 handle */
57 }
58 else if (Number < ARRAYSIZE(ExtraHandles) + 3)
60}
BOOL WINAPI DECLSPEC_HOTPATCH SetStdHandle(DWORD nStdHandle, HANDLE hHandle)
Definition: console.c:1213
ULONG Handle
Definition: gdb_input.c:15
BOOL ConStreamSetOSHandle(IN PCON_STREAM Stream, IN HANDLE Handle)
Definition: stream.c:263

Referenced by cmd_ctty(), PerformRedirection(), and UndoRedirection().

◆ SetRootPath()

BOOL SetRootPath ( TCHAR oldpath,
TCHAR InPath 
)

Definition at line 182 of file internal.c.

183{
184 DWORD dwLastError;
185 TCHAR OutPath[MAX_PATH];
186 TCHAR OutPathTemp[MAX_PATH];
187
188 StripQuotes(InPath);
189
190 /* Retrieve the full path name from the (possibly relative) InPath */
191 if (GetFullPathName(InPath, ARRAYSIZE(OutPathTemp), OutPathTemp, NULL) == 0)
192 {
193 dwLastError = GetLastError();
194 goto Fail;
195 }
196
198 {
199 /*
200 * Convert the full path to its correct case, and
201 * resolve any wilcard present as well in the path
202 * and retrieve the first result.
203 * Example: c:\windows\SYSTEM32 => C:\WINDOWS\System32
204 * Example: C:\WINDOWS\S* => C:\WINDOWS\System,
205 * or C:\WINDOWS\System32, depending on the user's OS.
206 */
207 GetPathCase(OutPathTemp, OutPath);
208 }
209 else
210 {
211 _tcscpy(OutPath, OutPathTemp);
212 }
213
214 /* Use _tchdir(), since unlike SetCurrentDirectory() it updates
215 * the current-directory-on-drive environment variables. */
216 if (_tchdir(OutPath) != 0)
217 {
218 dwLastError = GetLastError();
219 if (dwLastError == ERROR_FILE_NOT_FOUND)
220 dwLastError = ERROR_PATH_NOT_FOUND;
221 goto Fail;
222 }
223
224 /* Keep the original drive in ordinary CD/CHDIR (without /D switch) */
225 if (oldpath != NULL && _tcsncicmp(OutPath, oldpath, 2) != 0)
226 SetCurrentDirectory(oldpath);
227
228 return TRUE;
229
230Fail:
231 ConErrFormatMessage(dwLastError);
232 nErrorLevel = 1;
233 return FALSE;
234}
VOID GetPathCase(TCHAR *, TCHAR *)
Definition: misc.c:86
#define ConErrFormatMessage(MessageId,...)
Definition: console.h:56
int Fail
Definition: ehthrow.cxx:24

Referenced by cmd_chdir(), and CommandPushd().

◆ split()

LPTSTR * split ( LPTSTR  s,
LPINT  args,
BOOL  expand_wildcards,
BOOL  handle_plus 
)

Definition at line 282 of file misc.c.

283{
284 LPTSTR *arg;
286 LPTSTR q;
287 INT ac;
288 INT_PTR len;
289
290 arg = cmd_alloc (sizeof (LPTSTR));
291 if (!arg)
292 {
293 WARN("Cannot allocate memory for arg!\n");
294 return NULL;
295 }
296 *arg = NULL;
297
298 ac = 0;
299 while (*s)
300 {
301 BOOL bQuoted = FALSE;
302
303 /* skip leading spaces */
304 while (*s && (_istspace(*s) || _istcntrl(*s)))
305 ++s;
306
307 start = s;
308
309 /* the first character can be '/' */
310 if (*s == _T('/'))
311 ++s;
312
313 /* skip to next word delimiter or start of next option */
314 while (_istprint(*s))
315 {
316 /* if quote (") then set bQuoted */
317 bQuoted ^= (*s == _T('\"'));
318
319 /* Check if we have unquoted text */
320 if (!bQuoted)
321 {
322 /* check for separators */
323 if (_istspace(*s) ||
324 (*s == _T('/')) ||
325 (handle_plus && (*s == _T('+'))))
326 {
327 /* Make length at least one character */
328 if (s == start) s++;
329 break;
330 }
331 }
332
333 ++s;
334 }
335
336 /* a word was found */
337 if (s != start)
338 {
339 q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR));
340 if (!q)
341 {
342 WARN("Cannot allocate memory for q!\n");
343 return NULL;
344 }
345 memcpy (q, start, len * sizeof (TCHAR));
346 q[len] = _T('\0');
347 StripQuotes(q);
348 if (expand_wildcards && (_T('/') != *start) &&
349 (NULL != _tcschr(q, _T('*')) || NULL != _tcschr(q, _T('?'))))
350 {
351 if (! expand(&ac, &arg, q))
352 {
353 cmd_free (q);
354 freep (arg);
355 return NULL;
356 }
357 }
358 else
359 {
360 if (! add_entry(&ac, &arg, q))
361 {
362 cmd_free (q);
363 freep (arg);
364 return NULL;
365 }
366 }
367 cmd_free (q);
368 }
369 }
370
371 *args = ac;
372
373 return arg;
374}
VOID freep(LPTSTR *p)
Definition: misc.c:446
static BOOL expand(LPINT ac, LPTSTR **arg, LPCTSTR pattern)
Definition: misc.c:214
BOOL add_entry(LPINT ac, LPTSTR **arg, LPCTSTR entry)
Definition: misc.c:184
VOID StripQuotes(TCHAR *in)
Definition: misc.c:467
GLuint start
Definition: gl.h:1545
#define _istprint
Definition: tchar.h:1500

◆ splitspace()

LPTSTR * splitspace ( LPTSTR  s,
LPINT  args 
)

Definition at line 381 of file misc.c.

382{
383 LPTSTR *arg;
385 LPTSTR q;
386 INT ac;
387 INT_PTR len;
388
389 arg = cmd_alloc (sizeof (LPTSTR));
390 if (!arg)
391 {
392 WARN("Cannot allocate memory for arg!\n");
393 return NULL;
394 }
395 *arg = NULL;
396
397 ac = 0;
398 while (*s)
399 {
400 BOOL bQuoted = FALSE;
401
402 /* skip leading spaces */
403 while (*s && (_istspace (*s) || _istcntrl (*s)))
404 ++s;
405
406 start = s;
407
408 /* skip to next word delimiter or start of next option */
409 while (_istprint(*s) && (bQuoted || !_istspace(*s)))
410 {
411 /* if quote (") then set bQuoted */
412 bQuoted ^= (*s == _T('\"'));
413 ++s;
414 }
415
416 /* a word was found */
417 if (s != start)
418 {
419 q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR));
420 if (!q)
421 {
422 WARN("Cannot allocate memory for q!\n");
423 return NULL;
424 }
425 memcpy (q, start, len * sizeof (TCHAR));
426 q[len] = _T('\0');
427 StripQuotes(q);
428 if (! add_entry(&ac, &arg, q))
429 {
430 cmd_free (q);
431 freep (arg);
432 return NULL;
433 }
434 cmd_free (q);
435 }
436 }
437
438 *args = ac;
439
440 return arg;
441}

Referenced by cmd_move(), and cmd_setlocal().

◆ StringToColor()

BOOL StringToColor ( LPWORD  lpColor,
LPTSTR str 
)

Definition at line 255 of file strtoclr.c.

256{
257 WORD wRet;
258
259 wRet = str_to_color (str);
260 if (wRet == (WORD)-1)
261 {
262 wRet=hex_clr (*str);
263 chop_blank (str);
264 if (wRet == (WORD)-1)
265 return FALSE;
266 }
267
268 *lpColor = wRet;
269
270 return TRUE;
271}
static INT chop_blank(LPTSTR *arg_str)
Definition: strtoclr.c:93
static WORD hex_clr(LPTSTR str)
Definition: strtoclr.c:125
static WORD str_to_color(LPTSTR *arg_str)
Definition: strtoclr.c:181

Referenced by CommandColor().

◆ StripQuotes()

VOID StripQuotes ( LPTSTR  )

◆ SubstituteForVars()

BOOL SubstituteForVars ( IN PCTSTR  Src,
OUT PTSTR  Dest 
)

Definition at line 1596 of file cmd.c.

1599{
1600 PTCHAR DestEnd = &Dest[CMDLINE_LENGTH - 1];
1601 while (*Src)
1602 {
1603 if (Src[0] == _T('%'))
1604 {
1605 BOOL Dummy;
1606 PCTSTR End = &Src[2];
1607 PCTSTR Value = NULL;
1608
1609 if (Src[1] == _T('~'))
1611
1612 if (!Value && Src[1])
1613 {
1614 if (FindForVar(Src[1], &Value, &Dummy) && !Value)
1615 {
1616 /* The variable is empty, return an empty string */
1617 Value = _T("");
1618 }
1619 }
1620
1621 if (Value)
1622 {
1623 if (Dest + _tcslen(Value) > DestEnd)
1624 return FALSE;
1625 Dest = _stpcpy(Dest, Value);
1626 Src = End;
1627 continue;
1628 }
1629 }
1630 /* Not a variable; just copy the character */
1631 if (Dest >= DestEnd)
1632 return FALSE;
1633 *Dest++ = *Src++;
1634 }
1635 *Dest = _T('\0');
1636 return TRUE;
1637}
static BOOL FindForVar(IN TCHAR Var, OUT PCTSTR *VarPtr, OUT BOOL *IsParam0)
Definition: cmd.c:1574
static PCTSTR GetEnhancedVar(IN OUT PCTSTR *pFormat, IN BOOL(*GetVar)(TCHAR, PCTSTR *, BOOL *))
Definition: cmd.c:975
LPTSTR _stpcpy(LPTSTR, LPCTSTR)
Definition: misc.c:460
LPCSTR PCTSTR
Definition: ntbasedef.h:488

Referenced by DoDelayedExpansion(), EchoCommand(), and UnparseCommand().

◆ SubstituteVar()

BOOL SubstituteVar ( IN PCTSTR  Src,
OUT size_t SrcIncLen,
OUT PTCHAR  Dest,
IN PTCHAR  DestEnd,
OUT size_t DestIncLen,
IN TCHAR  Delim 
)

Definition at line 1326 of file cmd.c.

1333{
1334#define APPEND(From, Length) \
1335do { \
1336 if (Dest + (Length) > DestEnd) \
1337 goto too_long; \
1338 memcpy(Dest, (From), (Length) * sizeof(TCHAR)); \
1339 Dest += (Length); \
1340} while (0)
1341
1342#define APPEND1(Char) \
1343do { \
1344 if (Dest >= DestEnd) \
1345 goto too_long; \
1346 *Dest++ = (Char); \
1347} while (0)
1348
1349 PCTSTR Var;
1350 PCTSTR Start, End, SubstStart;
1351 TCHAR EndChr;
1352 size_t VarLength;
1353
1354 Start = Src;
1355 End = Dest;
1356 *SrcIncLen = 0;
1357 *DestIncLen = 0;
1358
1359 if (!Delim)
1360 return FALSE;
1361 if (*Src != Delim)
1362 return FALSE;
1363
1364 ++Src;
1365
1366 /* If we are already at the end of the string, fail the substitution */
1367 SubstStart = Src;
1368 if (!*Src || *Src == _T('\r') || *Src == _T('\n'))
1369 goto bad_subst;
1370
1371 if (bc && Delim == _T('%'))
1372 {
1373 UINT NameLen;
1374 Var = GetBatchVar(Src, &NameLen);
1375 if (!Var && bParseError)
1376 {
1377 /* Return the partially-parsed command to be
1378 * echoed for error diagnostics purposes. */
1379 APPEND1(Delim);
1380 APPEND(Src, _tcslen(Src) + 1);
1381 return FALSE;
1382 }
1383 if (Var != NULL)
1384 {
1385 VarLength = _tcslen(Var);
1386 APPEND(Var, VarLength);
1387 Src += NameLen;
1388 goto success;
1389 }
1390 }
1391
1392 /* Find the end of the variable name. A colon (:) will usually
1393 * end the name and begin the optional modifier, but not if it
1394 * is immediately followed by the delimiter (%VAR:%). */
1395 SubstStart = Src;
1396 while (*Src && *Src != Delim && !(*Src == _T(':') && Src[1] != Delim))
1397 {
1398 ++Src;
1399 }
1400 /* If we are either at the end of the string, or the delimiter
1401 * has been repeated more than once, fail the substitution. */
1402 if (!*Src || Src == SubstStart)
1403 goto bad_subst;
1404
1405 EndChr = *Src;
1406 *(PTSTR)Src = _T('\0'); // FIXME: HACK!
1407 Var = GetEnvVarOrSpecial(SubstStart);
1408 *(PTSTR)Src++ = EndChr;
1409 if (Var == NULL)
1410 {
1411 /* In a batch context, %NONEXISTENT% "expands" to an
1412 * empty string, otherwise fail the substitution. */
1413 if (bc)
1414 goto success;
1415 goto bad_subst;
1416 }
1417 VarLength = _tcslen(Var);
1418
1419 if (EndChr == Delim)
1420 {
1421 /* %VAR% - use as-is */
1422 APPEND(Var, VarLength);
1423 }
1424 else if (*Src == _T('~'))
1425 {
1426 /* %VAR:~[start][,length]% - Substring.
1427 * Negative values are offsets from the end.
1428 */
1429 SSIZE_T Start = _tcstol(Src + 1, (PTSTR*)&Src, 0);
1430 SSIZE_T End = (SSIZE_T)VarLength;
1431 if (Start < 0)
1432 Start += VarLength;
1433 Start = min(max(Start, 0), VarLength);
1434 if (*Src == _T(','))
1435 {
1436 End = _tcstol(Src + 1, (PTSTR*)&Src, 0);
1437 End += (End < 0) ? VarLength : Start;
1438 End = min(max(End, Start), VarLength);
1439 }
1440 if (*Src++ != Delim)
1441 goto bad_subst;
1442 APPEND(&Var[Start], End - Start);
1443 }
1444 else
1445 {
1446 /* %VAR:old=new% - Replace all occurrences of old with new.
1447 * %VAR:*old=new% - Replace first occurrence only,
1448 * and remove everything before it.
1449 */
1450 PCTSTR Old, New;
1451 size_t OldLength, NewLength;
1452 BOOL Star = FALSE;
1453 size_t LastMatch = 0, i = 0;
1454
1455 if (*Src == _T('*'))
1456 {
1457 Star = TRUE;
1458 Src++;
1459 }
1460
1461 /* The string to replace may contain the delimiter */
1462 Src = _tcschr(Old = Src, _T('='));
1463 if (Src == NULL)
1464 goto bad_subst;
1465 OldLength = Src++ - Old;
1466 if (OldLength == 0)
1467 goto bad_subst;
1468
1469 Src = _tcschr(New = Src, Delim);
1470 if (Src == NULL)
1471 goto bad_subst;
1472 NewLength = Src++ - New;
1473
1474 while (i < VarLength)
1475 {
1476 if (_tcsnicmp(&Var[i], Old, OldLength) == 0)
1477 {
1478 if (!Star)
1479 APPEND(&Var[LastMatch], i - LastMatch);
1481 i += OldLength;
1482 LastMatch = i;
1483 if (Star)
1484 break;
1485 continue;
1486 }
1487 i++;
1488 }
1489 APPEND(&Var[LastMatch], VarLength - LastMatch);
1490 }
1491
1492success:
1493 *SrcIncLen = (Src - Start);
1494 *DestIncLen = (Dest - End);
1495 return TRUE;
1496
1497bad_subst:
1498 Src = SubstStart;
1499 /* Only if no batch context active do we echo the delimiter */
1500 if (!bc)
1501 APPEND1(Delim);
1502 goto success;
1503
1504too_long:
1506 nErrorLevel = 9023;
1507 return FALSE;
1508
1509#undef APPEND
1510#undef APPEND1
1511}
static USHORT USHORT * NewLength
#define APPEND(From, Length)
static PCTSTR GetBatchVar(IN PCTSTR varName, OUT PUINT varNameLen)
Definition: cmd.c:1273
LONG_PTR SSIZE_T
Definition: basetsd.h:181
#define min(a, b)
Definition: monoChain.cc:55
#define New(t)
Definition: rtf.h:1086
#define max(a, b)
Definition: svc.c:63
@ Start
Definition: partlist.h:33
#define success(from, fromstr, to, tostr)

Referenced by DoDelayedExpansion(), and SubstituteVars().

◆ SubstituteVars()

BOOL SubstituteVars ( IN PCTSTR  Src,
OUT PTSTR  Dest,
IN TCHAR  Delim 
)

Definition at line 1514 of file cmd.c.

1518{
1519#define APPEND(From, Length) \
1520do { \
1521 if (Dest + (Length) > DestEnd) \
1522 goto too_long; \
1523 memcpy(Dest, (From), (Length) * sizeof(TCHAR)); \
1524 Dest += (Length); \
1525} while (0)
1526
1527#define APPEND1(Char) \
1528do { \
1529 if (Dest >= DestEnd) \
1530 goto too_long; \
1531 *Dest++ = (Char); \
1532} while (0)
1533
1534 PTCHAR DestEnd = Dest + CMDLINE_LENGTH - 1;
1535 PCTSTR End;
1536 size_t SrcIncLen, DestIncLen;
1537
1538 while (*Src /* && (Dest < DestEnd) */)
1539 {
1540 if (*Src != Delim)
1541 {
1542 End = _tcschr(Src, Delim);
1543 if (End == NULL)
1544 End = Src + _tcslen(Src);
1545 APPEND(Src, End - Src);
1546 Src = End;
1547 continue;
1548 }
1549
1550 if (!SubstituteVar(Src, &SrcIncLen, Dest, DestEnd, &DestIncLen, Delim))
1551 {
1552 return FALSE;
1553 }
1554 else
1555 {
1556 Src += SrcIncLen;
1557 Dest += DestIncLen;
1558 }
1559 }
1560 APPEND1(_T('\0'));
1561 return TRUE;
1562
1563too_long:
1565 nErrorLevel = 9023;
1566 return FALSE;
1567
1568#undef APPEND
1569#undef APPEND1
1570}

Referenced by ParseCommand(), and ReadLine().

◆ UndoRedirection()

VOID UndoRedirection ( REDIRECTION Redir,
REDIRECTION End 
)

Definition at line 142 of file redir.c.

143{
144 for (; Redir != End; Redir = Redir->Next)
145 {
147 SetHandle(Redir->Number, Redir->OldHandle);
149 }
150}

Referenced by ExecuteCommand(), ExitBatch(), and PerformRedirection().

◆ UnparseCommand()

PTCHAR UnparseCommand ( IN PARSED_COMMAND Cmd,
OUT PTCHAR  Out,
IN PTCHAR  OutEnd 
)

Definition at line 1965 of file parser.c.

1969{
1970/*
1971 * Since this function has the annoying requirement that it must avoid
1972 * overflowing the supplied buffer, define some helper macros to make
1973 * this less painful.
1974 */
1975#define CHAR(Char) \
1976do { \
1977 if (Out == OutEnd) return NULL; \
1978 *Out++ = Char; \
1979} while (0)
1980#define STRING(String) \
1981do { \
1982 if (Out + _tcslen(String) > OutEnd) return NULL; \
1983 Out = _stpcpy(Out, String); \
1984} while (0)
1985#define PRINTF(Format, ...) \
1986do { \
1987 UINT Len = _sntprintf(Out, OutEnd - Out, Format, __VA_ARGS__); \
1988 if (Len > (UINT)(OutEnd - Out)) return NULL; \
1989 Out += Len; \
1990} while (0)
1991#define RECURSE(Subcommand) \
1992do { \
1993 Out = UnparseCommand(Subcommand, Out, OutEnd); \
1994 if (!Out) return NULL; \
1995} while (0)
1996
1997 PARSED_COMMAND* Sub;
1998 REDIRECTION* Redir;
1999
2000 if (!Cmd)
2001 return Out;
2002
2003 switch (Cmd->Type)
2004 {
2005 case C_COMMAND:
2006 case C_REM:
2007 {
2008 /* This is fragile since there could be special characters, but
2009 * Windows doesn't bother escaping them, so for compatibility
2010 * we probably shouldn't do it either */
2011 if (!SubstituteForVars(Cmd->Command.First, TempBuf)) return NULL;
2012 STRING(TempBuf);
2013 if (!SubstituteForVars(Cmd->Command.Rest, TempBuf)) return NULL;
2014 STRING(TempBuf);
2015 break;
2016 }
2017
2018 case C_QUIET:
2019 {
2020 CHAR(_T('@'));
2021 RECURSE(Cmd->Subcommands);
2022 break;
2023 }
2024
2025 case C_BLOCK:
2026 {
2027 CHAR(_T('('));
2028 for (Sub = Cmd->Subcommands; Sub; Sub = Sub->Next)
2029 {
2030 RECURSE(Sub);
2031 if (Sub->Next)
2032 CHAR(_T('&'));
2033 }
2034 CHAR(_T(')'));
2035 break;
2036 }
2037
2038 case C_MULTI:
2039 case C_OR:
2040 case C_AND:
2041 case C_PIPE:
2042 {
2043 Sub = Cmd->Subcommands;
2044 RECURSE(Sub);
2045 PRINTF(_T(" %s "), OpString[Cmd->Type - C_OP_LOWEST]);
2046 RECURSE(Sub->Next);
2047 break;
2048 }
2049
2050 case C_FOR:
2051 {
2052 STRING(_T("for"));
2053 if (Cmd->For.Switches & FOR_DIRS) STRING(_T(" /D"));
2054 if (Cmd->For.Switches & FOR_F) STRING(_T(" /F"));
2055 if (Cmd->For.Switches & FOR_LOOP) STRING(_T(" /L"));
2056 if (Cmd->For.Switches & FOR_RECURSIVE) STRING(_T(" /R"));
2057 if (Cmd->For.Params)
2058 PRINTF(_T(" %s"), Cmd->For.Params);
2059 if (Cmd->For.List && SubstituteForVars(Cmd->For.List, TempBuf))
2060 PRINTF(_T(" %%%c in (%s) do "), Cmd->For.Variable, TempBuf);
2061 else
2062 PRINTF(_T(" %%%c in (%s) do "), Cmd->For.Variable, Cmd->For.List);
2063 RECURSE(Cmd->Subcommands);
2064 break;
2065 }
2066
2067 case C_IF:
2068 {
2069 STRING(_T("if"));
2070 if (Cmd->If.Flags & IFFLAG_IGNORECASE)
2071 STRING(_T(" /I"));
2072 if (Cmd->If.Flags & IFFLAG_NEGATE)
2073 STRING(_T(" not"));
2074 if (Cmd->If.LeftArg && SubstituteForVars(Cmd->If.LeftArg, TempBuf))
2075 PRINTF(_T(" %s"), TempBuf);
2076 PRINTF(_T(" %s"), IfOperatorString[Cmd->If.Operator]);
2077 if (!SubstituteForVars(Cmd->If.RightArg, TempBuf)) return NULL;
2078 PRINTF(_T(" %s "), TempBuf);
2079 Sub = Cmd->Subcommands;
2080 RECURSE(Sub);
2081 if (Sub->Next)
2082 {
2083 STRING(_T(" else "));
2084 RECURSE(Sub->Next);
2085 }
2086 break;
2087 }
2088
2089 default:
2090 ASSERT(FALSE);
2091 break;
2092 }
2093
2094 for (Redir = Cmd->Redirections; Redir; Redir = Redir->Next)
2095 {
2096 if (!SubstituteForVars(Redir->Filename, TempBuf))
2097 return NULL;
2098 PRINTF(_T(" %c%s%s"), _T('0') + Redir->Number,
2099 RedirString[Redir->Mode], TempBuf);
2100 }
2101 return Out;
2102
2103#undef CHAR
2104#undef STRING
2105#undef PRINTF
2106#undef RECURSE
2107}
#define PRINTF(Format,...)
#define CHAR(Char)
#define RECURSE(Subcommand)
#define STRING(String)
@ Out

Referenced by ExecuteAsync().

Variable Documentation

◆ AutoCompletionChar

TCHAR AutoCompletionChar
extern

Definition at line 111 of file cmdinput.c.

Referenced by LoadRegistrySettings().

◆ bCtrlBreak

BOOL bCtrlBreak
extern

◆ bDelayedExpansion

BOOL bDelayedExpansion
extern

◆ bDisableBatchEcho

BOOL bDisableBatchEcho
extern

Definition at line 160 of file cmd.c.

Referenced by Batch(), ExecuteCommandWithEcho(), and Initialize().

◆ bEnableExtensions

◆ bExit

◆ bHandleContinuations

BOOL bHandleContinuations
extern

Definition at line 97 of file parser.c.

Referenced by cmd_call(), ParseCommandOp(), ParseToken(), and ParseTokenEx().

◆ bIgnoreEcho

BOOL bIgnoreEcho
extern

Definition at line 155 of file cmd.c.

Referenced by Batch(), CommandScreen(), ExecuteCommandWithEcho(), ParseCommand(), and ReadLine().

◆ bIgnoreParserComments

BOOL bIgnoreParserComments
extern

Definition at line 96 of file parser.c.

Referenced by cmd_call(), and ParseCommandBinaryOp().

◆ bParseError

◆ cDateSeparator

TCHAR cDateSeparator
extern

Definition at line 16 of file locale.c.

Referenced by FormatDate(), InitLocale(), PromptDateString(), and ReadSeparator().

◆ cDecimalSeparator

TCHAR cDecimalSeparator
extern

Definition at line 19 of file locale.c.

Referenced by CommandTimer(), GetTimeString(), InitLocale(), ParseTime(), and PrintElapsedTime().

◆ CMD_ModuleHandle

◆ cmds

COMMAND cmds[]
extern

Definition at line 21 of file main.c.

◆ cThousandSeparator

TCHAR cThousandSeparator
extern

Definition at line 18 of file locale.c.

Referenced by ConvertULargeInteger(), and InitLocale().

◆ cTimeSeparator

TCHAR cTimeSeparator
extern

◆ lpOriginalEnvironment

LPTSTR lpOriginalEnvironment
extern

Definition at line 164 of file cmd.c.

Referenced by _tmain(), and cmd_start().

◆ nDateFormat

INT nDateFormat
extern

Definition at line 20 of file locale.c.

Referenced by FormatDate(), InitLocale(), ParseDate(), and PromptDateString().

◆ nErrorLevel

◆ nNumberGroups

INT nNumberGroups
extern

Definition at line 22 of file locale.c.

Referenced by ConvertULargeInteger(), and InitLocale().

◆ nTimeFormat

INT nTimeFormat
extern

Definition at line 21 of file locale.c.

Referenced by FormatTime(), InitLocale(), and ParseTime().

◆ ParseLine

TCHAR ParseLine[CMDLINE_LENGTH]
extern

Definition at line 92 of file parser.c.

Referenced by Batch(), InitParser(), ParseChar(), and ParseCommand().

◆ PathCompletionChar

TCHAR PathCompletionChar
extern

Definition at line 112 of file cmdinput.c.

Referenced by LoadRegistrySettings().

◆ wColor

◆ wDefColor

WORD wDefColor
extern

Definition at line 180 of file cmd.c.

Referenced by CommandColor(), Initialize(), and LoadRegistrySettings().