ReactOS  0.4.13-dev-52-g0efcfec
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 BREAK_BATCHFILE   1
 
#define BREAK_OUTOFBATCH   2
 
#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 */
 
#define PROMPT_NO   0
 
#define PROMPT_YES   1
 
#define PROMPT_ALL   2
 
#define PROMPT_BREAK   3
 

Typedefs

typedef struct tagCOMMAND COMMAND
 
typedef struct tagCOMMANDLPCOMMAND
 
typedef struct _PARSED_COMMAND PARSED_COMMAND
 
typedef enum _REDIR_MODE REDIR_MODE
 
typedef struct _REDIRECTION REDIRECTION
 

Enumerations

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

Functions

VOID ExpandAlias (LPTSTR, INT)
 
INT CommandAlias (LPTSTR)
 
INT CommandAssoc (LPTSTR)
 
INT CommandAttrib (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 (struct _PARSED_COMMAND *Cmd)
 
LPCTSTR GetEnvVarOrSpecial (LPCTSTR varName)
 
VOID AddBreakHandler (VOID)
 
VOID RemoveBreakHandler (VOID)
 
BOOL SubstituteVars (TCHAR *Src, TCHAR *Dest, TCHAR Delim)
 
BOOL SubstituteForVars (TCHAR *Src, TCHAR *Dest)
 
LPTSTR DoDelayedExpansion (LPTSTR 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 (DWORD, LPTSTR,...)
 
VOID error_no_pipe (VOID)
 
VOID error_bad_command (LPTSTR)
 
VOID error_invalid_drive (VOID)
 
VOID error_req_param_missing (VOID)
 
VOID error_sfile_not_found (LPTSTR)
 
VOID error_file_not_found (VOID)
 
VOID error_path_not_found (VOID)
 
VOID error_too_many_parameters (LPTSTR)
 
VOID error_parameter_format (TCHAR)
 
VOID error_invalid_switch (TCHAR)
 
VOID error_invalid_parameter_format (LPTSTR)
 
VOID error_out_of_memory (VOID)
 
VOID error_syntax (LPTSTR)
 
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)
 
INT cmd_label (LPTSTR)
 
VOID InitLocale (VOID)
 
LPTSTR GetDateString (VOID)
 
LPTSTR GetTimeString (VOID)
 
INT CommandMemory (LPTSTR)
 
INT cmd_mklink (LPTSTR)
 
INT GetRootPath (TCHAR *InPath, TCHAR *OutPath, 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 (LPCTSTR)
 
BOOL IsExistingFile (LPCTSTR)
 
BOOL IsExistingDirectory (LPCTSTR)
 
BOOL FileGetString (HANDLE, LPTSTR, INT)
 
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 (LPTSTR Line)
 
VOID EchoCommand (PARSED_COMMAND *Cmd)
 
TCHARUnparse (PARSED_COMMAND *Cmd, TCHAR *Out, TCHAR *OutEnd)
 
VOID FreeCommand (PARSED_COMMAND *Cmd)
 
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
 

Macro Definition Documentation

◆ BREAK_BATCHFILE

#define BREAK_BATCHFILE   1

Definition at line 31 of file cmd.h.

◆ BREAK_IGNORE

#define BREAK_IGNORE   4

Definition at line 34 of file cmd.h.

◆ BREAK_INPUT

#define BREAK_INPUT   3

Definition at line 33 of file cmd.h.

◆ BREAK_OUTOFBATCH

#define BREAK_OUTOFBATCH   2

Definition at line 32 of file cmd.h.

◆ BUFF_SIZE

#define BUFF_SIZE   16384

Definition at line 44 of file cmd.h.

◆ CMD_BATCHONLY

#define CMD_BATCHONLY   2

Definition at line 111 of file cmd.h.

◆ CMD_HIDE

#define CMD_HIDE   4

Definition at line 112 of file cmd.h.

◆ CMD_SPECIAL

#define CMD_SPECIAL   1

Definition at line 110 of file cmd.h.

◆ CMDLINE_LENGTH

#define CMDLINE_LENGTH   8192

Definition at line 41 of file cmd.h.

◆ D_OFF

#define D_OFF   _T("off")

Definition at line 38 of file cmd.h.

◆ D_ON

#define D_ON   _T("on")

Definition at line 37 of file cmd.h.

◆ FOR_DIRS

#define FOR_DIRS   1 /* /D */

Definition at line 200 of file cmd.h.

◆ FOR_F

#define FOR_F   2 /* /F */

Definition at line 201 of file cmd.h.

◆ FOR_LOOP

#define FOR_LOOP   4 /* /L */

Definition at line 202 of file cmd.h.

◆ FOR_RECURSIVE

#define FOR_RECURSIVE   8 /* /R */

Definition at line 203 of file cmd.h.

◆ IFFLAG_IGNORECASE

#define IFFLAG_IGNORECASE   2 /* /I */

Definition at line 227 of file cmd.h.

◆ IFFLAG_NEGATE

#define IFFLAG_NEGATE   1 /* NOT */

Definition at line 226 of file cmd.h.

◆ IS_COMPLETION_DISABLED

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

Definition at line 105 of file cmd.h.

◆ PROMPT_ALL

#define PROMPT_ALL   2

Definition at line 284 of file cmd.h.

◆ PROMPT_BREAK

#define PROMPT_BREAK   3

Definition at line 285 of file cmd.h.

◆ PROMPT_NO

#define PROMPT_NO   0

Definition at line 282 of file cmd.h.

◆ PROMPT_YES

#define PROMPT_YES   1

Definition at line 283 of file cmd.h.

Typedef Documentation

◆ COMMAND

◆ LPCOMMAND

◆ PARSED_COMMAND

◆ REDIR_MODE

◆ REDIRECTION

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
IF_CMDEXTVERSION 
IF_DEFINED 
IF_ERRORLEVEL 
IF_EXIST 
IF_STRINGEQ 
IF_EQU 
IF_GTR 
IF_GEQ 
IF_LSS 
IF_LEQ 
IF_NEQ 

Definition at line 228 of file cmd.h.

229  IF_STRINGEQ, /* == */
Definition: cmd.h:228
Definition: cmd.h:230
Definition: cmd.h:230
Definition: cmd.h:230
Definition: cmd.h:230
Definition: cmd.h:230
Definition: cmd.h:230

◆ anonymous enum

anonymous enum
Enumerator
C_COMMAND 
C_QUIET 
C_BLOCK 
C_MULTI 
C_IFFAILURE 
C_IFSUCCESS 
C_PIPE 
C_IF 
C_FOR 

Definition at line 298 of file cmd.h.

Definition: cmd.h:298
Definition: cmd.h:298
Definition: cmd.h:298
Definition: cmd.h:298
Definition: cmd.h:298
Definition: cmd.h:298
Definition: cmd.h:298

◆ _REDIR_MODE

Enumerator
REDIR_READ 
REDIR_WRITE 
REDIR_APPEND 

Definition at line 346 of file cmd.h.

347 {
348  REDIR_READ = 0,
349  REDIR_WRITE = 1,
350  REDIR_APPEND = 2
351 } REDIR_MODE;
enum _REDIR_MODE REDIR_MODE

Function Documentation

◆ _stpcpy()

LPTSTR _stpcpy ( LPTSTR  ,
LPCTSTR   
)

Definition at line 461 of file misc.c.

462 {
463  _tcscpy (dest, src);
464  return (dest + _tcslen (src));
465 }
_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(), and SubstituteForVars().

◆ add_entry()

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

Definition at line 185 of file misc.c.

186 {
187  LPTSTR q;
188  LPTSTR *oldarg;
189 
190  q = cmd_alloc ((_tcslen(entry) + 1) * sizeof (TCHAR));
191  if (!q)
192  {
193  WARN("Cannot allocate memory for q!\n");
194  return FALSE;
195  }
196 
197  _tcscpy (q, entry);
198  oldarg = *arg;
199  *arg = cmd_realloc (oldarg, (*ac + 2) * sizeof (LPTSTR));
200  if (!*arg)
201  {
202  WARN("Cannot reallocate memory for arg!\n");
203  *arg = oldarg;
204  cmd_free (q);
205  return FALSE;
206  }
207 
208  /* save new entry */
209  (*arg)[*ac] = q;
210  (*arg)[++(*ac)] = NULL;
211 
212  return TRUE;
213 }
#define TRUE
Definition: types.h:120
uint8_t entry
Definition: isohybrid.c:63
#define WARN(fmt,...)
Definition: debug.h:111
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
void * arg
Definition: msvc.h:12
CHAR * LPTSTR
Definition: xmlstorage.h:192
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
#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 1553 of file cmd.c.

1554 {
1556 }
#define TRUE
Definition: types.h:120
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleCtrlHandler(PHANDLER_ROUTINE HandlerRoutine, BOOL Add)
Definition: console.c:2111
BOOL WINAPI BreakHandler(DWORD dwCtrlType)
Definition: cmd.c:1508

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 }
#define TRUE
Definition: types.h:120
WCHAR UnicodeChar
Definition: wincon.h:230
union _KEY_EVENT_RECORD::@3144 uChar
DWORD dwControlKeyState
Definition: wincon.h:233
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
#define VK_MENU
Definition: winuser.h:2158
WORD wVirtualKeyCode
Definition: wincon.h:227
#define ReadConsoleInput
Definition: wincon.h:766
#define KEY_EVENT
Definition: wincon.h:122
#define VK_SHIFT
Definition: winuser.h:2156
#define STD_INPUT_HANDLE
Definition: winbase.h:264
union _INPUT_RECORD::@3145 Event
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:263
unsigned long DWORD
Definition: ntddk_ex.h:95
#define LEFT_CTRL_PRESSED
Definition: wincon.h:134
#define VK_CONTROL
Definition: winuser.h:2157
WORD EventType
Definition: wincon.h:261
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:133
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 
154  /* we need to be sure the string arrives on the screen! */
155  do
156  {
158  c = _totupper(cgetchar());
159  } while (!(_tcschr(options, c) || c == _T('\3')) || !c);
160 
161  ConOutChar(_T('\n'));
162 
163  if (c == options[1])
164  {
165  bCtrlBreak = FALSE; /* ignore */
166  return FALSE;
167  }
168 
169  /* leave all batch files */
170  bLeaveAll = ((c == options[2]) || (c == _T('\3')));
171  break;
172  }
173 
174  case BREAK_INPUT:
175  if (!bCtrlBreak)
176  return FALSE;
177  break;
178  }
179 
180  /* state processed */
181  return TRUE;
182 }
#define TRUE
Definition: types.h:120
#define BREAK_BATCHFILE
Definition: cmd.h:31
#define BREAK_INPUT
Definition: cmd.h:33
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
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:247
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:32
HANDLE CMD_ModuleHandle
Definition: cmd.c:164
#define ConOutResPuts(uID)
Definition: console.h:36
#define c
Definition: ke_i.h:80
#define LoadString
Definition: winuser.h:5685
BOOL bCtrlBreak
Definition: cmd.c:154

Referenced by cmd_copy(), CommandDir(), copy(), DirList(), DirPrintBareList(), DirPrintNewList(), DirPrintOldList(), DirPrintWideList(), 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
LPBATCH_CONTEXT bc
Definition: batch.c:66
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define STRING_BEEP_HELP
Definition: resource.h:71
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:76
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

◆ cmd_call()

INT cmd_call ( LPTSTR  )

Definition at line 37 of file call.c.

38 {
40  TCHAR *first;
41  BOOL bInQuote = FALSE;
42 
43  TRACE ("cmd_call: (\'%s\')\n", debugstr_aw(param));
44  if (!_tcsncmp (param, _T("/?"), 2))
45  {
47  return 0;
48  }
49 
50  /* Do a second round of %-variable substitutions */
51  if (!SubstituteVars(param, line, _T('%')))
52  return (nErrorLevel = 1);
53 
54  /* Find start and end of first word */
55  first = line;
56  while (_istspace(*first))
57  first++;
58 
59  for (param = first; *param; param++)
60  {
61  if (!bInQuote && (_istspace(*param) || _tcschr(_T(",;="), *param)))
62  break;
63  bInQuote ^= (*param == _T('"'));
64  }
65 
66  /* Separate first word from rest of line */
67  memmove(param + 1, param, (_tcslen(param) + 1) * sizeof(TCHAR));
68  *param++ = _T('\0');
69 
70  if (*first == _T(':') && bc)
71  {
72  /* CALL :label - call a subroutine of the current batch file */
73  while (*param == _T(' '))
74  param++;
76  return nErrorLevel;
77  }
78 
80  return nErrorLevel;
81 }
INT nErrorLevel
Definition: cmd.c:157
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
#define TRUE
Definition: types.h:120
LPBATCH_CONTEXT bc
Definition: batch.c:66
const GLint * first
Definition: glext.h:5794
#define debugstr_aw
Definition: precomp.h:43
#define CMDLINE_LENGTH
Definition: help.h:12
BOOL SubstituteVars(TCHAR *Src, TCHAR *Dest, TCHAR Delim)
Definition: cmd.c:1206
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
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
Definition: parser.c:48
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define TRACE(s)
Definition: solgame.cpp:4
TCHAR BatchFilePath[MAX_PATH]
Definition: batch.h:14
GLfloat param
Definition: glext.h:5796
char line[200]
Definition: main.c:97
static VOID DoCommand(PCONSOLE_STATE State, LPSTR line)
Definition: cmdcons.c:1082
#define STRING_CALL_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_chdir()

INT cmd_chdir ( LPTSTR  )

Definition at line 217 of file internal.c.

218 {
219  BOOL bChangeDrive = FALSE;
220  LPTSTR tmp;
221  TCHAR szCurrent[MAX_PATH];
222 
223  /* Filter out special cases first */
224 
225  /* Print Help */
226  if (!_tcsncmp(param, _T("/?"), 2))
227  {
229  return 0;
230  }
231 
232  /* Remove extra quotes and strip trailing whitespace */
234  tmp = param + _tcslen(param) - 1;
235  while (tmp > param && _istspace(*tmp))
236  tmp--;
237  *(tmp + 1) = _T('\0');
238 
239  /* Set Error Level to Success */
240  nErrorLevel = 0;
241 
242  /* Print Current Directory on a disk */
243  if (_tcslen(param) == 2 && param[1] == _T(':'))
244  {
245  if (GetRootPath(param, szCurrent, MAX_PATH))
246  {
248  return 1;
249  }
250  ConOutPrintf(_T("%s\n"), szCurrent);
251  return 0;
252  }
253 
254  /* Get Current Directory */
255  GetCurrentDirectory(MAX_PATH, szCurrent);
256  if (param[0] == _T('\0'))
257  {
258  ConOutPrintf(_T("%s\n"), szCurrent);
259  return 0;
260  }
261 
262  /* Input String Contains /D Switch */
263  if (!_tcsncicmp(param, _T("/D"), 2))
264  {
265  bChangeDrive = TRUE;
266  param += 2;
267  while (_istspace(*param))
268  param++;
269  }
270 
271  if (!SetRootPath(bChangeDrive ? NULL : szCurrent, param))
272  {
273  nErrorLevel = 1;
274  return 1;
275  }
276 
277  return 0;
278 }
INT nErrorLevel
Definition: cmd.c:157
#define TRUE
Definition: types.h:120
VOID error_invalid_drive(VOID)
Definition: error.c:115
#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
unsigned int BOOL
Definition: ntddk_ex.h:94
#define _tcsncicmp
Definition: tchar.h:1429
#define GetCurrentDirectory
Definition: winbase.h:3619
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:26
#define STRING_CD_HELP
Definition: resource.h:73
#define _istspace
Definition: tchar.h:1504
INT GetRootPath(TCHAR *InPath, TCHAR *OutPath, INT size)
Definition: internal.c:152
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:75
#define TRUE
Definition: types.h:120
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
CON_SCREEN StdOutScreen
Definition: console.c:29
#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:157
#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 TRUE
Definition: types.h:120
#define BREAK_INPUT
Definition: cmd.h:33
LPBATCH_CONTEXT bc
Definition: batch.c:66
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
GLdouble GLdouble t
Definition: gl.h:2047
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define PROMPT_BREAK
Definition: cmd.h:285
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define STRING_ERROR_REQ_PARAM_MISSING
Definition: resource.h:10
#define ConOutPrintf(szStr,...)
Definition: console.h:42
void * arg
Definition: msvc.h:12
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define PROMPT_NO
Definition: cmd.h:282
#define _totupper
Definition: tchar.h:1509
#define PROMPT_ALL
Definition: cmd.h:284
int32_t INT
Definition: typedefs.h:56
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
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:3619
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:215
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
smooth NULL
Definition: ftsmooth.c:416
#define FindFirstFile
Definition: winbase.h:3596
#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
BOOL IsExistingDirectory(LPCTSTR)
Definition: misc.c:507
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:3602
GLfloat param
Definition: glext.h:5796
#define MAX_PATH
Definition: compat.h:26
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
#define STRING_ERROR_INVALID_PARAM_FORMAT
Definition: resource.h:5
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:3635
_In_ HANDLE hFile
Definition: mswsock.h:90
INT GetRootPath(TCHAR *InPath, TCHAR *OutPath, INT size)
Definition: internal.c:152
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define PROMPT_YES
Definition: cmd.h:283
#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:95
_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:3628
#define STRING_COPY_ERROR3
Definition: resource.h:37
BOOL IsExistingFile(LPCTSTR)
Definition: misc.c:500
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_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
#define TRUE
Definition: types.h:120
BOOL WINAPI AllocConsole(VOID)
Definition: console.c:48
#define CloseHandle
Definition: compat.h:398
DeviceType
Definition: mmdrv.h:41
static WORD CheckTerminalDeviceType(IN LPCTSTR pszName)
Definition: ctty.c:30
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
#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:125
VOID SetHandle(UINT Number, HANDLE Handle)
Definition: redir.c:50
#define DUPLICATE_SAME_ACCESS
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID error_req_param_missing(VOID)
Definition: error.c:108
#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:426
GLfloat f
Definition: glext.h:7540
BOOL WINAPI FreeConsole(VOID)
Definition: console.c:105
#define _T(x)
Definition: vfdio.h:22
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1168
GLfloat param
Definition: glext.h:5796
unsigned short WORD
Definition: ntddk_ex.h:93
static const WCHAR L[]
Definition: oid.c:1250
#define GENERIC_READ
Definition: compat.h:124
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:904
#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:87
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 
184  if (!_tcsncmp (param, _T("/?"), 2))
185  {
187  return 0;
188  }
189 
190  nErrorLevel = 0;
191 
192  /* build parameter array */
193  arg = split (param, &argc, FALSE, FALSE);
194 
195  /* check for options */
196  for (i = 0; i < argc; i++)
197  {
198  if (_tcsicmp (arg[i], _T("/t")) == 0)
199  bPrompt = FALSE;
200  if ((*arg[i] != _T('/')) && (nDateString == -1))
201  nDateString = i;
202  }
203 
204  if (nDateString == -1)
205  ConOutPrintf(_T("%s"), GetDateString());
206 
207  if (!bPrompt)
208  {
209  freep (arg);
210  return 0;
211  }
212 
213  if (nDateString == -1)
214  {
215  while (TRUE) /* forever loop */
216  {
217  TCHAR s[40];
218 
219  PrintDateString ();
220  ConInString (s, 40);
221  TRACE ("\'%s\'\n", debugstr_aw(s));
222  while (*s && s[_tcslen (s) - 1] < _T(' '))
223  s[_tcslen (s) - 1] = _T('\0');
224  if (ParseDate (s))
225  {
226  freep (arg);
227  return 0;
228  }
230  }
231  }
232  else
233  {
234  if (!ParseDate (arg[nDateString]))
235  {
236  while (TRUE) /* forever loop */
237  {
238  TCHAR s[40];
240 
241  PrintDateString ();
242  ConInString (s, 40);
243 
244  while (*s && s[_tcslen (s) - 1] < _T(' '))
245  s[_tcslen (s) - 1] = _T('\0');
246  if (ParseDate (s))
247  {
248  freep (arg);
249  return 0;
250  }
251  }
252  }
253  }
254 
255  freep (arg);
256  return 0;
257 }
INT nErrorLevel
Definition: cmd.c:157
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define _tcsicmp
Definition: xmlstorage.h:205
#define ConErrResPuts(uID)
Definition: console.h:39
#define debugstr_aw
Definition: precomp.h:43
#define ConOutPrintf(szStr,...)
Definition: console.h:42
void * arg
Definition: msvc.h:12
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
int32_t INT
Definition: typedefs.h:56
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
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
LPTSTR GetDateString(VOID)
Definition: locale.c:58
GLdouble s
Definition: gl.h:2039
VOID ConInString(LPTSTR lpInput, DWORD dwLength)
Definition: console.c:81
#define STRING_DATE_HELP4
Definition: resource.h:100
#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 95 of file setlocal.c.

96 {
97  LPTSTR Environ, Name, Value;
98  SETLOCAL *Saved;
99 
100  /* Pop a SETLOCAL struct off of this batch file's stack */
101  if (!bc || !(Saved = bc->setlocal))
102  return 0;
103  bc->setlocal = Saved->Prev;
104 
107 
108  /* First, clear out the environment. Since making any changes to the
109  * environment invalidates pointers obtained from GetEnvironmentStrings(),
110  * we must make a copy of it and get the variable names from that */
111  Environ = DuplicateEnvironment();
112  if (Environ)
113  {
114  for (Name = Environ; *Name; Name += _tcslen(Name) + 1)
115  {
116  if (!(Value = _tcschr(Name + 1, _T('='))))
117  continue;
118  *Value++ = _T('\0');
120  Name = Value;
121  }
122  cmd_free(Environ);
123  }
124 
125  /* Now, restore variables from the copy saved by cmd_setlocal */
126  for (Name = Saved->Environment; *Name; Name += _tcslen(Name) + 1)
127  {
128  if (!(Value = _tcschr(Name + 1, _T('='))))
129  continue;
130  *Value++ = _T('\0');
132  Name = Value;
133  }
134 
135  cmd_free(Saved->Environment);
136  cmd_free(Saved);
137  return 0;
138 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
LPBATCH_CONTEXT bc
Definition: batch.c:66
CHAR * LPTSTR
Definition: xmlstorage.h:192
BOOL EnableExtensions
Definition: setlocal.c:15
struct NameRec_ * Name
Definition: cdprocs.h:464
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
struct _SETLOCAL * setlocal
Definition: batch.h:21
#define _T(x)
Definition: vfdio.h:22
BOOL bEnableExtensions
Definition: cmd.c:160
struct _SETLOCAL * Prev
Definition: setlocal.c:14
BOOL DelayedExpansion
Definition: setlocal.c:16
LPTSTR DuplicateEnvironment(VOID)
Definition: setlocal.c:22
LPTSTR Environment
Definition: setlocal.c:17
#define SetEnvironmentVariable
Definition: winbase.h:3722
#define cmd_free(ptr)
Definition: cmddbg.h:31
BOOL bDelayedExpansion
Definition: cmd.c:161

Referenced by ExitBatch().

◆ cmd_for()

INT cmd_for ( LPTSTR  )

Definition at line 37 of file for.c.

38 {
39  TRACE ("cmd_for (\'%s\')\n", debugstr_aw(param));
40 
41  if (!_tcsncmp (param, _T("/?"), 2))
42  {
44  return 0;
45  }
46 
48  return 1;
49 }
#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:129
#define _T(x)
Definition: vfdio.h:22
#define TRACE(s)
Definition: solgame.cpp:4
GLfloat param
Definition: glext.h:5796
VOID error_syntax(LPTSTR)
Definition: error.c:150
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

◆ cmd_goto()

INT cmd_goto ( LPTSTR  )

Definition at line 39 of file goto.c.

40 {
41  LPTSTR tmp, tmp2;
42 
43  TRACE ("cmd_goto (\'%s\')\n", debugstr_aw(param));
44 
45  if (!_tcsncmp (param, _T("/?"), 2))
46  {
48  return 0;
49  }
50 
51  /* if not in batch -- error!! */
52  if (bc == NULL)
53  {
54  return 1;
55  }
56 
57  if (*param == _T('\0'))
58  {
60  ExitBatch();
61  return 1;
62  }
63 
64  /* terminate label at first space char */
65  tmp = param+1;
66  while (!_istcntrl (*tmp) && !_istspace (*tmp) && (*tmp != _T(':')))
67  tmp++;
68  *(tmp) = _T('\0');
69 
70  /* jump to end of the file */
71  if ( _tcsicmp( param, _T(":eof"))==0)
72  {
73  bc->mempos=bc->memsize; /* position at the end of the batchfile */
74  return 0;
75  }
76 
77  /* jump to begin of the file */
78  bc->mempos=0;
79 
80  while (BatchGetString (textline, sizeof(textline) / sizeof(textline[0])))
81  {
82  int pos;
83  INT_PTR size;
84 
85  /* Strip out any trailing spaces or control chars */
86  tmp = textline + _tcslen (textline) - 1;
87 
88  while (tmp > textline && (_istcntrl (*tmp) || _istspace (*tmp) || (*tmp == _T(':'))))
89  tmp--;
90  *(tmp + 1) = _T('\0');
91 
92  /* Then leading spaces... */
93  tmp = textline;
94  while (_istspace (*tmp))
95  tmp++;
96 
97  /* All space after leading space terminate the string */
98  size = _tcslen(tmp) -1;
99  pos=0;
100  while (tmp+pos < tmp+size)
101  {
102  if (_istspace(tmp[pos]))
103  tmp[pos]=_T('\0');
104  pos++;
105  }
106 
107  tmp2 = param;
108  /* use whole label name */
109  if ((*tmp == _T(':')) && ((_tcsicmp (++tmp, param) == 0) || (_tcsicmp (tmp, ++tmp2) == 0)))
110  return 0;
111 
112  }
113 
115  ExitBatch();
116  return 1;
117 }
#define TRUE
Definition: types.h:120
DWORD mempos
Definition: batch.h:12
#define _tcsicmp
Definition: xmlstorage.h:205
LPBATCH_CONTEXT bc
Definition: batch.c:66
#define debugstr_aw
Definition: precomp.h:43
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
int32_t INT_PTR
Definition: typedefs.h:62
BOOL BatchGetString(LPTSTR lpBuffer, INT nBufferLength)
Definition: batch.c:400
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define STRING_GOTO_HELP1
Definition: resource.h:136
#define ConErrResPrintf(uID,...)
Definition: console.h:51
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
VOID ExitBatch(VOID)
Definition: batch.c:186
#define STRING_GOTO_ERROR2
Definition: resource.h:52
TCHAR textline[BATCH_BUFFSIZE]
Definition: batch.c:73
#define _T(x)
Definition: vfdio.h:22
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
GLfloat param
Definition: glext.h:5796
#define _istcntrl
Definition: tchar.h:739
#define STRING_GOTO_ERROR1
Definition: resource.h:51
DWORD memsize
Definition: batch.h:11
#define _istspace
Definition: tchar.h:1504
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

Referenced by Batch().

◆ cmd_if()

int cmd_if ( TCHAR )

◆ cmd_label()

INT cmd_label ( LPTSTR  )

Definition at line 25 of file label.c.

26 {
27  TCHAR szRootPath[] = _T("A:\\");
28  TCHAR szLabel[80];
29  TCHAR szOldLabel[80];
30  DWORD dwSerialNr;
31 
32  /* set empty label string */
33  szLabel[0] = _T('\0');
34 
35  nErrorLevel = 0;
36 
37  /* print help */
38  if (!_tcsncmp (param, _T("/?"), 2))
39  {
41  return 0;
42  }
43 
44  /* get parameters */
45  if (param[0] != _T('\0') && param[1] == _T(':'))
46  {
47  szRootPath[0] = toupper(*param);
48  param += 2;
49  while (_istspace(*param))
50  param++;
51  }
52  else
53  {
54  /* get label of current drive */
55  TCHAR szCurPath[MAX_PATH];
56  GetCurrentDirectory (MAX_PATH, szCurPath);
57  szRootPath[0] = szCurPath[0];
58  }
59 
60  _tcsncat(szLabel, param, 79);
61 
62  /* check root path */
63  if (!IsValidPathName (szRootPath))
64  {
66  nErrorLevel = 1;
67  return 1;
68  }
69 
70  if (szLabel[0] == _T('\0'))
71  {
72  GetVolumeInformation(szRootPath, szOldLabel, 80, &dwSerialNr,
73  NULL, NULL, NULL, 0);
74 
75  /* print drive info */
76  if (szOldLabel[0] != _T('\0'))
77  {
78  ConOutResPrintf(STRING_LABEL_HELP2, _totupper(szRootPath[0]), szOldLabel);
79  }
80  else
81  {
83  }
84 
85  /* print the volume serial number */
86  ConOutResPrintf(STRING_LABEL_HELP4, HIWORD(dwSerialNr), LOWORD(dwSerialNr));
87 
89 
90  ConInString(szLabel, 80);
91  }
92 
93  if (!SetVolumeLabel(szRootPath, szLabel))
94  {
96  nErrorLevel = 1;
97  return 1;
98  }
99 
100  return 0;
101 }
#define STRING_LABEL_HELP5
Definition: resource.h:142
INT nErrorLevel
Definition: cmd.c:157
#define ConOutFormatMessage(MessageId,...)
Definition: console.h:54
#define TRUE
Definition: types.h:120
#define STRING_LABEL_HELP4
Definition: resource.h:141
BOOL IsValidPathName(LPCTSTR)
Definition: misc.c:483
VOID error_invalid_drive(VOID)
Definition: error.c:115
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define _totupper
Definition: tchar.h:1509
#define STRING_LABEL_HELP1
Definition: resource.h:138
#define GetCurrentDirectory
Definition: winbase.h:3619
smooth NULL
Definition: ftsmooth.c:416
#define STRING_LABEL_HELP3
Definition: resource.h:140
char TCHAR
Definition: xmlstorage.h:189
int toupper(int c)
Definition: utclib.c:881
#define _T(x)
Definition: vfdio.h:22
_TCHAR * _tcsncat(_TCHAR *dst, const _TCHAR *src, size_t n)
Definition: tcsncat.h:5
GLfloat param
Definition: glext.h:5796
#define MAX_PATH
Definition: compat.h:26
#define ConOutResPrintf(uID,...)
Definition: console.h:48
unsigned long DWORD
Definition: ntddk_ex.h:95
#define STRING_LABEL_HELP2
Definition: resource.h:139
VOID ConInString(LPTSTR lpInput, DWORD dwLength)
Definition: console.c:81
#define GetVolumeInformation
Definition: winbase.h:3667
#define SetVolumeLabel
Definition: winbase.h:3731
#define ConOutResPuts(uID)
Definition: console.h:36
#define _istspace
Definition: tchar.h:1504
#define HIWORD(l)
Definition: typedefs.h:246
#define LOWORD(l)
Definition: pedump.c:82
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

◆ cmd_mkdir()

INT cmd_mkdir ( LPTSTR  )

Definition at line 322 of file internal.c.

323 {
324  LPTSTR *p;
325  INT argc, i;
326  if (!_tcsncmp (param, _T("/?"), 2))
327  {
329  return 0;
330  }
331 
332  p = split (param, &argc, FALSE, FALSE);
333  if (argc == 0)
334  {
336  freep(p);
337  nErrorLevel = 1;
338  return 1;
339  }
340 
341  nErrorLevel = 0;
342  for (i = 0; i < argc; i++)
343  {
344  if (!MakeFullPath(p[i]))
345  {
347  {
349  }
350  else
351  {
352  ErrorMessage (GetLastError(), _T("MD"));
353  }
354  nErrorLevel = 1;
355  }
356  }
357 
358  freep (p);
359  return nErrorLevel;
360 }
INT nErrorLevel
Definition: cmd.c:157
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
VOID ErrorMessage(DWORD, LPTSTR,...)
Definition: error.c:26
#define ConErrResPuts(uID)
Definition: console.h:39
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define STRING_ERROR_REQ_PARAM_MISSING
Definition: resource.h:10
#define STRING_MD_ERROR2
Definition: resource.h:228
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
int32_t INT
Definition: typedefs.h:56
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
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
#define _T(x)
Definition: vfdio.h:22
BOOL MakeFullPath(TCHAR *DirPath)
Definition: internal.c:287
GLfloat param
Definition: glext.h:5796
static LPSTR * split(LPSTR s, LPINT args)
Definition: cmdcons.c:163
#define STRING_MKDIR_HELP
Definition: resource.h:146
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
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:157
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
VOID ErrorMessage(DWORD, LPTSTR,...)
Definition: error.c:26
#define STRING_MKLINK_CREATED_JUNCTION
Definition: resource.h:244
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
void * arg
Definition: msvc.h:12
#define BOOL
Definition: nt_native.h:43
#define DWORD
Definition: nt_native.h:44
int32_t INT
Definition: typedefs.h:56
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
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID error_req_param_missing(VOID)
Definition: error.c:108
static VOID freep(LPSTR *p)
Definition: cmdcons.c:98
smooth NULL
Definition: ftsmooth.c:416
#define _T(x)
Definition: vfdio.h:22
GLfloat param
Definition: glext.h:5796
#define WINAPI
Definition: msvc.h:8
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_invalid_switch(TCHAR)
Definition: error.c:70
VOID error_too_many_parameters(LPTSTR)
Definition: error.c:77
static LPWSTR CreateSymbolicLink(IN LPGUID InterfaceGuid, IN LPCWSTR ReferenceString, IN struct DeviceInfo *devInfo)
Definition: interface.c:295
#define GetModuleHandle
Definition: winbase.h:3641
#define STRING_MKLINK_CREATED_SYMBOLIC
Definition: resource.h:242
#define STRING_MKLINK_HELP
Definition: resource.h:85
#define ConOutResPuts(uID)
Definition: console.h:36
#define GetProcAddress(x, y)
Definition: compat.h:410
#define STRING_MKLINK_CREATED_HARD
Definition: resource.h:243
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  freep(arg);
162  return 1;
163  }
164 
165  if (nFiles > 2)
166  {
167  /* there are more than two pathspecs */
169  freep(arg);
170  return 1;
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  freep(arg);
182  return 1;
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  freep (arg);
204  return 1;
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  freep(arg);
220  return 1;
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  freep (arg);
252  return 1;
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  freep(arg);
268  return 1;
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  freep(arg);
344  return 1;
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  freep (arg);
364  return 1;
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  if (MoveStatus)
500  else
502  }
503  while ((!OnlyOneFile || dwMoveStatusFlags & MOVE_SRC_CURRENT_IS_DIR ) &&
504  !(dwMoveStatusFlags & MOVE_SOURCE_IS_DIR) &&
505  FindNextFile (hFile, &findBuffer));
506  FindClose (hFile);
507 
508  if(hDestFile && hDestFile != INVALID_HANDLE_VALUE)
509  FindClose(hDestFile);
510 
511  freep (arg);
512  return 0;
513 }
INT nErrorLevel
Definition: cmd.c:157
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#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
VOID ErrorMessage(DWORD, LPTSTR,...)
Definition: error.c:26
#define STRING_MOVE_ERROR2
Definition: resource.h:54
#define MOVEFILE_COPY_ALLOWED
Definition: filesup.h:29
#define RemoveDirectory
Definition: winbase.h:3709
#define STRING_MOVE_ERROR1
Definition: resource.h:53
#define debugstr_aw
Definition: precomp.h:43
LPTSTR * splitspace(LPTSTR, LPINT)
Definition: misc.c:382
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
#define PROMPT_BREAK
Definition: cmd.h:285
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ConOutPrintf(szStr,...)
Definition: console.h:42
#define MoveFileEx
Definition: winbase.h:3692
void * arg
Definition: msvc.h:12
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:282
int32_t INT_PTR
Definition: typedefs.h:62
#define DeleteFile
Definition: winbase.h:3578
#define PROMPT_ALL
Definition: cmd.h:284
int32_t INT
Definition: typedefs.h:56
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 MOVEFILE_WRITE_THROUGH
Definition: filesup.h:30
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID error_req_param_missing(VOID)
Definition: error.c:108
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
VOID error_invalid_parameter_format(LPTSTR)
Definition: error.c:143
#define FindFirstFile
Definition: winbase.h:3596
_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:45
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define TRACE(s)
Definition: solgame.cpp:4
BOOL IsExistingDirectory(LPCTSTR)
Definition: misc.c:507
#define FindNextFile
Definition: winbase.h:3602
GLfloat param
Definition: glext.h:5796
#define MAX_PATH
Definition: compat.h:26
#define ConOutResPrintf(uID,...)
Definition: console.h:48
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID error_file_not_found(VOID)
Definition: error.c:91
#define CopyFile
Definition: winbase.h:3555
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
#define GetFullPathName
Definition: winbase.h:3635
_In_ HANDLE hFile
Definition: mswsock.h:90
VOID error_too_many_parameters(LPTSTR)
Definition: error.c:77
VOID error_syntax(LPTSTR)
Definition: error.c:150
#define STRING_MOVE_HELP2
Definition: resource.h:154
_TCHAR * _tcscat(_TCHAR *s, const _TCHAR *append)
Definition: tcscat.h:8
BOOL IsExistingFile(LPCTSTR)
Definition: misc.c:500
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
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  if (!_tcsncmp (param, _T("/?"), 2))
39  {
41  return 0;
42  }
43 
44  nErrorLevel = 0;
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");
56  return 1;
57  }
58 
59  dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
60  if (dwBuffer == 0)
61  {
62  cmd_free(pszBuffer);
64  return 0;
65  }
66  else if (dwBuffer > ENV_BUFFER_SIZE)
67  {
68  LPTSTR pszOldBuffer = pszBuffer;
69  pszBuffer = (LPTSTR)cmd_realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
70  if (!pszBuffer)
71  {
72  WARN("Cannot reallocate memory for pszBuffer!\n");
73  cmd_free(pszOldBuffer);
74  return 1;
75  }
76  GetEnvironmentVariable (_T("PATH"), pszBuffer, dwBuffer);
77  }
78 
79  ConOutPrintf(_T("PATH=%s\n"), pszBuffer);
80  cmd_free (pszBuffer);
81 
82  return 0;
83  }
84 
85  /* skip leading '=' */
86  if (*param == _T('='))
87  param++;
88 
89  /* set PATH environment variable */
90  if (!SetEnvironmentVariable (_T("PATH"), param))
91  {
92  nErrorLevel = 1;
93  return 1;
94  }
95 
96  return 0;
97 }
INT nErrorLevel
Definition: cmd.c:157
#define TRUE
Definition: types.h:120
#define WARN(fmt,...)
Definition: debug.h:111
#define ConOutPrintf(szStr,...)
Definition: console.h:42
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define STRING_VOL_HELP2
Definition: resource.h:208
CHAR * LPTSTR
Definition: xmlstorage.h:192
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
GLfloat param
Definition: glext.h:5796
#define ConOutResPrintf(uID,...)
Definition: console.h:48
unsigned long DWORD
Definition: ntddk_ex.h:95
#define cmd_realloc(ptr, size)
Definition: cmddbg.h:30
#define SetEnvironmentVariable
Definition: winbase.h:3722
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31
#define GetEnvironmentVariable
Definition: winbase.h:3628
#define ENV_BUFFER_SIZE
Definition: path.c:33
#define STRING_PATH_HELP1
Definition: resource.h:158
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 231 of file prompt.c.

232 {
233  if (!_tcsncmp(param, _T("/?"), 2))
234  {
236 
237 #ifdef FEATURE_DIRECTORY_STACK
239 #endif
241  return 0;
242  }
243 
244  /*
245  * Set the PROMPT environment variable. If 'param' is NULL or is
246  * an empty string (the user entered "prompt" only), then remove
247  * the environment variable and therefore use the default prompt.
248  * Otherwise, use the new prompt.
249  */
250  if (!SetEnvironmentVariable(_T("PROMPT"),
251  (param && param[0] != _T('\0') ? param : NULL)))
252  {
253  return 1;
254  }
255 
256  return 0;
257 }
#define TRUE
Definition: types.h:120
#define STRING_PROMPT_HELP1
Definition: resource.h:162
#define STRING_PROMPT_HELP2
Definition: resource.h:163
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define STRING_PROMPT_HELP3
Definition: resource.h:164
smooth NULL
Definition: ftsmooth.c:416
#define _T(x)
Definition: vfdio.h:22
GLfloat param
Definition: glext.h:5796
#define SetEnvironmentVariable
Definition: winbase.h:3722
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:157
#define STRING_REN_HELP1
Definition: resource.h:168
#define STRING_REN_HELP3
Definition: resource.h:170
#define TRUE
Definition: types.h:120
Definition: ren.c:45
#define STRING_REN_HELP2
Definition: resource.h:169
LPBATCH_CONTEXT bc
Definition: batch.c:66
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
#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:391
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#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:56
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
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ConErrResPrintf(uID,...)
Definition: console.h:51
VOID error_req_param_missing(VOID)
Definition: error.c:108
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
#define FindFirstFile
Definition: winbase.h:3596
_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
Definition: ren.c:46
#define FindNextFile
Definition: winbase.h:3602
GLfloat param
Definition: glext.h:5796
#define MAX_PATH
Definition: compat.h:26
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
VOID error_file_not_found(VOID)
Definition: error.c:91
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
_In_ HANDLE hFile
Definition: mswsock.h:90
Definition: ren.c:41
Definition: ren.c:44
VOID error_syntax(LPTSTR)
Definition: error.c:150
#define MoveFile
Definition: winbase.h:3691
Definition: ren.c:43
#define f
Definition: ke_i.h:83
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
_TCHAR * _tcscat(_TCHAR *s, const _TCHAR *append)
Definition: tcscat.h:8
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  return 0;
441  }
442  }
443  else
444  {
445  invalid_switch(arg[i]);
446  freep(arg);
447  return 0;
448  }
449  nFiles--;
450  }
451  else
452  {
453  if (srcIndex == -1)
454  {
455  srcIndex = i;
456  }
457  else if (destIndex == -1)
458  {
459  destIndex = i;
460  }
461  else
462  {
463  invalid_switch(arg[i]);
464  freep(arg);
465  return 0;
466  }
467  }
468  }
469 
470  /* See so that at least source is there */
471  if (nFiles < 1)
472  {
475  freep(arg);
476  return 1;
477  }
478  /* Check so that not both update and add switch is added and subdir */
480  {
483  freep(arg);
484  return 1;
485  }
486 
487  /* If we have a destination get the full path */
488  if (destIndex != -1)
489  {
490  if (_tcslen(arg[destIndex]) == 2 && arg[destIndex][1] == ':')
491  GetRootPath(arg[destIndex],szDestPath,MAX_PATH);
492  else
493  {
494  /* Check for wildcards in destination directory */
495  if (_tcschr (arg[destIndex], _T('*')) != NULL ||
496  _tcschr (arg[destIndex], _T('?')) != NULL)
497  {
500  freep(arg);
501  return 1;
502  }
503  getPath(szDestPath, arg[destIndex]);
504  /* Make sure that destination exists */
505  if (!IsExistingDirectory(szDestPath))
506  {
509  freep(arg);
510  return 1;
511  }
512  }
513  }
514  else
515  {
516  /* Dest is current dir */
517  GetCurrentDirectory(MAX_PATH,szDestPath);
518  }
519 
520  /* Get the full source path */
521  if (!(_tcslen(arg[srcIndex]) == 2 && arg[srcIndex][1] == ':'))
522  getPath(szSrcPath, arg[srcIndex]);
523  else
524  _tcscpy(szSrcPath,arg[srcIndex]);
525 
526  /* Source does not have wildcards */
527  if (_tcschr (arg[srcIndex], _T('*')) == NULL &&
528  _tcschr (arg[srcIndex], _T('?')) == NULL)
529  {
530  /* Check so that source is not a directory, because that is not allowed */
531  if (IsExistingDirectory(szSrcPath))
532  {
535  freep(arg);
536  return 1;
537  }
538  /* Check if the file exists */
539  if (!IsExistingFile(szSrcPath))
540  {
542  freep(arg);
543  return 1;
544  }
545  }
546  /* /w switch is set so wait for any key to be pressed */
547  if (dwFlags & REPLACE_DISK)
548  {
549  msg_pause();
550  cgetchar();
551  }
552 
553  /* Add an extra \ to the destination path if needed */
554  if (szDestPath[_tcslen(szDestPath) - 1] != _T('\\'))
555  _tcscat(szDestPath, _T("\\"));
556 
557  /* Save source path */
558  _tcscpy(tmpSrcPath,szSrcPath);
559  /* Replace in dest dir */
560  filesReplaced += recReplace(dwFlags, tmpSrcPath, szDestPath, &doMore);
561  /* If subdir switch is set replace in the subdirs to */
562  if (dwFlags & REPLACE_SUBDIR && doMore)
563  {
564  filesReplaced += recFindSubDirs(dwFlags, szSrcPath, szDestPath, &doMore);
565  }
566 
567  /* If source == dest write no more */
568  if (filesReplaced != -1)
569  {
570  /* No files replaced */
571  if (filesReplaced==0)
572  {
573  /* Add switch dependent output */
574  if (dwFlags & REPLACE_ADD)
576  else
578  }
579  /* Some files replaced */
580  else
581  {
582  /* Add switch dependent output */
583  if (dwFlags & REPLACE_ADD)
584  ConOutResPrintf(STRING_REPLACE_HELP8, filesReplaced);
585  else
586  ConOutResPrintf(STRING_REPLACE_HELP4, filesReplaced);
587  }
588  }
589  /* Return memory */
590  freep(arg);
591  return 1;
592 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define STRING_REPLACE_ERROR4
Definition: resource.h:63
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:12
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define _totupper
Definition: tchar.h:1509
int32_t INT
Definition: typedefs.h:56
CHAR * LPTSTR
Definition: xmlstorage.h:192
void invalid_switch(LPTSTR is)
Definition: replace.c:30
#define STRING_REPLACE_HELP3
Definition: resource.h:232
#define STRING_REPLACE_HELP4
Definition: resource.h:233
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
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetCurrentDirectory
Definition: winbase.h:3619
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
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
BOOL IsExistingDirectory(LPCTSTR)
Definition: misc.c:507
void getPath(TCHAR *out, LPTSTR in)
Definition: replace.c:37
#define STRING_REPLACE_HELP8
Definition: resource.h:237
GLfloat param
Definition: glext.h:5796
#define MAX_PATH
Definition: compat.h:26
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
#define STRING_REPLACE_HELP7
Definition: resource.h:236
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
VOID msg_pause(VOID)
Definition: error.c:165
INT GetRootPath(TCHAR *InPath, TCHAR *OutPath, INT size)
Definition: internal.c:152
#define STRING_REPLACE_ERROR2
Definition: resource.h:61
#define STRING_REPLACE_HELP1
Definition: resource.h:230
_TCHAR * _tcscat(_TCHAR *s, const _TCHAR *append)
Definition: tcscat.h:8
TCHAR cgetchar(VOID)
Definition: misc.c:41
INT recFindSubDirs(DWORD dwFlags, TCHAR szSrcPath[MAX_PATH], TCHAR szDestPath[MAX_PATH], BOOL *doMore)
Definition: replace.c:315
BOOL IsExistingFile(LPCTSTR)
Definition: misc.c:500
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9
#define STRING_REPLACE_HELP2
Definition: resource.h:231

◆ cmd_rmdir()

INT cmd_rmdir ( LPTSTR  )

Definition at line 406 of file internal.c.

407 {
408  TCHAR ch;
409  INT args;
410  INT dirCount;
411  LPTSTR *arg;
412  INT i;
413  BOOL RD_SUB = FALSE;
414  BOOL RD_QUIET = FALSE;
415  INT res;
416  INT nError = 0;
417  TCHAR szFullPath[MAX_PATH];
418 
419  if (!_tcsncmp (param, _T("/?"), 2))
420  {
422  return 0;
423  }
424 
425  arg = split (param, &args, FALSE, FALSE);
426  dirCount = 0;
427 
428  /* check for options anywhere in command line */
429  for (i = 0; i < args; i++)
430  {
431  if (*arg[i] == _T('/'))
432  {
433  /*found a command, but check to make sure it has something after it*/
434  if (_tcslen (arg[i]) == 2)
435  {
436  ch = _totupper (arg[i][1]);
437 
438  if (ch == _T('S'))
439  {
440  RD_SUB = TRUE;
441  }
442  else if (ch == _T('Q'))
443  {
444  RD_QUIET = TRUE;
445  }
446  }
447  }
448  else
449  {
450  dirCount++;
451  }
452  }
453 
454  if (dirCount == 0)
455  {
456  /* No folder to remove */
458  freep(arg);
459  return 1;
460  }
461 
462  for (i = 0; i < args; i++)
463  {
464  if (*arg[i] == _T('/'))
465  continue;
466 
467  if (RD_SUB)
468  {
469  /* ask if they want to delete everything in the folder */
470  if (!RD_QUIET)
471  {
473  if (res == PROMPT_NO || res == PROMPT_BREAK)
474  {
475  nError = 1;
476  continue;
477  }
478  if (res == PROMPT_ALL)
479  RD_QUIET = TRUE;
480  }
481  /* get the folder name */
482  GetFullPathName(arg[i],MAX_PATH,szFullPath,NULL);
483 
484  /* remove trailing \ if any, but ONLY if dir is not the root dir */
485  if (_tcslen (szFullPath) >= 2 && szFullPath[_tcslen (szFullPath) - 1] == _T('\\'))
486  szFullPath[_tcslen(szFullPath) - 1] = _T('\0');
487 
488  res = DeleteFolder(szFullPath);
489  }
490  else
491  {
492  res = RemoveDirectory(arg[i]);
493  }
494 
495  if (!res)
496  {
497  /* Couldn't delete the folder, print out the error */
498  nError = GetLastError();
499  ErrorMessage(nError, _T("RD"));
500  }
501  }
502 
503  freep (arg);
504  return nError;
505 }
#define TRUE
Definition: types.h:120
#define STRING_RMDIR_HELP
Definition: resource.h:172
VOID ErrorMessage(DWORD, LPTSTR,...)
Definition: error.c:26
#define RemoveDirectory
Definition: winbase.h:3709
#define PROMPT_BREAK
Definition: cmd.h:285
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
void * arg
Definition: msvc.h:12
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define PROMPT_NO
Definition: cmd.h:282
#define _totupper
Definition: tchar.h:1509
Definition: match.c:390
#define PROMPT_ALL
Definition: cmd.h:284
int32_t INT
Definition: typedefs.h:56
BOOL DeleteFolder(LPTSTR FileName)
Definition: internal.c:368
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
unsigned int BOOL
Definition: ntddk_ex.h:94
VOID error_req_param_missing(VOID)
Definition: error.c:108
#define STRING_DEL_HELP2
Definition: resource.h:102
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
INT FilePromptYNA(UINT)
Definition: misc.c:665
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:26
static LPSTR * split(LPSTR s, LPINT args)
Definition: cmdcons.c:163
#define GetFullPathName
Definition: winbase.h:3635
GLuint res
Definition: glext.h:9613
#define args
Definition: format.c:66
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

◆ cmd_set()

INT cmd_set ( LPTSTR  )

Definition at line 73 of file set.c.

74 {
75  LPTSTR p;
76  LPTSTR lpEnv;
77  LPTSTR lpOutput;
78 
79  if ( !_tcsncmp (param, _T("/?"), 2) )
80  {
82  return 0;
83  }
84 
86 
87  /* if no parameters, show the environment */
88  if (param[0] == _T('\0'))
89  {
90  lpEnv = (LPTSTR)GetEnvironmentStrings ();
91  if (lpEnv)
92  {
93  lpOutput = lpEnv;
94  while (*lpOutput)
95  {
96  if (*lpOutput != _T('='))
97  ConOutPuts(lpOutput);
98  lpOutput += _tcslen(lpOutput) + 1;
99  ConOutChar(_T('\n'));
100  }
101  FreeEnvironmentStrings (lpEnv);
102  }
103 
104  return 0;
105  }
106 
107  /* the /A does *NOT* have to be followed by a whitespace */
108  if ( !_tcsnicmp (param, _T("/A"), 2) )
109  {
110  BOOL Success;
112  Success = seta_eval ( skip_ws(param+2) );
113  if (!Success)
114  {
115  /* might seem random but this is what windows xp does */
116  nErrorLevel = 9165;