ReactOS  0.4.15-dev-1207-g698a8e6
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 cmd_ctty (LPTSTR)
 
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)
 
VOID CompleteFilename (LPTSTR, BOOL, LPTSTR, UINT)
 
INT cmd_for (LPTSTR)
 
INT ExecuteFor (struct _PARSED_COMMAND *Cmd)
 
INT CommandFree (LPTSTR)
 
INT cmd_goto (LPTSTR)
 
LPCTSTR PeekHistory (INT)
 
VOID History (INT, LPTSTR)
 
VOID History_move_to_bottom (VOID)
 
VOID InitHistory (VOID)
 
VOID CleanHistory (VOID)
 
VOID History_del_current_entry (LPTSTR str)
 
INT CommandHistory (LPTSTR param)
 
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 */
361  C_FOR, C_IF, C_REM
362 } COMMAND_TYPE;
Definition: cmd.h:359
Definition: cmd.h:361
Definition: cmd.h:361
Definition: cmd.h:355
Definition: cmd.h:359
Definition: cmd.h:353
Definition: cmd.h:359
Definition: cmd.h:361
enum _COMMAND_TYPE COMMAND_TYPE
Definition: cmd.h:357
Definition: cmd.h:359

◆ _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 */
275 } IF_OPERATOR;
enum _IF_OPERATOR IF_OPERATOR
Definition: cmd.h:274
Definition: cmd.h:274
Definition: cmd.h:274
Definition: cmd.h:274
Definition: cmd.h:266
Definition: cmd.h:274
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

Function Documentation

◆ _stpcpy()

LPTSTR _stpcpy ( LPTSTR  ,
LPCTSTR   
)

Definition at line 460 of file misc.c.

461 {
462  _tcscpy (dest, src);
463  return (dest + _tcslen (src));
464 }
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
GLenum src
Definition: glext.h:6340
static char * dest
Definition: rtl.c:135

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 TRUE
Definition: types.h:120
#define WARN(fmt,...)
Definition: debug.h:112
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
void * arg
Definition: msvc.h:10
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define FALSE
Definition: types.h:117
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
char TCHAR
Definition: xmlstorage.h:189
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
#define cmd_realloc(ptr, size)
Definition: cmddbg.h:30
uint32_t entry
Definition: isohybrid.c:63
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31

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

◆ AddBreakHandler()

VOID AddBreakHandler ( VOID  )

Definition at line 1842 of file cmd.c.

1843 {
1845 }
#define TRUE
Definition: types.h:120
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, BOOL Add)
Definition: console.c:2111
static BOOL WINAPI BreakHandler(IN DWORD dwCtrlType)
Definition: cmd.c:1797

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  {
58  bCtrlBreak = TRUE;
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 }
WCHAR UnicodeChar
Definition: wincon.h:245
#define TRUE
Definition: types.h:120
DWORD dwControlKeyState
Definition: wincon.h:248
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:200
#define VK_MENU
Definition: winuser.h:2179
WORD wVirtualKeyCode
Definition: wincon.h:242
#define FALSE
Definition: types.h:117
#define ReadConsoleInput
Definition: wincon.h:781
#define KEY_EVENT
Definition: wincon.h:128
#define VK_SHIFT
Definition: winuser.h:2177
#define STD_INPUT_HANDLE
Definition: winbase.h:264
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:278
unsigned long DWORD
Definition: ntddk_ex.h:95
union _KEY_EVENT_RECORD::@3241 uChar
#define LEFT_CTRL_PRESSED
Definition: wincon.h:140
#define VK_CONTROL
Definition: winuser.h:2178
WORD EventType
Definition: wincon.h:276
union _INPUT_RECORD::@3242 Event
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:139
BOOL bCtrlBreak
Definition: cmd.c:154

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

◆ CheckCtrlBreak()

BOOL CheckCtrlBreak ( INT  )

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 }
#define BREAK_BATCHFILE
Definition: cmd.h:34
#define BREAK_INPUT
Definition: cmd.h:36
#define TRUE
Definition: types.h:120
VOID ConOutChar(TCHAR c)
Definition: console.c:123
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define _totupper
Definition: tchar.h:1509
TCHAR cgetchar(VOID)
Definition: misc.c:41
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
#define STRING_CANCEL_BATCH_FILE
Definition: resource.h:240
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
const GLubyte * c
Definition: glext.h:8905
#define STRING_COPY_OPTION
Definition: resource.h:20
GLenum mode
Definition: glext.h:6217
#define BREAK_OUTOFBATCH
Definition: cmd.h:35
HANDLE CMD_ModuleHandle
Definition: cmd.c:165
#define ConOutResPuts(uID)
Definition: console.h:36
#define c
Definition: ke_i.h:80
#define LoadString
Definition: winuser.h:5794
BOOL bCtrlBreak
Definition: cmd.c:154

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

◆ CleanHistory()

VOID CleanHistory ( VOID  )

Definition at line 163 of file history.c.

164 {
165  ASSERT(Top && Bottom);
166 
167  while (Bottom->next != Top)
168  del(Bottom->next);
169 
170  cmd_free(Top);
171  cmd_free(Bottom);
172 }
struct tagHISTORY * next
Definition: history.c:47
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static VOID del(LPHIST_ENTRY item)
Definition: history.c:199
#define cmd_free(ptr)
Definition: cmddbg.h:31
static LPHIST_ENTRY Bottom
Definition: history.c:54
static LPHIST_ENTRY Top
Definition: history.c:53

Referenced by Cleanup(), and CommandHistory().

◆ cmd_beep()

INT cmd_beep ( LPTSTR  )

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 TRUE
Definition: types.h:120
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define STRING_BEEP_HELP
Definition: resource.h:70
smooth NULL
Definition: ftsmooth.c:416
HANDLE ConStreamGetOSHandle(IN PCON_STREAM Stream)
Definition: stream.c:240
#define _T(x)
Definition: vfdio.h:22
GLfloat param
Definition: glext.h:5796
VOID ConRingBell(HANDLE hOutput)
Definition: console.c:287
#define StdOut
Definition: stream.h:82
PBATCH_CONTEXT bc
Definition: batch.c:67
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

◆ cmd_call()

INT cmd_call ( LPTSTR  )

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
49  PTSTR first;
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)
158  cmd_free(first);
159 #endif
160  return (nErrorLevel = 0);
161  }
162 
163  /* Reset bParseError so as to continue running afterwards */
164  bParseError = FALSE;
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)
179  cmd_free(first);
180 #endif
181  if (Cmd) FreeCommand(Cmd);
182  return (nErrorLevel = 1);
183  }
184 
185 #ifdef MSCMD_CALL_QUIRKS
186  if (first != param)
187  cmd_free(first);
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"));
203  FreeCommand(Cmd);
204  return (nErrorLevel = 1);
205  }
206 
208  nErrorLevel = (ret != 0 ? ret : nErrorLevel);
209  }
210  else
211  {
213  }
214 
215  FreeCommand(Cmd);
216  return nErrorLevel;
217 }
INT nErrorLevel
Definition: cmd.c:158
TCHAR BatchFilePath[MAX_PATH]
Definition: batch.h:33
#define TRUE
Definition: types.h:120
Definition: cmd.h:361
const GLint * first
Definition: glext.h:5794
#define WARN(fmt,...)
Definition: debug.h:112
#define debugstr_aw
Definition: precomp.h:43
Definition: cmd.h:361
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
PARSED_COMMAND * ParseCommand(IN PCTSTR Line)
Definition: parser.c:1461
int32_t INT
Definition: typedefs.h:58
VOID FreeCommand(IN OUT PARSED_COMMAND *Cmd)
Definition: parser.c:527
Definition: cmd.h:353
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
VOID error_out_of_memory(VOID)
Definition: error.c:138
CHAR * PTSTR
Definition: xmlstorage.h:191
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
VOID ConErrPrintf(LPTSTR szFormat,...)
Definition: tee.c:36
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define TRACE(s)
Definition: solgame.cpp:4
GLfloat param
Definition: glext.h:5796
VOID ConErrPuts(LPTSTR szText)
Definition: tee.c:59
BOOL bEnableExtensions
Definition: cmd.c:161
int ret
Definition: sacdrv.h:277
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
Definition: cmd.h:361
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31
BOOL bIgnoreParserComments
Definition: parser.c:96
static VOID DoCommand(PCONSOLE_STATE State, LPSTR line)
Definition: cmdcons.c:1082
BOOL bHandleContinuations
Definition: parser.c:97
#define STRING_CALL_HELP
Definition: resource.h:71
PBATCH_CONTEXT bc
Definition: batch.c:67
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9
BOOL bParseError
Definition: parser.c:90
char * PTCHAR
Definition: ntbasedef.h:477

◆ cmd_chdir()

INT cmd_chdir ( LPTSTR  )

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 
268  if (bEnableExtensions)
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 }
INT nErrorLevel
Definition: cmd.c:158
INT GetRootPath(IN LPCTSTR InPath, OUT LPTSTR OutPath, IN INT size)
Definition: internal.c:152
VOID error_invalid_drive(VOID)
Definition: error.c:117
#define TRUE
Definition: types.h:120
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define ConOutPrintf(szStr,...)
Definition: console.h:42
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
static VOID StripQuotes(LPSTR in)
Definition: cmdcons.c:116
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define _tcsncicmp
Definition: tchar.h:1429
#define GetCurrentDirectory
Definition: winbase.h:3645
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
BOOL SetRootPath(TCHAR *oldpath, TCHAR *InPath)
Definition: internal.c:182
GLfloat param
Definition: glext.h:5796
#define MAX_PATH
Definition: compat.h:34
BOOL bEnableExtensions
Definition: cmd.c:161
#define STRING_CD_HELP
Definition: resource.h:72
#define _istspace
Definition: tchar.h:1504
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

◆ cmd_cls()

INT cmd_cls ( LPTSTR  )

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 }
#define STRING_CLS_HELP
Definition: resource.h:74
#define TRUE
Definition: types.h:120
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
CON_SCREEN StdOutScreen
Definition: attrib.c:47
#define _T(x)
Definition: vfdio.h:22
GLfloat param
Definition: glext.h:5796
VOID ConClearScreen(IN PCON_SCREEN Screen)
Definition: screen.c:131
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

◆ cmd_copy()

INT cmd_copy ( LPTSTR  )

Definition at line 331 of file copy.c.

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

◆ cmd_ctty()

INT cmd_ctty ( LPTSTR  )

Definition at line 102 of file ctty.c.

103 {
104  static SECURITY_ATTRIBUTES SecAttr = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
105 
106  BOOL Success;
108  HANDLE hDevice, hStdHandles[3]; // hStdIn, hStdOut, hStdErr;
109 
110  /* The user asked for help */
111  if (_tcsncmp(param, _T("/?"), 2) == 0)
112  {
114  return 0;
115  }
116 
117  if (!*param)
118  {
120  return 1;
121  }
122 
123  /* Check whether this is a valid terminal device name */
125  if (DeviceType == 1)
126  {
127  /*
128  * Special case for CON device.
129  *
130  * We do not open CON with GENERIC_READ or GENERIC_WRITE as is,
131  * but instead we separately open CONIN$ and CONOUT$ with both
132  * GENERIC_READ | GENERIC_WRITE access.
133  * We do so because otherwise, opening in particular CON with GENERIC_WRITE
134  * only would open CONOUT$ with an handle not passing the IsConsoleHandle()
135  * test, meaning that we could not use the full console functionalities.
136  */
137  BOOL bRetry = FALSE;
138 
139 RetryOpenConsole:
140  /*
141  * If we previously failed in opening handles to the console,
142  * this means the existing console is almost destroyed.
143  * Close the existing console and allocate and open a new one.
144  */
145  if (bRetry)
146  {
147  FreeConsole();
148  if (!AllocConsole())
149  return 1;
150  }
151 
152  /* Attempt to retrieve a handle for standard input */
153  hStdHandles[0] = CreateFile(_T("CONIN$"),
156  &SecAttr,
158  0,
159  NULL);
160  if (hStdHandles[0] == INVALID_HANDLE_VALUE)
161  {
162  // TODO: Error
163  // error_no_rw_device(param);
164 
165  if (bRetry)
166  return 1;
167  bRetry = TRUE;
168  goto RetryOpenConsole;
169  }
170 
171  /* Attempt to retrieve a handle for standard output.
172  * Note that GENERIC_READ is needed for IsConsoleHandle() to succeed afterwards. */
173  hStdHandles[1] = CreateFile(_T("CONOUT$"),
176  &SecAttr,
178  0,
179  NULL);
180  if (hStdHandles[1] == INVALID_HANDLE_VALUE)
181  {
182  // TODO: Error
183  // error_no_rw_device(param);
184 
185  CloseHandle(hStdHandles[0]);
186 
187  if (bRetry)
188  return 1;
189  bRetry = TRUE;
190  goto RetryOpenConsole;
191  }
192 
193  /* Duplicate a handle for standard error */
195  hStdHandles[1],
197  &hStdHandles[2],
198  0, // GENERIC_WRITE,
199  TRUE,
200  DUPLICATE_SAME_ACCESS /* 0 */);
201  if (!Success)
202  {
203  // TODO: Error
204  // error_no_rw_device(param);
205  CloseHandle(hStdHandles[1]);
206  CloseHandle(hStdHandles[0]);
207  return 1;
208  }
209  }
210  else if (DeviceType == 2)
211  {
212  /*
213  * COM and the other devices can only be opened once.
214  * Since we need different handles, we need to duplicate them.
215  */
216 
217  /* Attempt to retrieve a handle to the device for read/write access */
218  hDevice = CreateFile(param,
221  &SecAttr,
223  0, // FILE_FLAG_OVERLAPPED, // 0,
224  NULL);
225  if (hDevice == INVALID_HANDLE_VALUE)
226  {
227  // TODO: Error
228  // error_no_rw_device(param);
229  return 1;
230  }
231 
232  /* Duplicate a handle for standard input */
234  hDevice,
236  &hStdHandles[0],
237  GENERIC_READ,
238  TRUE,
239  0);
240  if (!Success)
241  {
242  // TODO: Error
243  // error_no_rw_device(param);
244  CloseHandle(hDevice);
245  return 1;
246  }
247 
248  /* Duplicate a handle for standard output */
250  hDevice,
252  &hStdHandles[1],
254  TRUE,
255  0);
256  if (!Success)
257  {
258  // TODO: Error
259  // error_no_rw_device(param);
260  CloseHandle(hStdHandles[0]);
261  CloseHandle(hDevice);
262  return 1;
263  }
264 
265  /* Duplicate a handle for standard error */
267  hDevice,
269  &hStdHandles[2],
271  TRUE,
272  0);
273  if (!Success)
274  {
275  // TODO: Error
276  // error_no_rw_device(param);
277  CloseHandle(hStdHandles[1]);
278  CloseHandle(hStdHandles[0]);
279  CloseHandle(hDevice);
280  return 1;
281  }
282 
283  /* Now get rid of the main device handle */
284  CloseHandle(hDevice);
285  }
286  else
287  {
288  // FIXME: Localize!
289  ConOutPrintf(L"Invalid device '%s'\n", param);
290  return 1;
291  }
292 
293 #if 0
294  /* Now change the file descriptors:
295  0 := rdonly
296  1,2 := wronly
297 
298  if CTTY is called within a pipe or its I/O is redirected,
299  oldinfd or oldoutfd is not equal to -1. In such case the
300  old*fd is modified in order to effect the file descriptor
301  after the redirections are restored. Otherwise a pipe or
302  redirection would left CTTY in a half-made status.
303  */
304  // int failed;
305  failed = dup2(f, 2); /* no redirection support */
306  if(oldinfd != -1)
307  dos_close(oldinfd);
308  oldinfd = f;
309  if(oldoutfd != -1)
310  dos_close(oldoutfd);
311  if((oldoutfd = dup(f)) == -1)
312  failed = 1;
313 
314  if(failed)
315  error_ctty_dup(param);
316 
317  return failed;
318 #endif
319 
320  /* Now set the standard handles */
321 
322  hDevice = GetHandle(0);
323  if (hDevice != INVALID_HANDLE_VALUE)
324  CloseHandle(hDevice);
325  SetHandle(0, hStdHandles[0]);
326 
327  hDevice = GetHandle(1);
328  if (hDevice != INVALID_HANDLE_VALUE)
329  CloseHandle(hDevice);
330  SetHandle(1, hStdHandles[1]);
331 
332  hDevice = GetHandle(2);
333  if (hDevice != INVALID_HANDLE_VALUE)
334  CloseHandle(hDevice);
335  SetHandle(2, hStdHandles[2]);
336 
337  return 0;
338 }
#define GetHandle(h)
Definition: treelist.c:116
BOOL WINAPI AllocConsole(VOID)
Definition: console.c:74
#define CloseHandle
Definition: compat.h:598
#define TRUE
Definition: types.h:120
DeviceType
Definition: mmdrv.h:41
static WORD CheckTerminalDeviceType(IN LPCTSTR pszName)
Definition: ctty.c:30
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
#define ConOutPrintf(szStr,...)
Definition: console.h:42
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:136
VOID SetHandle(UINT Number, HANDLE Handle)
Definition: redir.c:50
#define DUPLICATE_SAME_ACCESS
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID error_req_param_missing(VOID)
Definition: error.c:110
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
_Check_return_ _CRTIMP int __cdecl dup2(_In_ int _FileHandleSrc, _In_ int _FileHandleDst)
#define OPEN_EXISTING
Definition: compat.h:634
GLfloat f
Definition: glext.h:7540
BOOL WINAPI FreeConsole(VOID)
Definition: console.c:153
#define _T(x)
Definition: vfdio.h:22
GLfloat param
Definition: glext.h:5796
unsigned short WORD
Definition: ntddk_ex.h:93
static const WCHAR L[]
Definition: oid.c:1250
#define GetCurrentProcess()
Definition: compat.h:618
#define GENERIC_READ
Definition: compat.h:135
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:913
#define f
Definition: ke_i.h:83
_Check_return_ _CRTIMP int __cdecl dup(_In_ int _FileHandle)
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9
#define STRING_CTTY_HELP
Definition: resource.h:86
BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
Definition: handle.c:149
struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES

◆ cmd_date()

INT cmd_date ( LPTSTR  )

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  if (nDateString == -1)
207  ConOutPrintf(_T("%s"), GetDateString());
208 
209  if (!bPrompt)
210  {
211  freep(arg);
212  return 0;
213  }
214 
215  while (TRUE)
216  {
217  if (nDateString == -1)
218  {
219  PrintDateString();
221 
222  TRACE("\'%s\'\n", debugstr_aw(szDate));
223 
224  while (*szDate && szDate[_tcslen(szDate) - 1] < _T(' '))
225  szDate[_tcslen(szDate) - 1] = _T('\0');
226 
227  if (ParseDate(szDate))
228  {
229  freep(arg);
230  return 0;
231  }
232  }
233  else
234  {
235  if (ParseDate(arg[nDateString]))
236  {
237  freep(arg);
238  return 0;
239  }
240 
241  /* Force input the next time around */
242  nDateString = -1;
243  }
244 
246  nErrorLevel = 1;
247  }
248 
249  freep(arg);
250  return 0;
251 }
INT nErrorLevel
Definition: cmd.c:158
static int argc
Definition: ServiceArgs.c:12
#define _tcsicmp
Definition: xmlstorage.h:205
#define TRUE
Definition: types.h:120
#define ConErrResPuts(uID)
Definition: console.h:39
#define debugstr_aw
Definition: precomp.h:43
static VOID ConInString(LPWSTR lpInput, DWORD dwLength)
Definition: label.c:56
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define ConOutPrintf(szStr,...)
Definition: console.h:42
void * arg
Definition: msvc.h:10
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
int32_t INT
Definition: typedefs.h:58
CHAR * LPTSTR
Definition: xmlstorage.h:192
static BOOL ParseDate(LPTSTR s)
Definition: date.c:93
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 FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
static VOID PrintDateString(VOID)
Definition: date.c:47
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define TRACE(s)
Definition: solgame.cpp:4
GLfloat param
Definition: glext.h:5796
static LPSTR * split(LPSTR s, LPINT args)
Definition: cmdcons.c:163
BOOL bEnableExtensions
Definition: cmd.c:161
LPTSTR GetDateString(VOID)
Definition: locale.c:58
static const WCHAR szDate[]
Definition: http.c:100
#define STRING_DATE_HELP4
Definition: resource.h:99
#define STRING_DATE_ERROR
Definition: resource.h:39
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

Referenced by Initialize().

◆ cmd_endlocal()

INT cmd_endlocal ( LPTSTR  )

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 }
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
CHAR * LPTSTR
Definition: xmlstorage.h:192
IN UCHAR Value
Definition: halp.h:394
BOOL EnableExtensions
Definition: setlocal.c:19
struct NameRec_ * Name
Definition: cdprocs.h:459
struct _SETLOCAL * setlocal
Definition: batch.h:42
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
GLfloat param
Definition: glext.h:5796
#define MAX_PATH
Definition: compat.h:34
BOOL bEnableExtensions
Definition: cmd.c:161
struct _SETLOCAL * Prev
Definition: setlocal.c:16
BOOL DelayedExpansion
Definition: setlocal.c:20
LPTSTR DuplicateEnvironment(VOID)
Definition: setlocal.c:25
LPTSTR Environment
Definition: setlocal.c:17
#define SetEnvironmentVariable
Definition: winbase.h:3748
#define _stprintf
Definition: utility.h:124
#define cmd_free(ptr)
Definition: cmddbg.h:31
BOOL bDelayedExpansion
Definition: cmd.c:162
INT CurDrive
Definition: setlocal.c:18
#define GetEnvironmentVariable
Definition: winbase.h:3654
PBATCH_CONTEXT bc
Definition: batch.c:67
int _tchdir(const _TCHAR *_path)
Definition: chdir.c:8
VOID ConOutPuts(LPTSTR szText)
Definition: tee.c:27

Referenced by ExitBatch().

◆ cmd_for()

INT cmd_for ( LPTSTR  )

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 }
#define TRUE
Definition: types.h:120
#define debugstr_aw
Definition: precomp.h:43
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define STRING_FOR_HELP1
Definition: resource.h:128
#define _T(x)
Definition: vfdio.h:22
#define TRACE(s)
Definition: solgame.cpp:4
GLfloat param
Definition: glext.h:5796
VOID ParseErrorEx(IN PCTSTR s)
Definition: parser.c:227
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

◆ cmd_goto()

INT cmd_goto ( LPTSTR  )

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 */
84  if (bEnableExtensions &&
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 
121 retry:
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 
190 NotFound:
192  ExitBatch();
193  return 1;
194 }
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
DWORD mempos
Definition: batch.h:31
#define _tcsicmp
Definition: xmlstorage.h:205
#define TRUE
Definition: types.h:120
#define debugstr_aw
Definition: precomp.h:43
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
BOOL BatchGetString(LPTSTR lpBuffer, INT nBufferLength)
Definition: batch.c:526
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define STRING_GOTO_HELP1
Definition: resource.h:135
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ConErrResPrintf(uID,...)
Definition: console.h:51
#define _tcsnicmp
Definition: xmlstorage.h:207
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
VOID ExitBatch(VOID)
Definition: batch.c:223
#define STRING_GOTO_ERROR2
Definition: resource.h:52
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
TCHAR textline[BATCH_BUFFSIZE]
Definition: batch.c:76
#define _tcsstr
Definition: xmlstorage.h:199
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define TRACE(s)
Definition: solgame.cpp:4
GLfloat param
Definition: glext.h:5796
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL bEnableExtensions
Definition: cmd.c:161
#define _istcntrl
Definition: tchar.h:739
#define STANDARD_SEPS
Definition: cmd.h:348
uint8_t label[11]
Definition: fsck.fat.h:65
#define STRING_GOTO_ERROR1
Definition: resource.h:51
PARSED_COMMAND * current
Definition: batch.h:41
#define _istspace
Definition: tchar.h:1504
PBATCH_CONTEXT bc
Definition: batch.c:67
DWORD memsize
Definition: batch.h:30

Referenced by Batch(), and CommandExit().

◆ cmd_if()

int cmd_if ( TCHAR )

◆ cmd_mkdir()

INT cmd_mkdir ( LPTSTR  )

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 
393  case ERROR_FILE_EXISTS:
396  break;
397 
398  default:
400  }
401  nErrorLevel = 1;
402  }
403  }
404 
405  freep (p);
406  return nErrorLevel;
407 }
INT nErrorLevel
Definition: cmd.c:158
static int argc
Definition: ServiceArgs.c:12
#define ERROR_FILE_EXISTS
Definition: winerror.h:165
#define STRING_MD_ERROR
Definition: resource.h:220
#define TRUE
Definition: types.h:120
static VOID ErrorMessage(DWORD dwErrorCode, LPWSTR szFormat,...)
Definition: attrib.c:51
#define ConErrResPuts(uID)
Definition: console.h:39
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define STRING_ERROR_REQ_PARAM_MISSING
Definition: resource.h:10
#define STRING_MD_ERROR2
Definition: resource.h:221
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
int32_t INT
Definition: typedefs.h:58
CHAR * LPTSTR
Definition: xmlstorage.h:192
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 FALSE
Definition: types.h:117
#define ConErrResPrintf(uID,...)
Definition: console.h:51
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
smooth NULL
Definition: ftsmooth.c:416
#define _T(x)
Definition: vfdio.h:22
BOOL MakeFullPath(TCHAR *DirPath)
Definition: internal.c:325
GLfloat param
Definition: glext.h:5796
static LPSTR * split(LPSTR s, LPINT args)
Definition: cmdcons.c:163
unsigned long DWORD
Definition: ntddk_ex.h:95
#define STRING_MKDIR_HELP
Definition: resource.h:139
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
GLfloat GLfloat p
Definition: glext.h:8902
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

◆ cmd_mklink()

INT cmd_mklink ( LPTSTR  )

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
201  = (BOOL (WINAPI *)(LPCTSTR, LPCTSTR, LPSECURITY_ATTRIBUTES))GetProcAddress(hKernel32, "CreateHardLinkW");
202 #else
203  = (BOOL (WINAPI *)(LPCTSTR, LPCTSTR, LPSECURITY_ATTRIBUTES))GetProcAddress(hKernel32, "CreateHardLinkA");
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 }
INT nErrorLevel
Definition: cmd.c:158
static int argc
Definition: ServiceArgs.c:12
wchar_t UNICODE
Definition: ms-dtyp.idl:111
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
struct _SECURITY_ATTRIBUTES * LPSECURITY_ATTRIBUTES
#define _tcsicmp
Definition: xmlstorage.h:205
#define STRING_MKLINK_CREATED_JUNCTION
Definition: resource.h:237
static VOID ErrorMessage(DWORD dwErrorCode, LPWSTR szFormat,...)
Definition: attrib.c:51
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
void * arg
Definition: msvc.h:10
#define BOOL
Definition: nt_native.h:43
#define DWORD
Definition: nt_native.h:44
int32_t INT
Definition: typedefs.h:58
CHAR * LPTSTR
Definition: xmlstorage.h:192
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
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 FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID error_req_param_missing(VOID)
Definition: error.c:110
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
smooth NULL
Definition: ftsmooth.c:416
VOID error_invalid_switch(TCHAR ch)
Definition: error.c:72
#define _T(x)
Definition: vfdio.h:22
GLfloat param
Definition: glext.h:5796
#define WINAPI
Definition: msvc.h:6
static LPSTR * split(LPSTR s, LPINT args)
Definition: cmdcons.c:163
#define ConOutResPrintf(uID,...)
Definition: console.h:48
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID error_too_many_parameters(PCTSTR s)
Definition: error.c:79
static LPWSTR CreateSymbolicLink(IN LPGUID InterfaceGuid, IN LPCWSTR ReferenceString, IN struct DeviceInfo *devInfo)
Definition: interface.c:295
#define GetModuleHandle
Definition: winbase.h:3667
#define STRING_MKLINK_CREATED_SYMBOLIC
Definition: resource.h:235
#define STRING_MKLINK_HELP
Definition: resource.h:84
#define ConOutResPuts(uID)
Definition: console.h:36
#define GetProcAddress(x, y)
Definition: compat.h:612
#define STRING_MKLINK_CREATED_HARD
Definition: resource.h:236
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

◆ cmd_move()

INT cmd_move ( LPTSTR  )

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;
100  HANDLE hFile;
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;
141  arg = splitspace(param, &argc);
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? */
218  FindClose(hFile);
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  }
242  FindClose(hFile);
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 */
266  FindClose(hFile);
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 &
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 */
342  FindClose(hFile);
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*/
362  FindClose(hFile);
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));
512  FindClose (hFile);
513 
514  if(hDestFile && hDestFile != INVALID_HANDLE_VALUE)
515  FindClose(hDestFile);
516 
517 Quit:
518  freep(arg);
519  return nErrorLevel;
520 }
INT nErrorLevel
Definition: cmd.c:158
static int argc
Definition: ServiceArgs.c:12
#define _tcsicmp
Definition: xmlstorage.h:205
#define MOVEFILE_REPLACE_EXISTING
Definition: filesup.h:28
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
#define TRUE
Definition: types.h:120
#define STRING_MOVE_ERROR2
Definition: resource.h:54
static VOID ErrorMessage(DWORD dwErrorCode, LPWSTR szFormat,...)
Definition: attrib.c:51
#define MOVEFILE_COPY_ALLOWED
Definition: filesup.h:29
#define RemoveDirectory
Definition: winbase.h:3735
#define STRING_MOVE_ERROR1
Definition: resource.h:53
#define debugstr_aw
Definition: precomp.h:43
BOOL IsExistingFile(IN LPCTSTR pszPath)
Definition: misc.c:498
LPTSTR * splitspace(LPTSTR, LPINT)
Definition: misc.c:381
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define PROMPT_BREAK
Definition: cmd.h:333
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define ConOutPrintf(szStr,...)
Definition: console.h:42
#define MoveFileEx
Definition: winbase.h:3718
void * arg
Definition: msvc.h:10
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
static INT MoveOverwrite(LPTSTR fn)
Definition: move.c:56
#define PROMPT_NO
Definition: cmd.h:330
int32_t INT_PTR
Definition: typedefs.h:64
#define DeleteFile
Definition: winbase.h:3604
#define PROMPT_ALL
Definition: cmd.h:332
int32_t INT
Definition: typedefs.h:58
CHAR * LPTSTR
Definition: xmlstorage.h:192
VOID error_invalid_parameter_format(PCTSTR s)
Definition: error.c:145
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 FALSE
Definition: types.h:117
#define MOVEFILE_WRITE_THROUGH
Definition: filesup.h:30
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID error_req_param_missing(VOID)
Definition: error.c:110
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
smooth NULL
Definition: ftsmooth.c:416
#define FindFirstFile
Definition: winbase.h:3622
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
static TCHAR szTempPath[MAX_PATH]
Definition: CImage.cpp:25
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define TRACE(s)
Definition: solgame.cpp:4
#define FindNextFile
Definition: winbase.h:3628
GLfloat param
Definition: glext.h:5796
#define MAX_PATH
Definition: compat.h:34
#define ConOutResPrintf(uID,...)
Definition: console.h:48
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID error_file_not_found(VOID)
Definition: error.c:93
#define CopyFile
Definition: winbase.h:3581
VOID error_too_many_parameters(PCTSTR s)
Definition: error.c:79
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define GetFullPathName
Definition: winbase.h:3661
_In_ HANDLE hFile
Definition: mswsock.h:90
#define STRING_MOVE_HELP2
Definition: resource.h:147
_TCHAR * _tcscat(_TCHAR *s, const _TCHAR *append)
Definition: tcscat.h:8
VOID error_syntax(PCTSTR s)
Definition: error.c:152
void GetDirectory(LPTSTR wholepath, LPTSTR directory, BOOL CheckExisting)
Definition: move.c:65
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9
BOOL IsExistingDirectory(IN LPCTSTR pszPath)
Definition: misc.c:504
VOID ConOutPuts(LPTSTR szText)
Definition: tee.c:27
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

◆ cmd_path()

INT cmd_path ( LPTSTR  )

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 
101 Quit:
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 }
INT nErrorLevel
Definition: cmd.c:158
#define TRUE
Definition: types.h:120
#define WARN(fmt,...)
Definition: debug.h:112
#define ConOutPrintf(szStr,...)
Definition: console.h:42
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
int32_t INT
Definition: typedefs.h:58
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define STRING_SET_ENV_ERROR
Definition: resource.h:55
#define ConErrResPrintf(uID,...)
Definition: console.h:51
VOID error_out_of_memory(VOID)
Definition: error.c:138
Definition: batch.h:19
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
BATCH_TYPE BatType
Definition: batch.c:66
GLfloat param
Definition: glext.h:5796
unsigned long DWORD
Definition: ntddk_ex.h:95
#define cmd_realloc(ptr, size)
Definition: cmddbg.h:30
#define SetEnvironmentVariable
Definition: winbase.h:3748
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31
#define GetEnvironmentVariable
Definition: winbase.h:3654
#define ENV_BUFFER_SIZE
Definition: path.c:33
#define STRING_PATH_HELP1
Definition: resource.h:151
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

Referenced by RunShell().

◆ cmd_pause()

int cmd_pause ( TCHAR )

◆ cmd_prompt()

INT cmd_prompt ( LPTSTR  )

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 }
INT nErrorLevel
Definition: cmd.c:158
#define STRING_PROMPT_HELP1
Definition: resource.h:155
#define TRUE
Definition: types.h:120
#define STRING_PROMPT_HELP2
Definition: resource.h:156
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
int32_t INT
Definition: typedefs.h:58
#define FALSE
Definition: types.h:117
#define STRING_PROMPT_HELP3
Definition: resource.h:157
smooth NULL
Definition: ftsmooth.c:416
Definition: batch.h:19
#define _T(x)
Definition: vfdio.h:22
BATCH_TYPE BatType
Definition: batch.c:66
GLfloat param
Definition: glext.h:5796
#define SetEnvironmentVariable
Definition: winbase.h:3748
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

◆ cmd_rename()

INT cmd_rename ( LPTSTR  )

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 
80  HANDLE hFile;
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*/
92  arg = split(param, &args, FALSE, FALSE);
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'):
113  dwFlags |= REN_ERROR;
114  break;
115 
116  case _T('N'):
117  dwFlags |= REN_NOTHING;
118  break;
119 
120  case _T('P'):
121  dwFlags |= REN_PROMPT;
122  break;
123 
124  case _T('Q'):
125  dwFlags |= REN_QUIET;
126  break;
127 
128  case _T('S'):
129  dwFlags |= REN_SUBDIR;
130  break;
131 
132  case _T('T'):
133  dwFlags |= REN_TOTAL;
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)
143  dwFlags |= REN_QUIET;
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.
324  FindClose(hFile);
325 
326  if (!(dwFlags & REN_QUIET))
327  {
328  if (dwFiles == 1)
330  else
332  }
333 
334  freep(arg);
335  return 0;
336 }
INT nErrorLevel
Definition: cmd.c:158
#define STRING_REN_HELP1
Definition: resource.h:161
#define STRING_REN_HELP3
Definition: resource.h:163
#define STRING_REN_HELP2
Definition: resource.h:162
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
#define TRUE
Definition: types.h:120
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
_TCHAR * _tcsncpy(_TCHAR *dst, const _TCHAR *src, size_t n)
Definition: tcsncpy.h:9
#define debugstr_aw
Definition: precomp.h:43
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
Definition: ren.c:45
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define ConOutPrintf(szStr,...)
Definition: console.h:42
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define STRING_REN_ERROR1
Definition: resource.h:56
#define _totupper
Definition: tchar.h:1509
Definition: match.c:390
int32_t INT
Definition: typedefs.h:58
CHAR * LPTSTR
Definition: xmlstorage.h:192
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 FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ConErrResPrintf(uID,...)
Definition: console.h:51
VOID error_req_param_missing(VOID)
Definition: error.c:110
GLuint srcPath
Definition: glext.h:11718
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
smooth NULL
Definition: ftsmooth.c:416
Definition: ren.c:43
#define FindFirstFile
Definition: winbase.h:3622
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
char TCHAR
Definition: xmlstorage.h:189
GLfloat f
Definition: glext.h:7540
#define _T(x)
Definition: vfdio.h:22
#define TRACE(s)
Definition: solgame.cpp:4
#define FindNextFile
Definition: winbase.h:3628
GLfloat param
Definition: glext.h:5796
#define MAX_PATH
Definition: compat.h:34
static LPSTR * split(LPSTR s, LPINT args)
Definition: cmdcons.c:163
#define ConOutResPrintf(uID,...)
Definition: console.h:48
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
Definition: ren.c:44
VOID error_file_not_found(VOID)
Definition: error.c:93
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
_In_ HANDLE hFile
Definition: mswsock.h:90
#define MoveFile
Definition: winbase.h:3717
Definition: ren.c:41
#define f
Definition: ke_i.h:83
Definition: ren.c:46
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
_TCHAR * _tcscat(_TCHAR *s, const _TCHAR *append)
Definition: tcscat.h:8
PBATCH_CONTEXT bc
Definition: batch.c:67
VOID error_syntax(PCTSTR s)
Definition: error.c:152
GLfloat GLfloat p
Definition: glext.h:8902
#define args
Definition: format.c:66
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

◆ cmd_replace()

INT cmd_replace ( LPTSTR  )

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'):
421  dwFlags |= REPLACE_ADD;
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:
439  invalid_switch(arg[i]);
440  freep(arg);
441  return 0;
442  }
443  }
444  else
445  {
446  invalid_switch(arg[i]);
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  {
464  invalid_switch(arg[i]);
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)
585  ConOutResPrintf(STRING_REPLACE_HELP8, filesReplaced);
586  else
587  ConOutResPrintf(STRING_REPLACE_HELP4, filesReplaced);
588  }
589  }
590  /* Return memory */
591  freep(arg);
592  return 1;
593 }
static int argc
Definition: ServiceArgs.c:12
#define STRING_REPLACE_ERROR4
Definition: resource.h:63
#define TRUE
Definition: types.h:120
BOOL IsExistingFile(IN LPCTSTR pszPath)
Definition: misc.c:498
INT recReplace(DWORD dwFlags, TCHAR szSrcPath[MAX_PATH], TCHAR szDestPath[MAX_PATH], BOOL *doMore)
Definition: replace.c:215
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define STRING_REPLACE_ERROR6
Definition: resource.h:65
void * arg
Definition: msvc.h:10
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define _totupper
Definition: tchar.h:1509
int32_t INT
Definition: typedefs.h:58