ReactOS  0.4.14-dev-614-gbfd8a84
misc.c File Reference
#include "precomp.h"
Include dependency graph for misc.c:

Go to the source code of this file.

Functions

TCHAR cgetchar (VOID)
 
VOID GetPathCase (TCHAR *Path, TCHAR *OutPath)
 
BOOL CheckCtrlBreak (INT mode)
 
BOOL add_entry (LPINT ac, LPTSTR **arg, LPCTSTR entry)
 
static BOOL expand (LPINT ac, LPTSTR **arg, LPCTSTR pattern)
 
LPTSTRsplit (LPTSTR s, LPINT args, BOOL expand_wildcards, BOOL handle_plus)
 
LPTSTRsplitspace (LPTSTR s, LPINT args)
 
VOID freep (LPTSTR *p)
 
LPTSTR _stpcpy (LPTSTR dest, LPCTSTR src)
 
VOID StripQuotes (TCHAR *in)
 
BOOL IsValidPathName (LPCTSTR pszPath)
 
BOOL IsExistingFile (LPCTSTR pszPath)
 
BOOL IsExistingDirectory (LPCTSTR pszPath)
 
BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength)
 
BOOL __stdcall PagePrompt (PCON_PAGER Pager, DWORD Done, DWORD Total)
 
INT FilePromptYN (UINT resID)
 
INT FilePromptYNA (UINT resID)
 

Function Documentation

◆ _stpcpy()

LPTSTR _stpcpy ( LPTSTR  dest,
LPCTSTR  src 
)

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
#define WARN(fmt,...)
Definition: debug.h:111
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
void * arg
Definition: msvc.h:10
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
uint32_t entry
Definition: isohybrid.c:63
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31

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

◆ 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
DWORD dwControlKeyState
Definition: wincon.h:233
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:174
union _KEY_EVENT_RECORD::@3176 uChar
#define VK_MENU
Definition: winuser.h:2179
union _INPUT_RECORD::@3177 Event
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:2177
#define STD_INPUT_HANDLE
Definition: winbase.h:264
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:2178
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  mode)

Definition at line 132 of file misc.c.

133 {
134  static BOOL bLeaveAll = FALSE; /* leave all batch files */
135  TCHAR options[4]; /* Yes, No, All */
136  TCHAR c;
137 
138  switch (mode)
139  {
140  case BREAK_OUTOFBATCH:
141  bLeaveAll = FALSE;
142  return FALSE;
143 
144  case BREAK_BATCHFILE:
145  {
146  if (bLeaveAll)
147  return TRUE;
148 
149  if (!bCtrlBreak)
150  return FALSE;
151 
153 
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:240
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
const GLubyte * c
Definition: glext.h:8905
#define STRING_COPY_OPTION
Definition: resource.h:20
GLenum mode
Definition: glext.h:6217
#define BREAK_OUTOFBATCH
Definition: cmd.h: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:5794
BOOL bCtrlBreak
Definition: cmd.c:154

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

◆ expand()

static BOOL expand ( LPINT  ac,
LPTSTR **  arg,
LPCTSTR  pattern 
)
static

Definition at line 215 of file misc.c.

216 {
217  HANDLE hFind;
218  WIN32_FIND_DATA FindData;
219  BOOL ok;
220  LPCTSTR pathend;
221  LPTSTR dirpart, fullname;
222 
223  pathend = _tcsrchr (pattern, _T('\\'));
224  if (NULL != pathend)
225  {
226  dirpart = cmd_alloc((pathend - pattern + 2) * sizeof(TCHAR));
227  if (!dirpart)
228  {
229  WARN("Cannot allocate memory for dirpart!\n");
230  return FALSE;
231  }
232  memcpy(dirpart, pattern, pathend - pattern + 1);
233  dirpart[pathend - pattern + 1] = _T('\0');
234  }
235  else
236  {
237  dirpart = NULL;
238  }
239  hFind = FindFirstFile (pattern, &FindData);
240  if (INVALID_HANDLE_VALUE != hFind)
241  {
242  do
243  {
244  if (NULL != dirpart)
245  {
246  fullname = cmd_alloc((_tcslen(dirpart) + _tcslen(FindData.cFileName) + 1) * sizeof(TCHAR));
247  if (!fullname)
248  {
249  WARN("Cannot allocate memory for fullname!\n");
250  ok = FALSE;
251  }
252  else
253  {
254  _tcscat (_tcscpy (fullname, dirpart), FindData.cFileName);
255  ok = add_entry(ac, arg, fullname);
256  cmd_free (fullname);
257  }
258  }
259  else
260  {
261  ok = add_entry(ac, arg, FindData.cFileName);
262  }
263  } while (FindNextFile (hFind, &FindData) && ok);
264  FindClose (hFind);
265  }
266  else
267  {
268  ok = add_entry(ac, arg, pattern);
269  }
270 
271  if (NULL != dirpart)
272  {
273  cmd_free (dirpart);
274  }
275 
276  return ok;
277 }
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
BOOL add_entry(LPINT ac, LPTSTR **arg, LPCTSTR entry)
Definition: misc.c:185
#define WARN(fmt,...)
Definition: debug.h:111
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
CHAR * LPTSTR
Definition: xmlstorage.h:192
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
#define FindFirstFile
Definition: winbase.h:3616
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define FindNextFile
Definition: winbase.h:3622
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31
#define ok(value,...)
Definition: atltest.h:57
_TCHAR * _tcscat(_TCHAR *s, const _TCHAR *append)
Definition: tcscat.h:8
_TCHAR * _tcsrchr(const _TCHAR *s, _XINT c)
Definition: tcsrchr.h:4
GLubyte * pattern
Definition: glext.h:7787
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

Referenced by aclist_Expand(), ShellBrowser::select_entry(), ShellBrowser::select_folder(), split(), and wine_fold_string().

◆ FileGetString()

BOOL FileGetString ( HANDLE  hFile,
LPTSTR  lpBuffer,
INT  nBufferLength 
)

Definition at line 514 of file misc.c.

515 {
516  LPSTR lpString;
517  DWORD dwRead;
518  INT len = 0;
519 #ifdef _UNICODE
520  lpString = cmd_alloc(nBufferLength);
521 #else
522  lpString = lpBuffer;
523 #endif
524 
525  if (ReadFile(hFile, lpString, nBufferLength - 1, &dwRead, NULL))
526  {
527  /* break at new line*/
528  CHAR *end = memchr(lpString, '\n', dwRead);
529  len = dwRead;
530  if (end)
531  {
532  len = (INT)(end - lpString) + 1;
534  }
535  }
536 
537  if (!len)
538  {
539 #ifdef _UNICODE
540  cmd_free(lpString);
541 #endif
542  return FALSE;
543  }
544 
545  lpString[len++] = '\0';
546 #ifdef _UNICODE
547  MultiByteToWideChar(OutputCodePage, 0, lpString, -1, lpBuffer, len);
548  cmd_free(lpString);
549 #endif
550  return TRUE;
551 }
#define TRUE
Definition: types.h:120
#define memchr(s, c, n)
Definition: mkisofs.h:875
char CHAR
Definition: xmlstorage.h:175
#define FILE_CURRENT
Definition: winbase.h:113
GLuint GLuint end
Definition: gl.h:1545
static INT
Definition: misc.c:33
char * LPSTR
Definition: xmlstorage.h:182
int32_t INT
Definition: typedefs.h:56
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
smooth NULL
Definition: ftsmooth.c:416
_In_ LPCSTR _In_opt_ LPCSTR _In_ DWORD nBufferLength
Definition: winbase.h:3028
UINT OutputCodePage
Definition: console.c:26
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
_In_ HANDLE hFile
Definition: mswsock.h:90
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31
#define MultiByteToWideChar
Definition: compat.h:100
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123

◆ FilePromptYN()

INT FilePromptYN ( UINT  resID)

Definition at line 601 of file misc.c.

602 {
603  TCHAR szMsg[RC_STRING_MAX_SIZE];
604 // TCHAR cKey = 0;
605 // LPTSTR szKeys = _T("yna");
606 
607  TCHAR szIn[10];
608  LPTSTR p;
609 
610  if (resID != 0)
611  ConOutResPrintf (resID);
612 
613  /* preliminary fix */
614  ConInString(szIn, 10);
615  ConOutChar(_T('\n'));
616 
617  _tcsupr (szIn);
618  for (p = szIn; _istspace (*p); p++)
619  ;
620 
622 
623  if (_tcsncmp(p, &szMsg[0], 1) == 0)
624  return PROMPT_YES;
625  else if (_tcsncmp(p, &szMsg[1], 1) == 0)
626  return PROMPT_NO;
627 #if 0
628  else if (*p == _T('\03'))
629  return PROMPT_BREAK;
630 #endif
631 
632  return PROMPT_NO;
633 
634  /* unfinished solution */
635 #if 0
637  ConInDisable();
638 
639  do
640  {
641  ConInKey (&ir);
642  cKey = _totlower (ir.Event.KeyEvent.uChar.AsciiChar);
643  if (_tcschr (szKeys, cKey[0]) == NULL)
644  cKey = 0;
645 
646 
647  }
648  while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
649  (ir.Event.KeyEvent.wVirtualKeyCode == VK_MENU) ||
650  (ir.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL));
651 
652  AddBreakHandler();
653  ConInEnable();
654 
655  if ((ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
656  ((ir.Event.KeyEvent.wVirtualKeyCode == 'C') &&
657  (ir.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))))
658  return PROMPT_BREAK;
659 
660  return PROMPT_YES;
661 #endif
662 }
VOID ConOutChar(TCHAR c)
Definition: console.c:123
static VOID ConInString(LPWSTR lpInput, DWORD dwLength)
Definition: label.c:56
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define PROMPT_BREAK
Definition: cmd.h:279
#define PROMPT_NO
Definition: cmd.h:276
#define VK_MENU
Definition: winuser.h:2179
#define VK_ESCAPE
Definition: winuser.h:2189
CHAR * LPTSTR
Definition: xmlstorage.h:192
VOID ConInKey(PINPUT_RECORD lpBuffer)
Definition: console.c:61
#define VK_SHIFT
Definition: winuser.h:2177
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
VOID ConInEnable(VOID)
Definition: console.c:46
#define ConOutResPrintf(uID,...)
Definition: console.h:48
VOID ConInDisable(VOID)
Definition: console.c:36
#define _totlower
Definition: tchar.h:1511
#define LEFT_CTRL_PRESSED
Definition: wincon.h:134
#define _tcsupr
Definition: tchar.h:1467
VOID AddBreakHandler(VOID)
Definition: cmd.c:1553
#define STRING_CHOICE_OPTION
Definition: resource.h:19
#define PROMPT_YES
Definition: cmd.h:277
HANDLE CMD_ModuleHandle
Definition: cmd.c:164
#define VK_CONTROL
Definition: winuser.h:2178
#define _istspace
Definition: tchar.h:1504
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:133
GLfloat GLfloat p
Definition: glext.h:8902
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9
#define LoadString
Definition: winuser.h:5794
VOID RemoveBreakHandler(VOID)
Definition: cmd.c:1559
#define RC_STRING_MAX_SIZE
Definition: resource.h:3

Referenced by DeleteFiles().

◆ FilePromptYNA()

INT FilePromptYNA ( UINT  resID)

Definition at line 665 of file misc.c.

666 {
667  TCHAR szMsg[RC_STRING_MAX_SIZE];
668 // TCHAR cKey = 0;
669 // LPTSTR szKeys = _T("yna");
670 
671  TCHAR szIn[10];
672  LPTSTR p;
673 
674  if (resID != 0)
675  ConOutResPrintf (resID);
676 
677  /* preliminary fix */
678  ConInString(szIn, 10);
679  ConOutChar(_T('\n'));
680 
681  _tcsupr (szIn);
682  for (p = szIn; _istspace (*p); p++)
683  ;
684 
686 
687  if (_tcsncmp(p, &szMsg[0], 1) == 0)
688  return PROMPT_YES;
689  else if (_tcsncmp(p, &szMsg[1], 1) == 0)
690  return PROMPT_NO;
691  else if (_tcsncmp(p, &szMsg[2], 1) == 0)
692  return PROMPT_ALL;
693 #if 0
694  else if (*p == _T('\03'))
695  return PROMPT_BREAK;
696 #endif
697 
698  return PROMPT_NO;
699 
700  /* unfinished solution */
701 #if 0
703  ConInDisable();
704 
705  do
706  {
707  ConInKey (&ir);
708  cKey = _totlower (ir.Event.KeyEvent.uChar.AsciiChar);
709  if (_tcschr (szKeys, cKey[0]) == NULL)
710  cKey = 0;
711  }
712  while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
713  (ir.Event.KeyEvent.wVirtualKeyCode == VK_MENU) ||
714  (ir.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL));
715 
716  AddBreakHandler();
717  ConInEnable();
718 
719  if ((ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
720  ((ir.Event.KeyEvent.wVirtualKeyCode == _T('C')) &&
721  (ir.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))))
722  return PROMPT_BREAK;
723 
724  return PROMPT_YES;
725 #endif
726 }
VOID ConOutChar(TCHAR c)
Definition: console.c:123
static VOID ConInString(LPWSTR lpInput, DWORD dwLength)
Definition: label.c:56
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define PROMPT_BREAK
Definition: cmd.h:279
#define PROMPT_NO
Definition: cmd.h:276
#define VK_MENU
Definition: winuser.h:2179
#define VK_ESCAPE
Definition: winuser.h:2189
#define PROMPT_ALL
Definition: cmd.h:278
CHAR * LPTSTR
Definition: xmlstorage.h:192
VOID ConInKey(PINPUT_RECORD lpBuffer)
Definition: console.c:61
#define VK_SHIFT
Definition: winuser.h:2177
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
VOID ConInEnable(VOID)
Definition: console.c:46
#define ConOutResPrintf(uID,...)
Definition: console.h:48
#define STRING_COPY_OPTION
Definition: resource.h:20
VOID ConInDisable(VOID)
Definition: console.c:36
#define _totlower
Definition: tchar.h:1511
#define LEFT_CTRL_PRESSED
Definition: wincon.h:134
#define _tcsupr
Definition: tchar.h:1467
VOID AddBreakHandler(VOID)
Definition: cmd.c:1553
#define PROMPT_YES
Definition: cmd.h:277
HANDLE CMD_ModuleHandle
Definition: cmd.c:164
#define VK_CONTROL
Definition: winuser.h:2178
#define _istspace
Definition: tchar.h:1504
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:133
GLfloat GLfloat p
Definition: glext.h:8902
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9
#define LoadString
Definition: winuser.h:5794
VOID RemoveBreakHandler(VOID)
Definition: cmd.c:1559
#define RC_STRING_MAX_SIZE
Definition: resource.h:3

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

◆ freep()

VOID freep ( LPTSTR p)

Definition at line 447 of file misc.c.

448 {
449  LPTSTR *q;
450 
451  if (!p)
452  return;
453 
454  q = p;
455  while (*q)
456  cmd_free(*q++);
457 
458  cmd_free(p);
459 }
CHAR * LPTSTR
Definition: xmlstorage.h:192
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
#define cmd_free(ptr)
Definition: cmddbg.h:31
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by split(), and splitspace().

◆ GetPathCase()

VOID GetPathCase ( TCHAR Path,
TCHAR OutPath 
)

Definition at line 86 of file misc.c.

87 {
88  UINT i = 0;
89  TCHAR TempPath[MAX_PATH];
90  WIN32_FIND_DATA FindFileData;
91  HANDLE hFind;
92  _tcscpy(TempPath, _T(""));
93  _tcscpy(OutPath, _T(""));
94 
95  for(i = 0; i < _tcslen(Path); i++)
96  {
97  if (Path[i] != _T('\\'))
98  {
99  _tcsncat(TempPath, &Path[i], 1);
100  if (i != _tcslen(Path) - 1)
101  continue;
102  }
103  /* Handle the base part of the path different.
104  Because if you put it into findfirstfile, it will
105  return your current folder */
106  if (_tcslen(TempPath) == 2 && TempPath[1] == _T(':'))
107  {
108  _tcscat(OutPath, TempPath);
109  _tcscat(OutPath, _T("\\"));
110  _tcscat(TempPath, _T("\\"));
111  }
112  else
113  {
114  hFind = FindFirstFile(TempPath,&FindFileData);
115  if (hFind == INVALID_HANDLE_VALUE)
116  {
117  _tcscpy(OutPath, Path);
118  return;
119  }
120  _tcscat(TempPath, _T("\\"));
121  _tcscat(OutPath, FindFileData.cFileName);
122  _tcscat(OutPath, _T("\\"));
123  FindClose(hFind);
124  }
125  }
126 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
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
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
#define FindFirstFile
Definition: winbase.h:3616
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
#define MAX_PATH
Definition: compat.h:26
PRTL_UNICODE_STRING_BUFFER Path
unsigned int UINT
Definition: ndis.h:50
_TCHAR * _tcscat(_TCHAR *s, const _TCHAR *append)
Definition: tcscat.h:8
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

Referenced by replace(), and SetRootPath().

◆ IsExistingDirectory()

BOOL IsExistingDirectory ( LPCTSTR  pszPath)

Definition at line 507 of file misc.c.

508 {
509  DWORD attr = GetFileAttributes (pszPath);
510  return (attr != 0xFFFFFFFF && (attr & FILE_ATTRIBUTE_DIRECTORY) );
511 }
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
unsigned long DWORD
Definition: ntddk_ex.h:95
Definition: cookie.c:201
#define GetFileAttributes
Definition: winbase.h:3649

Referenced by cmd_copy(), cmd_move(), cmd_replace(), DeleteFiles(), GetDirectory(), ProcessDirectory(), recFindSubDirs(), and ResolvePattern().

◆ IsExistingFile()

BOOL IsExistingFile ( LPCTSTR  pszPath)

Definition at line 500 of file misc.c.

501 {
502  DWORD attr = GetFileAttributes (pszPath);
503  return (attr != 0xFFFFFFFF && (! (attr & FILE_ATTRIBUTE_DIRECTORY)) );
504 }
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
unsigned long DWORD
Definition: ntddk_ex.h:95
Definition: cookie.c:201
#define GetFileAttributes
Definition: winbase.h:3649

Referenced by Cleanup(), cmd_copy(), cmd_move(), cmd_replace(), copy(), DoCommand(), Initialize(), recFindSubDirs(), recReplace(), replace(), and SearchForExecutableSingle().

◆ IsValidPathName()

BOOL IsValidPathName ( LPCTSTR  pszPath)

Definition at line 483 of file misc.c.

484 {
485  TCHAR szOldPath[MAX_PATH];
486  BOOL bResult;
487 
488  GetCurrentDirectory (MAX_PATH, szOldPath);
489  bResult = SetCurrentDirectory (pszPath);
490 
491  SetCurrentDirectory (szOldPath);
492 
493  return bResult;
494 }
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetCurrentDirectory
Definition: winbase.h:3639
char TCHAR
Definition: xmlstorage.h:189
#define MAX_PATH
Definition: compat.h:26
#define SetCurrentDirectory
Definition: winbase.h:3737

◆ PagePrompt()

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

Definition at line 554 of file misc.c.

555 {
556  SHORT iScreenWidth, iCursorY;
557  INPUT_RECORD ir;
558 
560 
562  ConInDisable();
563 
564  do
565  {
566  ConInKey(&ir);
567  }
568  while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
571 
572  AddBreakHandler();
573  ConInEnable();
574 
575  /*
576  * Get the screen width, erase the full line where the cursor is,
577  * and move the cursor back to the beginning of the line.
578  */
579  GetScreenSize(&iScreenWidth, NULL);
580  iCursorY = GetCursorY();
581  SetCursorXY(0, iCursorY);
582  while (iScreenWidth-- > 0) // Or call FillConsoleOutputCharacter ?
583  ConOutChar(_T(' '));
584  SetCursorXY(0, iCursorY);
585 
586  if ((ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
587  ((ir.Event.KeyEvent.wVirtualKeyCode == _T('C')) &&
589  {
590  /* We break, output a newline */
591  ConOutChar(_T('\n'));
592 
593  bCtrlBreak = TRUE;
594  return FALSE;
595  }
596 
597  return TRUE;
598 }
#define TRUE
Definition: types.h:120
VOID ConOutChar(TCHAR c)
Definition: console.c:123
DWORD dwControlKeyState
Definition: wincon.h:233
#define VK_MENU
Definition: winuser.h:2179
#define VK_ESCAPE
Definition: winuser.h:2189
union _INPUT_RECORD::@3177 Event
WORD wVirtualKeyCode
Definition: wincon.h:227
VOID ConInKey(PINPUT_RECORD lpBuffer)
Definition: console.c:61
short SHORT
Definition: pedump.c:59
#define VK_SHIFT
Definition: winuser.h:2177
smooth NULL
Definition: ftsmooth.c:416
#define _T(x)
Definition: vfdio.h:22
VOID ConInEnable(VOID)
Definition: console.c:46
KEY_EVENT_RECORD KeyEvent
Definition: wincon.h:263
VOID ConInDisable(VOID)
Definition: console.c:36
#define LEFT_CTRL_PRESSED
Definition: wincon.h:134
VOID GetScreenSize(PSHORT maxx, PSHORT maxy)
Definition: console.c:236
VOID AddBreakHandler(VOID)
Definition: cmd.c:1553
VOID SetCursorXY(SHORT x, SHORT y)
Definition: console.c:191
#define STRING_MISC_HELP1
Definition: resource.h:144
#define VK_CONTROL
Definition: winuser.h:2178
SHORT GetCursorY(VOID)
Definition: console.c:218
#define ConOutResPuts(uID)
Definition: console.h:36
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:133
VOID RemoveBreakHandler(VOID)
Definition: cmd.c:1559
BOOL bCtrlBreak
Definition: cmd.c:154

◆ split()

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

Definition at line 283 of file misc.c.

284 {
285  LPTSTR *arg;
286  LPTSTR start;
287  LPTSTR q;
288  INT ac;
289  INT_PTR len;
290 
291  arg = cmd_alloc (sizeof (LPTSTR));
292  if (!arg)
293  {
294  WARN("Cannot allocate memory for arg!\n");
295  return NULL;
296  }
297  *arg = NULL;
298 
299  ac = 0;
300  while (*s)
301  {
302  BOOL bQuoted = FALSE;
303 
304  /* skip leading spaces */
305  while (*s && (_istspace(*s) || _istcntrl(*s)))
306  ++s;
307 
308  start = s;
309 
310  /* the first character can be '/' */
311  if (*s == _T('/'))
312  ++s;
313 
314  /* skip to next word delimiter or start of next option */
315  while (_istprint(*s))
316  {
317  /* if quote (") then set bQuoted */
318  bQuoted ^= (*s == _T('\"'));
319 
320  /* Check if we have unquoted text */
321  if (!bQuoted)
322  {
323  /* check for separators */
324  if (_istspace(*s) ||
325  (*s == _T('/')) ||
326  (handle_plus && (*s == _T('+'))))
327  {
328  /* Make length at least one character */
329  if (s == start) s++;
330  break;
331  }
332  }
333 
334  ++s;
335  }
336 
337  /* a word was found */
338  if (s != start)
339  {
340  q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR));
341  if (!q)
342  {
343  WARN("Cannot allocate memory for q!\n");
344  return NULL;
345  }
346  memcpy (q, start, len * sizeof (TCHAR));
347  q[len] = _T('\0');
348  StripQuotes(q);
349  if (expand_wildcards && (_T('/') != *start) &&
350  (NULL != _tcschr(q, _T('*')) || NULL != _tcschr(q, _T('?'))))
351  {
352  if (! expand(&ac, &arg, q))
353  {
354  cmd_free (q);
355  freep (arg);
356  return NULL;
357  }
358  }
359  else
360  {
361  if (! add_entry(&ac, &arg, q))
362  {
363  cmd_free (q);
364  freep (arg);
365  return NULL;
366  }
367  }
368  cmd_free (q);
369  }
370  }
371 
372  *args = ac;
373 
374  return arg;
375 }
BOOL add_entry(LPINT ac, LPTSTR **arg, LPCTSTR entry)
Definition: misc.c:185
#define WARN(fmt,...)
Definition: debug.h:111
void * arg
Definition: msvc.h:10
int32_t INT_PTR
Definition: typedefs.h:62
Definition: match.c:390
int32_t INT
Definition: typedefs.h:56
CHAR * LPTSTR
Definition: xmlstorage.h:192
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
static BOOL expand(LPINT ac, LPTSTR **arg, LPCTSTR pattern)
Definition: misc.c:215
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
#define _istcntrl
Definition: tchar.h:739
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
#define _istprint
Definition: tchar.h:1500
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31
GLuint start
Definition: gl.h:1545
VOID freep(LPTSTR *p)
Definition: misc.c:447
#define _istspace
Definition: tchar.h:1504
VOID StripQuotes(TCHAR *in)
Definition: misc.c:468

◆ splitspace()

LPTSTR* splitspace ( LPTSTR  s,
LPINT  args 
)

Definition at line 382 of file misc.c.

383 {
384  LPTSTR *arg;
385  LPTSTR start;
386  LPTSTR q;
387  INT ac;
388  INT_PTR len;
389 
390  arg = cmd_alloc (sizeof (LPTSTR));
391  if (!arg)
392  {
393  WARN("Cannot allocate memory for arg!\n");
394  return NULL;
395  }
396  *arg = NULL;
397 
398  ac = 0;
399  while (*s)
400  {
401  BOOL bQuoted = FALSE;
402 
403  /* skip leading spaces */
404  while (*s && (_istspace (*s) || _istcntrl (*s)))
405  ++s;
406 
407  start = s;
408 
409  /* skip to next word delimiter or start of next option */
410  while (_istprint(*s) && (bQuoted || !_istspace(*s)))
411  {
412  /* if quote (") then set bQuoted */
413  bQuoted ^= (*s == _T('\"'));
414  ++s;
415  }
416 
417  /* a word was found */
418  if (s != start)
419  {
420  q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR));
421  if (!q)
422  {
423  WARN("Cannot allocate memory for q!\n");
424  return NULL;
425  }
426  memcpy (q, start, len * sizeof (TCHAR));
427  q[len] = _T('\0');
428  StripQuotes(q);
429  if (! add_entry(&ac, &arg, q))
430  {
431  cmd_free (q);
432  freep (arg);
433  return NULL;
434  }
435  cmd_free (q);
436  }
437  }
438 
439  *args = ac;
440 
441  return arg;
442 }
BOOL add_entry(LPINT ac, LPTSTR **arg, LPCTSTR entry)
Definition: misc.c:185
#define WARN(fmt,...)
Definition: debug.h:111
void * arg
Definition: msvc.h:10
int32_t INT_PTR
Definition: typedefs.h:62
Definition: match.c:390
int32_t INT
Definition: typedefs.h:56
CHAR * LPTSTR
Definition: xmlstorage.h:192
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
#define _istcntrl
Definition: tchar.h:739
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
#define _istprint
Definition: tchar.h:1500
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31
GLuint start
Definition: gl.h:1545
VOID freep(LPTSTR *p)
Definition: misc.c:447
#define _istspace
Definition: tchar.h:1504
VOID StripQuotes(TCHAR *in)
Definition: misc.c:468

Referenced by cmd_move(), and cmd_setlocal().

◆ StripQuotes()

VOID StripQuotes ( TCHAR in)

Definition at line 468 of file misc.c.

469 {
470  TCHAR *out = in;
471  for (; *in; in++)
472  {
473  if (*in != _T('"'))
474  *out++ = *in;
475  }
476  *out = _T('\0');
477 }
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
static FILE * out
Definition: regtests2xml.c:44
GLuint in
Definition: glext.h:9616

Referenced by split(), and splitspace().