ReactOS  0.4.15-dev-313-g8fde48b
for.c File Reference
#include "precomp.h"
Include dependency graph for for.c:

Go to the source code of this file.

Macros

#define RunInstance(Cmd)   ExecuteCommandWithEcho((Cmd)->Subcommands)
 

Functions

INT cmd_for (LPTSTR param)
 
static BOOL GetNextElement (TCHAR **pStart, TCHAR **pEnd)
 
static BOOL Exiting (PARSED_COMMAND *Cmd)
 
static LPTSTR ReadFileContents (FILE *InputFile, TCHAR *Buffer)
 
static INT ForF (PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer)
 
static INT ForLoop (PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer)
 
static INT ForDir (PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer, TCHAR *BufPos)
 
static INT ForRecursive (PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer, TCHAR *BufPos)
 
INT ExecuteFor (PARSED_COMMAND *Cmd)
 

Variables

LPFOR_CONTEXT fc = NULL
 

Macro Definition Documentation

◆ RunInstance

#define RunInstance (   Cmd)    ExecuteCommandWithEcho((Cmd)->Subcommands)

Definition at line 73 of file for.c.

Function Documentation

◆ cmd_for()

INT cmd_for ( LPTSTR  param)

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:128
#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:154
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

◆ ExecuteFor()

INT ExecuteFor ( PARSED_COMMAND Cmd)

Definition at line 453 of file for.c.

454 {
455  TCHAR Buffer[CMDLINE_LENGTH]; /* Buffer to hold the variable value */
456  LPTSTR BufferPtr = Buffer;
457  LPFOR_CONTEXT lpNew;
458  INT Ret;
459  LPTSTR List = DoDelayedExpansion(Cmd->For.List);
460 
461  if (!List)
462  return 1;
463 
464  /* Create our FOR context */
465  lpNew = cmd_alloc(sizeof(FOR_CONTEXT));
466  if (!lpNew)
467  {
468  WARN("Cannot allocate memory for lpNew!\n");
469  cmd_free(List);
470  return 1;
471  }
472  lpNew->prev = fc;
473  lpNew->firstvar = Cmd->For.Variable;
474  lpNew->varcount = 1;
475  lpNew->values = &BufferPtr;
476 
477  Cmd->For.Context = lpNew;
478  fc = lpNew;
479 
480  if (Cmd->For.Switches & FOR_F)
481  {
482  Ret = ForF(Cmd, List, Buffer);
483  }
484  else if (Cmd->For.Switches & FOR_LOOP)
485  {
486  Ret = ForLoop(Cmd, List, Buffer);
487  }
488  else if (Cmd->For.Switches & FOR_RECURSIVE)
489  {
490  DWORD Len = GetFullPathName(Cmd->For.Params ? Cmd->For.Params : _T("."),
491  MAX_PATH, Buffer, NULL);
492  Ret = ForRecursive(Cmd, List, Buffer, &Buffer[Len]);
493  }
494  else
495  {
496  Ret = ForDir(Cmd, List, Buffer, Buffer);
497  }
498 
499  /* Remove our context, unless someone already did that */
500  if (fc == lpNew)
501  fc = lpNew->prev;
502 
503  cmd_free(lpNew);
504  cmd_free(List);
505  return Ret;
506 }
#define WARN(fmt,...)
Definition: debug.h:112
#define CMDLINE_LENGTH
Definition: help.h:12
UINT varcount
Definition: batch.h:28
static INT ForF(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer)
Definition: for.c:119
int32_t INT
Definition: typedefs.h:57
#define FOR_F
Definition: cmd.h:210
CHAR * LPTSTR
Definition: xmlstorage.h:192
TCHAR firstvar
Definition: batch.h:27
#define FOR_LOOP
Definition: cmd.h:211
LPFOR_CONTEXT fc
Definition: for.c:53
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
char TCHAR
Definition: xmlstorage.h:189
static INT ForRecursive(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer, TCHAR *BufPos)
Definition: for.c:421
#define _T(x)
Definition: vfdio.h:22
static INT ForLoop(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer)
Definition: for.c:349
LIST_ENTRY List
Definition: psmgr.c:57
#define MAX_PATH
Definition: compat.h:26
LPTSTR DoDelayedExpansion(LPTSTR Line)
Definition: cmd.c:1427
static INT ForDir(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer, TCHAR *BufPos)
Definition: for.c:374
unsigned long DWORD
Definition: ntddk_ex.h:95
#define Len
Definition: deflate.h:82
LPTSTR * values
Definition: batch.h:29
#define FOR_RECURSIVE
Definition: cmd.h:212
Definition: sacdrv.h:277
#define GetFullPathName
Definition: winbase.h:3661
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
struct tagFORCONTEXT * prev
Definition: batch.h:26

Referenced by ExecuteCommand().

◆ Exiting()

static BOOL Exiting ( PARSED_COMMAND Cmd)
static

Definition at line 77 of file for.c.

78 {
79  /* Someone might have removed our context */
80  return bCtrlBreak || fc != Cmd->For.Context;
81 }
LPFOR_CONTEXT fc
Definition: for.c:53
Definition: sacdrv.h:277
BOOL bCtrlBreak
Definition: cmd.c:154

Referenced by ForDir(), ForF(), ForLoop(), and ForRecursive().

◆ ForDir()

static INT ForDir ( PARSED_COMMAND Cmd,
LPTSTR  List,
TCHAR Buffer,
TCHAR BufPos 
)
static

Definition at line 374 of file for.c.

375 {
376  TCHAR *Start, *End = List;
377  INT Ret = 0;
378  while (!Exiting(Cmd) && GetNextElement(&Start, &End))
379  {
380  if (BufPos + (End - Start) > &Buffer[CMDLINE_LENGTH])
381  continue;
382  memcpy(BufPos, Start, (End - Start) * sizeof(TCHAR));
383  BufPos[End - Start] = _T('\0');
384 
385  if (_tcschr(BufPos, _T('?')) || _tcschr(BufPos, _T('*')))
386  {
387  WIN32_FIND_DATA w32fd;
388  HANDLE hFind;
389  TCHAR *FilePart;
390 
391  StripQuotes(BufPos);
392  hFind = FindFirstFile(Buffer, &w32fd);
393  if (hFind == INVALID_HANDLE_VALUE)
394  continue;
395  FilePart = _tcsrchr(BufPos, _T('\\'));
396  FilePart = FilePart ? FilePart + 1 : BufPos;
397  do
398  {
399  if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
400  continue;
401  if (!(w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
402  != !(Cmd->For.Switches & FOR_DIRS))
403  continue;
404  if (_tcscmp(w32fd.cFileName, _T(".")) == 0 ||
405  _tcscmp(w32fd.cFileName, _T("..")) == 0)
406  continue;
407  _tcscpy(FilePart, w32fd.cFileName);
408  Ret = RunInstance(Cmd);
409  } while (!Exiting(Cmd) && FindNextFile(hFind, &w32fd));
410  FindClose(hFind);
411  }
412  else
413  {
414  Ret = RunInstance(Cmd);
415  }
416  }
417  return Ret;
418 }
#define FOR_DIRS
Definition: cmd.h:209
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
#define CMDLINE_LENGTH
Definition: help.h:12
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
static VOID StripQuotes(LPSTR in)
Definition: cmdcons.c:116
int32_t INT
Definition: typedefs.h:57
Definition: bufpool.h:45
#define FindFirstFile
Definition: winbase.h:3622
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
static BOOL GetNextElement(TCHAR **pStart, TCHAR **pEnd)
Definition: for.c:56
LIST_ENTRY List
Definition: psmgr.c:57
#define FindNextFile
Definition: winbase.h:3628
#define RunInstance(Cmd)
Definition: for.c:73
Definition: partlist.h:33
Definition: sacdrv.h:277
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
_TCHAR * _tcsrchr(const _TCHAR *s, _XINT c)
Definition: tcsrchr.h:4
static BOOL Exiting(PARSED_COMMAND *Cmd)
Definition: for.c:77
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

Referenced by ExecuteFor(), and ForRecursive().

◆ ForF()

static INT ForF ( PARSED_COMMAND Cmd,
LPTSTR  List,
TCHAR Buffer 
)
static

Definition at line 119 of file for.c.

120 {
121  LPTSTR Delims = _T(" \t");
122  TCHAR Eol = _T(';');
123  INT SkipLines = 0;
124  DWORD Tokens = (1 << 1);
125  BOOL RemainderVar = FALSE;
126  TCHAR StringQuote = _T('"');
127  TCHAR CommandQuote = _T('\'');
128  LPTSTR Variables[32];
129  TCHAR *Start, *End;
130  INT i;
131  INT Ret = 0;
132 
133  if (Cmd->For.Params)
134  {
135  TCHAR Quote = 0;
136  TCHAR *Param = Cmd->For.Params;
137  if (*Param == _T('"') || *Param == _T('\''))
138  Quote = *Param++;
139 
140  while (*Param && *Param != Quote)
141  {
142  if (*Param <= _T(' '))
143  {
144  Param++;
145  }
146  else if (_tcsnicmp(Param, _T("delims="), 7) == 0)
147  {
148  Param += 7;
149  /* delims=xxx: Specifies the list of characters that separate tokens */
150  Delims = Param;
151  while (*Param && *Param != Quote)
152  {
153  if (*Param == _T(' '))
154  {
155  TCHAR *FirstSpace = Param;
156  Param += _tcsspn(Param, _T(" "));
157  /* Exclude trailing spaces if this is not the last parameter */
158  if (*Param && *Param != Quote)
159  *FirstSpace = _T('\0');
160  break;
161  }
162  Param++;
163  }
164  if (*Param == Quote)
165  *Param++ = _T('\0');
166  }
167  else if (_tcsnicmp(Param, _T("eol="), 4) == 0)
168  {
169  Param += 4;
170  /* eol=c: Lines starting with this character (may be
171  * preceded by delimiters) are skipped. */
172  Eol = *Param;
173  if (Eol != _T('\0'))
174  Param++;
175  }
176  else if (_tcsnicmp(Param, _T("skip="), 5) == 0)
177  {
178  /* skip=n: Number of lines to skip at the beginning of each file */
179  SkipLines = _tcstol(Param + 5, &Param, 0);
180  if (SkipLines <= 0)
181  goto error;
182  }
183  else if (_tcsnicmp(Param, _T("tokens="), 7) == 0)
184  {
185  Param += 7;
186  /* tokens=x,y,m-n: List of token numbers (must be between
187  * 1 and 31) that will be assigned into variables. */
188  Tokens = 0;
189  while (*Param && *Param != Quote && *Param != _T('*'))
190  {
191  INT First = _tcstol(Param, &Param, 0);
192  INT Last = First;
193  if (First < 1)
194  goto error;
195  if (*Param == _T('-'))
196  {
197  /* It's a range of tokens */
198  Last = _tcstol(Param + 1, &Param, 0);
199  if (Last < First || Last > 31)
200  goto error;
201  }
202  Tokens |= (2 << Last) - (1 << First);
203 
204  if (*Param != _T(','))
205  break;
206  Param++;
207  }
208  /* With an asterisk at the end, an additional variable
209  * will be created to hold the remainder of the line
210  * (after the last token specified). */
211  if (*Param == _T('*'))
212  {
213  RemainderVar = TRUE;
214  Param++;
215  }
216  }
217  else if (_tcsnicmp(Param, _T("useback"), 7) == 0)
218  {
219  Param += 7;
220  /* usebackq: Use alternate quote characters */
221  StringQuote = _T('\'');
222  CommandQuote = _T('`');
223  /* Can be written as either "useback" or "usebackq" */
224  if (_totlower(*Param) == _T('q'))
225  Param++;
226  }
227  else
228  {
229  error:
230  error_syntax(Param);
231  return 1;
232  }
233  }
234  }
235 
236  /* Count how many variables will be set: one for each token,
237  * plus maybe one for the remainder */
238  fc->varcount = RemainderVar;
239  for (i = 1; i < 32; i++)
240  fc->varcount += (Tokens >> i & 1);
241  fc->values = Variables;
242 
243  if (*List == StringQuote || *List == CommandQuote)
244  {
245  /* Treat the entire "list" as one single element */
246  Start = List;
247  End = &List[_tcslen(List)];
248  goto single_element;
249  }
250 
251  End = List;
252  while (GetNextElement(&Start, &End))
253  {
254  FILE *InputFile;
255  LPTSTR FullInput, In, NextLine;
256  INT Skip;
257  single_element:
258 
259  if (*Start == StringQuote && End[-1] == StringQuote)
260  {
261  /* Input given directly as a string */
262  End[-1] = _T('\0');
263  FullInput = cmd_dup(Start + 1);
264  }
265  else if (*Start == CommandQuote && End[-1] == CommandQuote)
266  {
267  /* Read input from a command */
268  End[-1] = _T('\0');
269  InputFile = _tpopen(Start + 1, _T("r"));
270  if (!InputFile)
271  {
273  return 1;
274  }
275  FullInput = ReadFileContents(InputFile, Buffer);
276  _pclose(InputFile);
277  }
278  else
279  {
280  /* Read input from a file */
281  TCHAR Temp = *End;
282  *End = _T('\0');
284  InputFile = _tfopen(Start, _T("r"));
285  *End = Temp;
286  if (!InputFile)
287  {
289  return 1;
290  }
291  FullInput = ReadFileContents(InputFile, Buffer);
292  fclose(InputFile);
293  }
294 
295  if (!FullInput)
296  {
298  return 1;
299  }
300 
301  /* Loop over the input line by line */
302  In = FullInput;
303  Skip = SkipLines;
304  do
305  {
306  DWORD RemainingTokens = Tokens;
307  LPTSTR *CurVar = Variables;
308 
309  NextLine = _tcschr(In, _T('\n'));
310  if (NextLine)
311  *NextLine++ = _T('\0');
312 
313  if (--Skip >= 0)
314  continue;
315 
316  /* Ignore lines where the first token starts with the eol character */
317  In += _tcsspn(In, Delims);
318  if (*In == Eol)
319  continue;
320 
321  while ((RemainingTokens >>= 1) != 0)
322  {
323  /* Save pointer to this token in a variable if requested */
324  if (RemainingTokens & 1)
325  *CurVar++ = In;
326  /* Find end of token */
327  In += _tcscspn(In, Delims);
328  /* Nul-terminate it and advance to next token */
329  if (*In)
330  {
331  *In++ = _T('\0');
332  In += _tcsspn(In, Delims);
333  }
334  }
335  /* Save pointer to remainder of line */
336  *CurVar = In;
337 
338  /* Don't run unless the line had enough tokens to fill at least one variable */
339  if (*Variables[0])
340  Ret = RunInstance(Cmd);
341  } while (!Exiting(Cmd) && (In = NextLine) != NULL);
342  cmd_free(FullInput);
343  }
344 
345  return Ret;
346 }
#define TRUE
Definition: types.h:120
#define error(str)
Definition: mkdosfs.c:1605
ULONG SkipLines(VOID)
Definition: parser.c:275
#define _tcstol
Definition: tchar.h:594
_Check_return_opt_ _CRTIMP int __cdecl _pclose(_Inout_ FILE *_File)
UINT varcount
Definition: batch.h:28
static VOID StripQuotes(LPSTR in)
Definition: cmdcons.c:116
int32_t INT
Definition: typedefs.h:57
CHAR * LPTSTR
Definition: xmlstorage.h:192
BOOLEAN NextLine(PCHAR LineBuffer, ULONG BufferSize, FILE *File)
Definition: parser.c:230
WCHAR First[]
Definition: FormatMessage.c:11
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 _tcsnicmp
Definition: xmlstorage.h:207
LPFOR_CONTEXT fc
Definition: for.c:53
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
VOID error_out_of_memory(VOID)
Definition: error.c:140
Definition: bufpool.h:45
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
char TCHAR
Definition: xmlstorage.h:189
#define _tfopen
Definition: xmlstorage.h:196
#define _T(x)
Definition: vfdio.h:22
static BOOL GetNextElement(TCHAR **pStart, TCHAR **pEnd)
Definition: for.c:56
LIST_ENTRY List
Definition: psmgr.c:57
#define RunInstance(Cmd)
Definition: for.c:73
unsigned long DWORD
Definition: ntddk_ex.h:95
Definition: partlist.h:33
LPTSTR * values
Definition: batch.h:29
#define _totlower
Definition: tchar.h:1511
Definition: sacdrv.h:277
VOID error_sfile_not_found(LPTSTR)
Definition: error.c:102
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define _tcsspn
Definition: tchar.h:1414
VOID error_syntax(LPTSTR)
Definition: error.c:154
#define cmd_free(ptr)
Definition: cmddbg.h:31
VOID error_bad_command(LPTSTR)
Definition: error.c:126
FILE * _tpopen(const _TCHAR *cm, const _TCHAR *md)
Definition: popen.c:38
#define cmd_dup(str)
Definition: cmddbg.h:32
static LPTSTR ReadFileContents(FILE *InputFile, TCHAR *Buffer)
Definition: for.c:85
static BOOL Exiting(PARSED_COMMAND *Cmd)
Definition: for.c:77
#define _tcscspn
Definition: tchar.h:1407

Referenced by ExecuteFor().

◆ ForLoop()

static INT ForLoop ( PARSED_COMMAND Cmd,
LPTSTR  List,
TCHAR Buffer 
)
static

Definition at line 349 of file for.c.

350 {
351  enum { START, STEP, END };
352  INT params[3] = { 0, 0, 0 };
353  INT i;
354  INT Ret = 0;
355 
356  TCHAR *Start, *End = List;
357  for (i = 0; i < 3 && GetNextElement(&Start, &End); i++)
358  params[i] = _tcstol(Start, NULL, 0);
359 
360  i = params[START];
361  while (!Exiting(Cmd) &&
362  (params[STEP] >= 0 ? (i <= params[END]) : (i >= params[END])))
363  {
364  _itot(i, Buffer, 10);
365  Ret = RunInstance(Cmd);
366  i += params[STEP];
367  }
368  return Ret;
369 }
#define _tcstol
Definition: tchar.h:594
int32_t INT
Definition: typedefs.h:57
#define _itot
Definition: tchar.h:608
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
GLenum const GLfloat * params
Definition: glext.h:5645
#define STEP
Definition: input.c:1260
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
Definition: infcodes.c:25
char TCHAR
Definition: xmlstorage.h:189
static BOOL GetNextElement(TCHAR **pStart, TCHAR **pEnd)
Definition: for.c:56
LIST_ENTRY List
Definition: psmgr.c:57
#define RunInstance(Cmd)
Definition: for.c:73
Definition: partlist.h:33
Definition: sacdrv.h:277
Definition: infcodes.c:17
static BOOL Exiting(PARSED_COMMAND *Cmd)
Definition: for.c:77

Referenced by ExecuteFor().

◆ ForRecursive()

static INT ForRecursive ( PARSED_COMMAND Cmd,
LPTSTR  List,
TCHAR Buffer,
TCHAR BufPos 
)
static

Definition at line 421 of file for.c.

422 {
423  HANDLE hFind;
424  WIN32_FIND_DATA w32fd;
425  INT Ret = 0;
426 
427  if (BufPos[-1] != _T('\\'))
428  {
429  *BufPos++ = _T('\\');
430  *BufPos = _T('\0');
431  }
432 
433  Ret = ForDir(Cmd, List, Buffer, BufPos);
434 
435  _tcscpy(BufPos, _T("*"));
436  hFind = FindFirstFile(Buffer, &w32fd);
437  if (hFind == INVALID_HANDLE_VALUE)
438  return Ret;
439  do
440  {
441  if (!(w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
442  continue;
443  if (_tcscmp(w32fd.cFileName, _T(".")) == 0 ||
444  _tcscmp(w32fd.cFileName, _T("..")) == 0)
445  continue;
446  Ret = ForRecursive(Cmd, List, Buffer, _stpcpy(BufPos, w32fd.cFileName));
447  } while (!Exiting(Cmd) && FindNextFile(hFind, &w32fd));
448  FindClose(hFind);
449  return Ret;
450 }
int _tcscmp(const _TCHAR *s1, const _TCHAR *s2)
Definition: tcscmp.h:8
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
int32_t INT
Definition: typedefs.h:57
LPTSTR _stpcpy(LPTSTR, LPCTSTR)
Definition: misc.c:460
Definition: bufpool.h:45
#define FindFirstFile
Definition: winbase.h:3622
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
static INT ForRecursive(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer, TCHAR *BufPos)
Definition: for.c:421
#define _T(x)
Definition: vfdio.h:22
LIST_ENTRY List
Definition: psmgr.c:57
#define FindNextFile
Definition: winbase.h:3628
static INT ForDir(PARSED_COMMAND *Cmd, LPTSTR List, TCHAR *Buffer, TCHAR *BufPos)
Definition: for.c:374
Definition: sacdrv.h:277
static BOOL Exiting(PARSED_COMMAND *Cmd)
Definition: for.c:77
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

Referenced by ExecuteFor().

◆ GetNextElement()

static BOOL GetNextElement ( TCHAR **  pStart,
TCHAR **  pEnd 
)
static

Definition at line 56 of file for.c.

57 {
58  TCHAR *p = *pEnd;
59  BOOL InQuotes = FALSE;
60  while (_istspace(*p))
61  p++;
62  if (!*p)
63  return FALSE;
64  *pStart = p;
65  while (*p && (InQuotes || !_istspace(*p)))
66  InQuotes ^= (*p++ == _T('"'));
67  *pEnd = p;
68  return TRUE;
69 }
#define TRUE
Definition: types.h:120
unsigned int BOOL
Definition: ntddk_ex.h:94
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define _istspace
Definition: tchar.h:1504
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by ForDir(), ForF(), and ForLoop().

◆ ReadFileContents()

static LPTSTR ReadFileContents ( FILE InputFile,
TCHAR Buffer 
)
static

Definition at line 85 of file for.c.

86 {
87  SIZE_T Len = 0;
88  SIZE_T AllocLen = 1000;
89 
90  LPTSTR Contents = cmd_alloc(AllocLen * sizeof(TCHAR));
91  if (!Contents)
92  {
93  WARN("Cannot allocate memory for Contents!\n");
94  return NULL;
95  }
96 
97  while (_fgetts(Buffer, CMDLINE_LENGTH, InputFile))
98  {
99  ULONG_PTR CharsRead = _tcslen(Buffer);
100  while (Len + CharsRead >= AllocLen)
101  {
102  LPTSTR OldContents = Contents;
103  Contents = cmd_realloc(Contents, (AllocLen *= 2) * sizeof(TCHAR));
104  if (!Contents)
105  {
106  WARN("Cannot reallocate memory for Contents!\n");
107  cmd_free(OldContents);
108  return NULL;
109  }
110  }
111  _tcscpy(&Contents[Len], Buffer);
112  Len += CharsRead;
113  }
114 
115  Contents[Len] = _T('\0');
116  return Contents;
117 }
#define WARN(fmt,...)
Definition: debug.h:112
#define _fgetts
Definition: tchar.h:565
#define CMDLINE_LENGTH
Definition: help.h:12
_TCHAR * _tcscpy(_TCHAR *to, const _TCHAR *from)
Definition: tcscpy.h:8
CHAR * LPTSTR
Definition: xmlstorage.h:192
uint32_t ULONG_PTR
Definition: typedefs.h:64
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define Len
Definition: deflate.h:82
#define cmd_realloc(ptr, size)
Definition: cmddbg.h:30
ULONG_PTR SIZE_T
Definition: typedefs.h:79
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31

Referenced by ForF().

Variable Documentation

◆ fc