ReactOS 0.4.16-dev-336-gb667d82
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 (IN LPCTSTR Path, OUT LPTSTR 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 (IN LPCTSTR pszPath)
 
BOOL IsExistingFile (IN LPCTSTR pszPath)
 
BOOL IsExistingDirectory (IN LPCTSTR pszPath)
 
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 474 of file misc.c.

475{
476 _tcscpy (dest, src);
477 return (dest + _tcslen (src));
478}
GLenum src
Definition: glext.h:6340
#define _tcscpy
Definition: tchar.h:623
static char * dest
Definition: rtl.c:135
#define _tcslen
Definition: xmlstorage.h:198

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

◆ add_entry()

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

Definition at line 198 of file misc.c.

199{
200 LPTSTR q;
201 LPTSTR *oldarg;
202
203 q = cmd_alloc ((_tcslen(entry) + 1) * sizeof (TCHAR));
204 if (!q)
205 {
206 WARN("Cannot allocate memory for q!\n");
207 return FALSE;
208 }
209
210 _tcscpy (q, entry);
211 oldarg = *arg;
212 *arg = cmd_realloc (oldarg, (*ac + 2) * sizeof (LPTSTR));
213 if (!*arg)
214 {
215 WARN("Cannot reallocate memory for arg!\n");
216 *arg = oldarg;
217 cmd_free (q);
218 return FALSE;
219 }
220
221 /* save new entry */
222 (*arg)[*ac] = q;
223 (*arg)[++(*ac)] = NULL;
224
225 return TRUE;
226}
#define WARN(fmt,...)
Definition: precomp.h:61
#define cmd_realloc(ptr, size)
Definition: cmddbg.h:30
#define cmd_free(ptr)
Definition: cmddbg.h:31
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
uint32_t entry
Definition: isohybrid.c:63
void * arg
Definition: msvc.h:10
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192

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

◆ cgetchar()

TCHAR cgetchar ( VOID  )

Definition at line 41 of file misc.c.

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

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

◆ CheckCtrlBreak()

BOOL CheckCtrlBreak ( INT  mode)

Definition at line 146 of file misc.c.

147{
148 static BOOL bLeaveAll = FALSE; /* leave all batch files */
149 TCHAR options[4]; /* Yes, No, All */
150 TCHAR c;
151
152 switch (mode)
153 {
154 case BREAK_OUTOFBATCH:
155 bLeaveAll = FALSE;
156 return FALSE;
157
158 case BREAK_BATCHFILE:
159 {
160 if (bLeaveAll)
161 return TRUE;
162
163 if (!bCtrlBreak)
164 return FALSE;
165
167
169 do
170 {
171 c = _totupper(cgetchar());
172 } while (!(_tcschr(options, c) || c == _T('\3')) || !c);
173
174 ConOutChar(_T('\n'));
175
176 if (c == options[1])
177 {
178 bCtrlBreak = FALSE; /* ignore */
179 return FALSE;
180 }
181
182 /* leave all batch files */
183 bLeaveAll = ((c == options[2]) || (c == _T('\3')));
184 break;
185 }
186
187 case BREAK_INPUT:
188 if (!bCtrlBreak)
189 return FALSE;
190 break;
191 }
192
193 /* state processed */
194 return TRUE;
195}
#define STRING_COPY_OPTION
Definition: resource.h:22
HANDLE CMD_ModuleHandle
Definition: cmd.c:165
#define BREAK_INPUT
Definition: cmd.h:36
#define BREAK_BATCHFILE
Definition: cmd.h:34
#define BREAK_OUTOFBATCH
Definition: cmd.h:35
TCHAR cgetchar(VOID)
Definition: misc.c:41
#define STRING_CANCEL_BATCH_FILE
Definition: resource.h:230
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
unsigned int BOOL
Definition: ntddk_ex.h:94
const GLubyte * c
Definition: glext.h:8905
GLenum mode
Definition: glext.h:6217
#define _totupper
Definition: tchar.h:1509
#define _tcschr
Definition: tchar.h:1406
#define c
Definition: ke_i.h:80
VOID ConOutChar(TCHAR c)
Definition: util.c:233
#define ConOutResPuts(uID)
Definition: replace.h:28
#define _T(x)
Definition: vfdio.h:22
#define LoadString
Definition: winuser.h:5831

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

◆ expand()

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

Definition at line 228 of file misc.c.

229{
230 HANDLE hFind;
231 WIN32_FIND_DATA FindData;
232 BOOL ok;
233 LPCTSTR pathend;
234 LPTSTR dirpart, fullname;
235
236 pathend = _tcsrchr (pattern, _T('\\'));
237 if (NULL != pathend)
238 {
239 dirpart = cmd_alloc((pathend - pattern + 2) * sizeof(TCHAR));
240 if (!dirpart)
241 {
242 WARN("Cannot allocate memory for dirpart!\n");
243 return FALSE;
244 }
245 memcpy(dirpart, pattern, pathend - pattern + 1);
246 dirpart[pathend - pattern + 1] = _T('\0');
247 }
248 else
249 {
250 dirpart = NULL;
251 }
252 hFind = FindFirstFile (pattern, &FindData);
253 if (INVALID_HANDLE_VALUE != hFind)
254 {
255 do
256 {
257 if (NULL != dirpart)
258 {
259 fullname = cmd_alloc((_tcslen(dirpart) + _tcslen(FindData.cFileName) + 1) * sizeof(TCHAR));
260 if (!fullname)
261 {
262 WARN("Cannot allocate memory for fullname!\n");
263 ok = FALSE;
264 }
265 else
266 {
267 _tcscat (_tcscpy (fullname, dirpart), FindData.cFileName);
268 ok = add_entry(ac, arg, fullname);
270 }
271 }
272 else
273 {
274 ok = add_entry(ac, arg, FindData.cFileName);
275 }
276 } while (FindNextFile (hFind, &FindData) && ok);
277 FindClose (hFind);
278 }
279 else
280 {
281 ok = add_entry(ac, arg, pattern);
282 }
283
284 if (NULL != dirpart)
285 {
286 cmd_free (dirpart);
287 }
288
289 return ok;
290}
#define ok(value,...)
Definition: atltest.h:57
BOOL add_entry(LPINT ac, LPTSTR **arg, LPCTSTR entry)
Definition: misc.c:198
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
GLubyte * pattern
Definition: glext.h:7787
#define _tcscat
Definition: tchar.h:622
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define _tcsrchr
Definition: utility.h:116
const char * fullname
Definition: shader.c:1766
#define FindNextFile
Definition: winbase.h:3813
#define FindFirstFile
Definition: winbase.h:3807
const CHAR * LPCTSTR
Definition: xmlstorage.h:193

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

◆ FilePromptYN()

INT FilePromptYN ( UINT  resID)

Definition at line 573 of file misc.c.

574{
576// TCHAR cKey = 0;
577// LPTSTR szKeys = _T("yna");
578
579 TCHAR szIn[10];
580 LPTSTR p;
581
582 if (resID != 0)
583 ConOutResPrintf (resID);
584
585 /* preliminary fix */
586 ConInString(szIn, 10);
587
588 _tcsupr (szIn);
589 for (p = szIn; _istspace (*p); p++)
590 ;
591
593
594 if (_tcsncmp(p, &szMsg[0], 1) == 0)
595 return PROMPT_YES;
596 else if (_tcsncmp(p, &szMsg[1], 1) == 0)
597 return PROMPT_NO;
598#if 0
599 else if (*p == _T('\03'))
600 return PROMPT_BREAK;
601#endif
602
603 return PROMPT_NO;
604
605 /* unfinished solution */
606#if 0
608 ConInDisable();
609
610 do
611 {
612 ConInKey (&ir);
613 cKey = _totlower (ir.Event.KeyEvent.uChar.AsciiChar);
614 if (_tcschr (szKeys, cKey[0]) == NULL)
615 cKey = 0;
616
617
618 }
619 while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
620 (ir.Event.KeyEvent.wVirtualKeyCode == VK_MENU) ||
621 (ir.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL));
622
624 ConInEnable();
625
626 if ((ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
627 ((ir.Event.KeyEvent.wVirtualKeyCode == 'C') &&
628 (ir.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))))
629 return PROMPT_BREAK;
630
631 return PROMPT_YES;
632#endif
633}
#define RC_STRING_MAX_SIZE
Definition: resource.h:3
VOID AddBreakHandler(VOID)
Definition: cmd.c:1844
VOID RemoveBreakHandler(VOID)
Definition: cmd.c:1850
VOID ConInDisable(VOID)
Definition: console.c:36
VOID ConInEnable(VOID)
Definition: console.c:46
VOID ConInKey(PINPUT_RECORD lpBuffer)
Definition: console.c:61
#define STRING_CHOICE_OPTION
Definition: resource.h:26
GLfloat GLfloat p
Definition: glext.h:8902
#define _istspace
Definition: tchar.h:1504
#define _tcsupr
Definition: tchar.h:1467
#define _tcsncmp
Definition: tchar.h:1428
#define _totlower
Definition: tchar.h:1511
static VOID ConInString(LPWSTR lpInput, DWORD dwLength)
Definition: label.c:56
#define ConOutResPrintf(uID,...)
Definition: replace.h:31
#define PROMPT_YES
Definition: replace.h:21
#define PROMPT_NO
Definition: replace.h:20
#define PROMPT_BREAK
Definition: replace.h:23
#define VK_ESCAPE
Definition: winuser.h:2217

Referenced by DeleteFiles().

◆ FilePromptYNA()

INT FilePromptYNA ( UINT  resID)

Definition at line 636 of file misc.c.

637{
639// TCHAR cKey = 0;
640// LPTSTR szKeys = _T("yna");
641
642 TCHAR szIn[10];
643 LPTSTR p;
644
645 if (resID != 0)
646 ConOutResPrintf (resID);
647
648 /* preliminary fix */
649 ConInString(szIn, 10);
650
651 _tcsupr (szIn);
652 for (p = szIn; _istspace (*p); p++)
653 ;
654
656
657 if (_tcsncmp(p, &szMsg[0], 1) == 0)
658 return PROMPT_YES;
659 else if (_tcsncmp(p, &szMsg[1], 1) == 0)
660 return PROMPT_NO;
661 else if (_tcsncmp(p, &szMsg[2], 1) == 0)
662 return PROMPT_ALL;
663#if 0
664 else if (*p == _T('\03'))
665 return PROMPT_BREAK;
666#endif
667
668 return PROMPT_NO;
669
670 /* unfinished solution */
671#if 0
673 ConInDisable();
674
675 do
676 {
677 ConInKey (&ir);
678 cKey = _totlower (ir.Event.KeyEvent.uChar.AsciiChar);
679 if (_tcschr (szKeys, cKey[0]) == NULL)
680 cKey = 0;
681 }
682 while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
683 (ir.Event.KeyEvent.wVirtualKeyCode == VK_MENU) ||
684 (ir.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL));
685
687 ConInEnable();
688
689 if ((ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
690 ((ir.Event.KeyEvent.wVirtualKeyCode == _T('C')) &&
691 (ir.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))))
692 return PROMPT_BREAK;
693
694 return PROMPT_YES;
695#endif
696}
#define PROMPT_ALL
Definition: replace.h:22

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

◆ freep()

VOID freep ( LPTSTR p)

Definition at line 460 of file misc.c.

461{
462 LPTSTR *q;
463
464 if (!p)
465 return;
466
467 q = p;
468 while (*q)
469 cmd_free(*q++);
470
471 cmd_free(p);
472}

Referenced by split(), and splitspace().

◆ GetPathCase()

VOID GetPathCase ( IN LPCTSTR  Path,
OUT LPTSTR  OutPath 
)

Definition at line 86 of file misc.c.

87{
88 SIZE_T i;
89 SIZE_T cchPath = _tcslen(Path);
90 TCHAR TempPath[MAX_PATH];
91 LPTSTR pchTemp = TempPath;
92 LPTSTR pchTempEnd = TempPath + _countof(TempPath);
93 WIN32_FIND_DATA FindFileData;
94 HANDLE hFind;
95
96 *pchTemp = OutPath[0] = 0;
97
98 for (i = 0; i < cchPath; ++i)
99 {
100 if (pchTemp + 1 >= pchTempEnd)
101 {
102 // On failure, copy the original path for an error message
103 StringCchCopy(OutPath, MAX_PATH, Path);
104 return;
105 }
106
107 if (Path[i] != _T('\\') && Path[i] != _T('/'))
108 {
109 *pchTemp++ = Path[i];
110 *pchTemp = 0;
111 if (i != cchPath - 1)
112 continue;
113 }
114
115 /* Handle the base part of the path different.
116 Because if you put it into findfirstfile, it will
117 return your current folder */
118 if (TempPath[0] && TempPath[1] == _T(':') && !TempPath[2]) /* "C:", "D:" etc. */
119 {
120 StringCchCat(OutPath, MAX_PATH, TempPath);
121 StringCchCat(OutPath, MAX_PATH, _T("\\"));
122 StringCchCat(TempPath, _countof(TempPath), _T("\\"));
123 }
124 else
125 {
126 hFind = FindFirstFile(TempPath, &FindFileData);
127 if (hFind == INVALID_HANDLE_VALUE)
128 {
129 StringCchCopy(OutPath, MAX_PATH, Path);
130 return;
131 }
132 FindClose(hFind);
133 StringCchCat(OutPath, MAX_PATH, _T("\\"));
134 StringCchCat(OutPath, MAX_PATH, FindFileData.cFileName);
135 StringCchCat(OutPath, MAX_PATH, _T("\\"));
136 StringCchCopy(TempPath, _countof(TempPath), OutPath);
137 }
138 pchTemp = TempPath + _tcslen(TempPath);
139 }
140}
PRTL_UNICODE_STRING_BUFFER Path
#define MAX_PATH
Definition: compat.h:34
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 _countof(array)
Definition: sndvol32.h:70
#define StringCchCopy
Definition: strsafe.h:139
#define StringCchCat
Definition: strsafe.h:317
ULONG_PTR SIZE_T
Definition: typedefs.h:80

◆ IsExistingDirectory()

BOOL IsExistingDirectory ( IN LPCTSTR  pszPath)

Definition at line 518 of file misc.c.

519{
520 DWORD attr = GetFileAttributes(pszPath);
522}
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
Definition: cookie.c:202
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define GetFileAttributes
Definition: winbase.h:3840

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

◆ IsExistingFile()

BOOL IsExistingFile ( IN LPCTSTR  pszPath)

◆ IsValidPathName()

BOOL IsValidPathName ( IN LPCTSTR  pszPath)

Definition at line 496 of file misc.c.

497{
498 BOOL bResult;
499 TCHAR szOldPath[MAX_PATH];
500
501 GetCurrentDirectory(ARRAYSIZE(szOldPath), szOldPath);
502 bResult = SetCurrentDirectory(pszPath);
503
504 SetCurrentDirectory(szOldPath);
505
506 return bResult;
507}
#define SetCurrentDirectory
Definition: winbase.h:3928
#define GetCurrentDirectory
Definition: winbase.h:3830

◆ PagePrompt()

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

Definition at line 526 of file misc.c.

527{
528 SHORT iScreenWidth, iCursorY;
529 INPUT_RECORD ir;
530
532
534 ConInDisable();
535
536 do
537 {
538 ConInKey(&ir);
539 }
540 while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
543
545 ConInEnable();
546
547 /*
548 * Get the screen width, erase the full line where the cursor is,
549 * and move the cursor back to the beginning of the line.
550 */
551 GetScreenSize(&iScreenWidth, NULL);
552 iCursorY = GetCursorY();
553 SetCursorXY(0, iCursorY);
554 while (iScreenWidth-- > 0) // Or call FillConsoleOutputCharacter ?
555 ConOutChar(_T(' '));
556 SetCursorXY(0, iCursorY);
557
559 ((ir.Event.KeyEvent.wVirtualKeyCode == _T('C')) &&
561 {
562 /* We break, output a newline */
563 ConOutChar(_T('\n'));
564
566 return FALSE;
567 }
568
569 return TRUE;
570}
VOID SetCursorXY(SHORT x, SHORT y)
Definition: console.c:187
SHORT GetCursorY(VOID)
Definition: console.c:214
VOID GetScreenSize(PSHORT maxx, PSHORT maxy)
Definition: console.c:232
#define STRING_MISC_HELP1
Definition: resource.h:146
short SHORT
Definition: pedump.c:59

◆ split()

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

Definition at line 296 of file misc.c.

297{
298 LPTSTR *arg;
300 LPTSTR q;
301 INT ac;
302 INT_PTR len;
303
304 arg = cmd_alloc (sizeof (LPTSTR));
305 if (!arg)
306 {
307 WARN("Cannot allocate memory for arg!\n");
308 return NULL;
309 }
310 *arg = NULL;
311
312 ac = 0;
313 while (*s)
314 {
315 BOOL bQuoted = FALSE;
316
317 /* skip leading spaces */
318 while (*s && (_istspace(*s) || _istcntrl(*s)))
319 ++s;
320
321 start = s;
322
323 /* the first character can be '/' */
324 if (*s == _T('/'))
325 ++s;
326
327 /* skip to next word delimiter or start of next option */
328 while (_istprint(*s))
329 {
330 /* if quote (") then set bQuoted */
331 bQuoted ^= (*s == _T('\"'));
332
333 /* Check if we have unquoted text */
334 if (!bQuoted)
335 {
336 /* check for separators */
337 if (_istspace(*s) ||
338 (*s == _T('/')) ||
339 (handle_plus && (*s == _T('+'))))
340 {
341 /* Make length at least one character */
342 if (s == start) s++;
343 break;
344 }
345 }
346
347 ++s;
348 }
349
350 /* a word was found */
351 if (s != start)
352 {
353 q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR));
354 if (!q)
355 {
356 WARN("Cannot allocate memory for q!\n");
357 return NULL;
358 }
359 memcpy (q, start, len * sizeof (TCHAR));
360 q[len] = _T('\0');
361 StripQuotes(q);
362 if (expand_wildcards && (_T('/') != *start) &&
363 (NULL != _tcschr(q, _T('*')) || NULL != _tcschr(q, _T('?'))))
364 {
365 if (! expand(&ac, &arg, q))
366 {
367 cmd_free (q);
368 freep (arg);
369 return NULL;
370 }
371 }
372 else
373 {
374 if (! add_entry(&ac, &arg, q))
375 {
376 cmd_free (q);
377 freep (arg);
378 return NULL;
379 }
380 }
381 cmd_free (q);
382 }
383 }
384
385 *args = ac;
386
387 return arg;
388}
VOID freep(LPTSTR *p)
Definition: misc.c:460
static BOOL expand(LPINT ac, LPTSTR **arg, LPCTSTR pattern)
Definition: misc.c:228
VOID StripQuotes(TCHAR *in)
Definition: misc.c:481
GLuint start
Definition: gl.h:1545
GLdouble s
Definition: gl.h:2039
GLenum GLsizei len
Definition: glext.h:6722
#define _istcntrl
Definition: tchar.h:739
#define _istprint
Definition: tchar.h:1500
Definition: match.c:390
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58

◆ splitspace()

LPTSTR * splitspace ( LPTSTR  s,
LPINT  args 
)

Definition at line 395 of file misc.c.

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

Referenced by cmd_move(), and cmd_setlocal().

◆ StripQuotes()

VOID StripQuotes ( TCHAR in)

Definition at line 481 of file misc.c.

482{
483 TCHAR *out = in;
484 for (; *in; in++)
485 {
486 if (*in != _T('"'))
487 *out++ = *in;
488 }
489 *out = _T('\0');
490}
GLuint in
Definition: glext.h:9616
static FILE * out
Definition: regtests2xml.c:44

Referenced by split(), and splitspace().