ReactOS 0.4.15-dev-8119-g4fb2fdb
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 (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 460 of file misc.c.

461{
462 _tcscpy (dest, src);
463 return (dest + _tcslen (src));
464}
GLenum src
Definition: glext.h:6340
#define _tcscpy
Definition: tchar.h:623
static char * dest
Definition: rtl.c:135
#define _tcslen
Definition: xmlstorage.h:198

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

◆ add_entry()

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

Definition at line 184 of file misc.c.

185{
186 LPTSTR q;
187 LPTSTR *oldarg;
188
189 q = cmd_alloc ((_tcslen(entry) + 1) * sizeof (TCHAR));
190 if (!q)
191 {
192 WARN("Cannot allocate memory for q!\n");
193 return FALSE;
194 }
195
196 _tcscpy (q, entry);
197 oldarg = *arg;
198 *arg = cmd_realloc (oldarg, (*ac + 2) * sizeof (LPTSTR));
199 if (!*arg)
200 {
201 WARN("Cannot reallocate memory for arg!\n");
202 *arg = oldarg;
203 cmd_free (q);
204 return FALSE;
205 }
206
207 /* save new entry */
208 (*arg)[*ac] = q;
209 (*arg)[++(*ac)] = NULL;
210
211 return TRUE;
212}
#define WARN(fmt,...)
Definition: debug.h:115
#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
BOOL bCtrlBreak
Definition: cmd.c:154
unsigned long DWORD
Definition: ntddk_ex.h:95
union _INPUT_RECORD::@3297 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::@3296 uChar
WCHAR UnicodeChar
Definition: wincon.h:245
#define STD_INPUT_HANDLE
Definition: winbase.h:267
#define LEFT_CTRL_PRESSED
Definition: wincon.h:140
#define ReadConsoleInput
Definition: wincon.h:778
#define KEY_EVENT
Definition: wincon.h:128
#define RIGHT_CTRL_PRESSED
Definition: wincon.h:139
#define VK_CONTROL
Definition: winuser.h:2203
#define VK_SHIFT
Definition: winuser.h:2202
#define VK_MENU
Definition: winuser.h:2204

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

◆ CheckCtrlBreak()

BOOL CheckCtrlBreak ( INT  mode)

Definition at line 132 of file misc.c.

133{
134 static BOOL bLeaveAll = FALSE; /* leave all batch files */
135 TCHAR options[4]; /* Yes, No, All */
136 TCHAR c;
137
138 switch (mode)
139 {
140 case BREAK_OUTOFBATCH:
141 bLeaveAll = FALSE;
142 return FALSE;
143
144 case BREAK_BATCHFILE:
145 {
146 if (bLeaveAll)
147 return TRUE;
148
149 if (!bCtrlBreak)
150 return FALSE;
151
153
155 do
156 {
157 c = _totupper(cgetchar());
158 } while (!(_tcschr(options, c) || c == _T('\3')) || !c);
159
160 ConOutChar(_T('\n'));
161
162 if (c == options[1])
163 {
164 bCtrlBreak = FALSE; /* ignore */
165 return FALSE;
166 }
167
168 /* leave all batch files */
169 bLeaveAll = ((c == options[2]) || (c == _T('\3')));
170 break;
171 }
172
173 case BREAK_INPUT:
174 if (!bCtrlBreak)
175 return FALSE;
176 break;
177 }
178
179 /* state processed */
180 return TRUE;
181}
HANDLE CMD_ModuleHandle
Definition: cmd.c:165
#define BREAK_INPUT
Definition: cmd.h:36
#define BREAK_BATCHFILE
Definition: cmd.h:34
#define BREAK_OUTOFBATCH
Definition: cmd.h:35
VOID ConOutChar(TCHAR c)
Definition: console.c:123
#define ConOutResPuts(uID)
Definition: console.h:35
TCHAR cgetchar(VOID)
Definition: misc.c:41
#define STRING_COPY_OPTION
Definition: resource.h:20
#define STRING_CANCEL_BATCH_FILE
Definition: resource.h:241
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
unsigned int BOOL
Definition: ntddk_ex.h:94
const GLubyte * c
Definition: glext.h:8905
GLenum mode
Definition: glext.h:6217
#define _totupper
Definition: tchar.h:1509
#define _tcschr
Definition: tchar.h:1406
#define c
Definition: ke_i.h:80
#define _T(x)
Definition: vfdio.h:22
#define LoadString
Definition: winuser.h:5819

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

◆ expand()

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

Definition at line 214 of file misc.c.

215{
216 HANDLE hFind;
217 WIN32_FIND_DATA FindData;
218 BOOL ok;
219 LPCTSTR pathend;
220 LPTSTR dirpart, fullname;
221
222 pathend = _tcsrchr (pattern, _T('\\'));
223 if (NULL != pathend)
224 {
225 dirpart = cmd_alloc((pathend - pattern + 2) * sizeof(TCHAR));
226 if (!dirpart)
227 {
228 WARN("Cannot allocate memory for dirpart!\n");
229 return FALSE;
230 }
231 memcpy(dirpart, pattern, pathend - pattern + 1);
232 dirpart[pathend - pattern + 1] = _T('\0');
233 }
234 else
235 {
236 dirpart = NULL;
237 }
238 hFind = FindFirstFile (pattern, &FindData);
239 if (INVALID_HANDLE_VALUE != hFind)
240 {
241 do
242 {
243 if (NULL != dirpart)
244 {
245 fullname = cmd_alloc((_tcslen(dirpart) + _tcslen(FindData.cFileName) + 1) * sizeof(TCHAR));
246 if (!fullname)
247 {
248 WARN("Cannot allocate memory for fullname!\n");
249 ok = FALSE;
250 }
251 else
252 {
253 _tcscat (_tcscpy (fullname, dirpart), FindData.cFileName);
254 ok = add_entry(ac, arg, fullname);
256 }
257 }
258 else
259 {
260 ok = add_entry(ac, arg, FindData.cFileName);
261 }
262 } while (FindNextFile (hFind, &FindData) && ok);
263 FindClose (hFind);
264 }
265 else
266 {
267 ok = add_entry(ac, arg, pattern);
268 }
269
270 if (NULL != dirpart)
271 {
272 cmd_free (dirpart);
273 }
274
275 return ok;
276}
#define ok(value,...)
Definition: atltest.h:57
BOOL add_entry(LPINT ac, LPTSTR **arg, LPCTSTR entry)
Definition: misc.c:184
#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:3788
#define FindFirstFile
Definition: winbase.h:3782
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 559 of file misc.c.

560{
562// TCHAR cKey = 0;
563// LPTSTR szKeys = _T("yna");
564
565 TCHAR szIn[10];
566 LPTSTR p;
567
568 if (resID != 0)
569 ConOutResPrintf (resID);
570
571 /* preliminary fix */
572 ConInString(szIn, 10);
573
574 _tcsupr (szIn);
575 for (p = szIn; _istspace (*p); p++)
576 ;
577
579
580 if (_tcsncmp(p, &szMsg[0], 1) == 0)
581 return PROMPT_YES;
582 else if (_tcsncmp(p, &szMsg[1], 1) == 0)
583 return PROMPT_NO;
584#if 0
585 else if (*p == _T('\03'))
586 return PROMPT_BREAK;
587#endif
588
589 return PROMPT_NO;
590
591 /* unfinished solution */
592#if 0
594 ConInDisable();
595
596 do
597 {
598 ConInKey (&ir);
599 cKey = _totlower (ir.Event.KeyEvent.uChar.AsciiChar);
600 if (_tcschr (szKeys, cKey[0]) == NULL)
601 cKey = 0;
602
603
604 }
605 while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
606 (ir.Event.KeyEvent.wVirtualKeyCode == VK_MENU) ||
607 (ir.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL));
608
610 ConInEnable();
611
612 if ((ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
613 ((ir.Event.KeyEvent.wVirtualKeyCode == 'C') &&
614 (ir.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))))
615 return PROMPT_BREAK;
616
617 return PROMPT_YES;
618#endif
619}
#define RC_STRING_MAX_SIZE
Definition: resource.h:3
VOID AddBreakHandler(VOID)
Definition: cmd.c:1844
VOID RemoveBreakHandler(VOID)
Definition: cmd.c:1850
#define PROMPT_YES
Definition: cmd.h:331
#define PROMPT_NO
Definition: cmd.h:330
#define PROMPT_BREAK
Definition: cmd.h:333
VOID ConInDisable(VOID)
Definition: console.c:36
VOID ConInEnable(VOID)
Definition: console.c:46
VOID ConInKey(PINPUT_RECORD lpBuffer)
Definition: console.c:61
#define ConOutResPrintf(uID,...)
Definition: console.h:47
#define STRING_CHOICE_OPTION
Definition: resource.h:19
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 VK_ESCAPE
Definition: winuser.h:2214

Referenced by DeleteFiles().

◆ FilePromptYNA()

INT FilePromptYNA ( UINT  resID)

Definition at line 622 of file misc.c.

623{
625// TCHAR cKey = 0;
626// LPTSTR szKeys = _T("yna");
627
628 TCHAR szIn[10];
629 LPTSTR p;
630
631 if (resID != 0)
632 ConOutResPrintf (resID);
633
634 /* preliminary fix */
635 ConInString(szIn, 10);
636
637 _tcsupr (szIn);
638 for (p = szIn; _istspace (*p); p++)
639 ;
640
642
643 if (_tcsncmp(p, &szMsg[0], 1) == 0)
644 return PROMPT_YES;
645 else if (_tcsncmp(p, &szMsg[1], 1) == 0)
646 return PROMPT_NO;
647 else if (_tcsncmp(p, &szMsg[2], 1) == 0)
648 return PROMPT_ALL;
649#if 0
650 else if (*p == _T('\03'))
651 return PROMPT_BREAK;
652#endif
653
654 return PROMPT_NO;
655
656 /* unfinished solution */
657#if 0
659 ConInDisable();
660
661 do
662 {
663 ConInKey (&ir);
664 cKey = _totlower (ir.Event.KeyEvent.uChar.AsciiChar);
665 if (_tcschr (szKeys, cKey[0]) == NULL)
666 cKey = 0;
667 }
668 while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
669 (ir.Event.KeyEvent.wVirtualKeyCode == VK_MENU) ||
670 (ir.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL));
671
673 ConInEnable();
674
675 if ((ir.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE) ||
676 ((ir.Event.KeyEvent.wVirtualKeyCode == _T('C')) &&
677 (ir.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))))
678 return PROMPT_BREAK;
679
680 return PROMPT_YES;
681#endif
682}
#define PROMPT_ALL
Definition: cmd.h:332

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

◆ freep()

VOID freep ( LPTSTR p)

Definition at line 446 of file misc.c.

447{
448 LPTSTR *q;
449
450 if (!p)
451 return;
452
453 q = p;
454 while (*q)
455 cmd_free(*q++);
456
457 cmd_free(p);
458}

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}
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 _tcsncat
Definition: tchar.h:1408
unsigned int UINT
Definition: ndis.h:50

Referenced by replace(), and SetRootPath().

◆ IsExistingDirectory()

BOOL IsExistingDirectory ( IN LPCTSTR  pszPath)

Definition at line 504 of file misc.c.

505{
506 DWORD attr = GetFileAttributes(pszPath);
508}
#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:3815

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 482 of file misc.c.

483{
484 BOOL bResult;
485 TCHAR szOldPath[MAX_PATH];
486
487 GetCurrentDirectory(ARRAYSIZE(szOldPath), szOldPath);
488 bResult = SetCurrentDirectory(pszPath);
489
490 SetCurrentDirectory(szOldPath);
491
492 return bResult;
493}
#define SetCurrentDirectory
Definition: winbase.h:3903
#define GetCurrentDirectory
Definition: winbase.h:3805

◆ PagePrompt()

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

Definition at line 512 of file misc.c.

513{
514 SHORT iScreenWidth, iCursorY;
515 INPUT_RECORD ir;
516
518
520 ConInDisable();
521
522 do
523 {
524 ConInKey(&ir);
525 }
526 while ((ir.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT) ||
529
531 ConInEnable();
532
533 /*
534 * Get the screen width, erase the full line where the cursor is,
535 * and move the cursor back to the beginning of the line.
536 */
537 GetScreenSize(&iScreenWidth, NULL);
538 iCursorY = GetCursorY();
539 SetCursorXY(0, iCursorY);
540 while (iScreenWidth-- > 0) // Or call FillConsoleOutputCharacter ?
541 ConOutChar(_T(' '));
542 SetCursorXY(0, iCursorY);
543
545 ((ir.Event.KeyEvent.wVirtualKeyCode == _T('C')) &&
547 {
548 /* We break, output a newline */
549 ConOutChar(_T('\n'));
550
552 return FALSE;
553 }
554
555 return TRUE;
556}
VOID SetCursorXY(SHORT x, SHORT y)
Definition: console.c:191
SHORT GetCursorY(VOID)
Definition: console.c:218
VOID GetScreenSize(PSHORT maxx, PSHORT maxy)
Definition: console.c:236
#define STRING_MISC_HELP1
Definition: resource.h:145
short SHORT
Definition: pedump.c:59

◆ split()

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

Definition at line 282 of file misc.c.

283{
284 LPTSTR *arg;
286 LPTSTR q;
287 INT ac;
288 INT_PTR len;
289
290 arg = cmd_alloc (sizeof (LPTSTR));
291 if (!arg)
292 {
293 WARN("Cannot allocate memory for arg!\n");
294 return NULL;
295 }
296 *arg = NULL;
297
298 ac = 0;
299 while (*s)
300 {
301 BOOL bQuoted = FALSE;
302
303 /* skip leading spaces */
304 while (*s && (_istspace(*s) || _istcntrl(*s)))
305 ++s;
306
307 start = s;
308
309 /* the first character can be '/' */
310 if (*s == _T('/'))
311 ++s;
312
313 /* skip to next word delimiter or start of next option */
314 while (_istprint(*s))
315 {
316 /* if quote (") then set bQuoted */
317 bQuoted ^= (*s == _T('\"'));
318
319 /* Check if we have unquoted text */
320 if (!bQuoted)
321 {
322 /* check for separators */
323 if (_istspace(*s) ||
324 (*s == _T('/')) ||
325 (handle_plus && (*s == _T('+'))))
326 {
327 /* Make length at least one character */
328 if (s == start) s++;
329 break;
330 }
331 }
332
333 ++s;
334 }
335
336 /* a word was found */
337 if (s != start)
338 {
339 q = cmd_alloc (((len = s - start) + 1) * sizeof (TCHAR));
340 if (!q)
341 {
342 WARN("Cannot allocate memory for q!\n");
343 return NULL;
344 }
345 memcpy (q, start, len * sizeof (TCHAR));
346 q[len] = _T('\0');
347 StripQuotes(q);
348 if (expand_wildcards && (_T('/') != *start) &&
349 (NULL != _tcschr(q, _T('*')) || NULL != _tcschr(q, _T('?'))))
350 {
351 if (! expand(&ac, &arg, q))
352 {
353 cmd_free (q);
354 freep (arg);
355 return NULL;
356 }
357 }
358 else
359 {
360 if (! add_entry(&ac, &arg, q))
361 {
362 cmd_free (q);
363 freep (arg);
364 return NULL;
365 }
366 }
367 cmd_free (q);
368 }
369 }
370
371 *args = ac;
372
373 return arg;
374}
VOID freep(LPTSTR *p)
Definition: misc.c:446
static BOOL expand(LPINT ac, LPTSTR **arg, LPCTSTR pattern)
Definition: misc.c:214
VOID StripQuotes(TCHAR *in)
Definition: misc.c:467
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 381 of file misc.c.

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

Referenced by cmd_move(), and cmd_setlocal().

◆ StripQuotes()

VOID StripQuotes ( TCHAR in)

Definition at line 467 of file misc.c.

468{
469 TCHAR *out = in;
470 for (; *in; in++)
471 {
472 if (*in != _T('"'))
473 *out++ = *in;
474 }
475 *out = _T('\0');
476}
GLuint in
Definition: glext.h:9616
static FILE * out
Definition: regtests2xml.c:44

Referenced by split(), and splitspace().