ReactOS 0.4.15-dev-7670-g69b08be
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
WORD EventType
Definition: wincon.h:273
union _INPUT_RECORD::@3288 Event
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:275
union _KEY_EVENT_RECORD::@3287 uChar
DWORD dwControlKeyState
Definition: wincon.h:248
WORD wVirtualKeyCode
Definition: wincon.h:242
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:2202
#define VK_SHIFT
Definition: winuser.h:2201
#define VK_MENU
Definition: winuser.h:2203

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:5818

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:769
#define SW_MINIMIZE
Definition: winuser.h:775
#define SW_MAXIMIZE
Definition: winuser.h:771

◆ 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"));