ReactOS  0.4.15-dev-1397-g19779b3
batch.c File Reference
#include "precomp.h"
Include dependency graph for batch.c:

Go to the source code of this file.

Functions

BOOL FindArg (IN TCHAR Char, OUT PCTSTR *ArgPtr, OUT BOOL *IsParam0)
 
static BOOL BatchParams (IN PCTSTR Arg0, IN PCTSTR Args, OUT PTSTR *RawParams, OUT PTSTR *ParamList)
 
static VOID ClearBatch (VOID)
 
VOID ExitBatch (VOID)
 
VOID ExitAllBatches (VOID)
 
static void BatchFile2Mem (HANDLE hBatchFile)
 
INT Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param, PARSED_COMMAND *Cmd)
 
VOID AddBatchRedirection (REDIRECTION **RedirList)
 
BOOL BatchGetString (LPTSTR lpBuffer, INT nBufferLength)
 
LPTSTR ReadBatchLine (VOID)
 

Variables

BATCH_TYPE BatType = NONE
 
PBATCH_CONTEXT bc = NULL
 
BOOL bBcEcho = TRUE
 
BOOL bEcho = TRUE
 
TCHAR textline [BATCH_BUFFSIZE]
 

Function Documentation

◆ AddBatchRedirection()

VOID AddBatchRedirection ( REDIRECTION **  RedirList)

Definition at line 508 of file batch.c.

509 {
511 
512  /* Prepend the list to the batch context's list */
513  ListEnd = RedirList;
514  while (*ListEnd)
515  ListEnd = &(*ListEnd)->Next;
516  *ListEnd = bc->RedirList;
517  bc->RedirList = *RedirList;
518 
519  /* Null out the pointer so that the list will not be cleared prematurely.
520  * These redirections should persist until the batch file exits. */
521  *RedirList = NULL;
522 }
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY ListEnd
Definition: exfuncs.h:1223
#define NULL
Definition: types.h:112
PBATCH_CONTEXT bc
Definition: batch.c:67
REDIRECTION * RedirList
Definition: batch.h:40

Referenced by Batch().

◆ Batch()

INT Batch ( LPTSTR  fullname,
LPTSTR  firstword,
LPTSTR  param,
PARSED_COMMAND Cmd 
)

Definition at line 300 of file batch.c.

301 {
302  INT ret = 0;
303  INT i;
304  HANDLE hFile = NULL;
305  BOOLEAN bSameFn = FALSE;
306  BOOLEAN bTopLevel;
307  BATCH_CONTEXT new;
308  PFOR_CONTEXT saved_fc;
309 
310  SetLastError(0);
311  if (bc && bc->mem)
312  {
313  TCHAR fpname[MAX_PATH];
314  GetFullPathName(fullname, ARRAYSIZE(fpname), fpname, NULL);
315  if (_tcsicmp(bc->BatchFilePath, fpname) == 0)
316  bSameFn = TRUE;
317  }
318  TRACE("Batch(\'%s\', \'%s\', \'%s\') bSameFn = %d\n",
319  debugstr_aw(fullname), debugstr_aw(firstword), debugstr_aw(param), bSameFn);
320 
321  if (!bSameFn)
322  {
326 
328  {
330  return 1;
331  }
332  }
333 
334  /*
335  * Remember whether this is a top-level batch context, i.e. if there is
336  * no batch context existing prior (bc == NULL originally), and we are
337  * going to create one below.
338  */
339  bTopLevel = !bc;
340 
341  if (bc != NULL && Cmd == bc->current)
342  {
343  /* Then we are transferring to another batch */
344  ClearBatch();
345  AddBatchRedirection(&Cmd->Redirections);
346  }
347  else
348  {
349  struct _SETLOCAL *setlocal = NULL;
350 
351  if (Cmd == NULL)
352  {
353  /* This is a CALL. CALL will set errorlevel to our return value, so
354  * in order to keep the value of errorlevel unchanged in the case
355  * of calling an empty batch file, we must return that same value. */
356  ret = nErrorLevel;
357  }
358  else if (bc)
359  {
360  /* If a batch file runs another batch file as part of a compound command
361  * (e.g. "x.bat & somethingelse") then the first file gets terminated. */
362 
363  /* Get its SETLOCAL stack so it can be migrated to the new context */
364  setlocal = bc->setlocal;
365  bc->setlocal = NULL;
366  ExitBatch();
367  }
368 
369  /* Create a new context. This function will not
370  * return until this context has been exited */
371  new.prev = bc;
372  /* copy some fields in the new structure if it is the same file */
373  if (bSameFn)
374  {
375  new.mem = bc->mem;
376  new.memsize = bc->memsize;
377  new.mempos = 0;
378  new.memfree = FALSE; /* don't free this, being used before this */
379  }
380  bc = &new;
381  bc->RedirList = NULL;
382  bc->setlocal = setlocal;
383  }
384 
386 
387  /* If a new batch file, load it into memory and close the file */
388  if (!bSameFn)
389  {
392  }
393 
394  bc->mempos = 0; /* Go to the beginning of the batch file */
395 #ifndef MSCMD_BATCH_ECHO
396  bc->bEcho = bEcho; /* Preserve echo across batch calls */
397 #endif
398  for (i = 0; i < 10; i++)
399  bc->shiftlevel[i] = i;
400 
401  /* Parse the batch parameters */
402  if (!BatchParams(firstword, param, &bc->raw_params, &bc->params))
403  return 1;
404 
405  /* If we are calling from inside a FOR, hide the FOR variables */
406  saved_fc = fc;
407  fc = NULL;
408 
409  /* Perform top-level batch initialization */
410  if (bTopLevel)
411  {
412  TCHAR *dot;
413 
414  /* Default the top-level batch context type to .BAT */
415  BatType = BAT_TYPE;
416 
417  /* If this is a .CMD file, adjust the type */
418  dot = _tcsrchr(bc->BatchFilePath, _T('.'));
419  if (dot && (!_tcsicmp(dot, _T(".cmd"))))
420  {
421  BatType = CMD_TYPE;
422  }
423 
424 #ifdef MSCMD_BATCH_ECHO
425  bBcEcho = bEcho;
426 #endif
427  }
428 
429  /* If this is a "CALL :label args ...", call a subroutine of
430  * the current batch file, only if extensions are enabled. */
431  if (bEnableExtensions && (*firstword == _T(':')))
432  {
433  LPTSTR expLabel;
434 
435  /* Position at the place of the parent file (which is the same as the caller) */
436  bc->mempos = (bc->prev ? bc->prev->mempos : 0);
437 
438  /*
439  * Jump to the label. Strip the label's colon; as a side-effect
440  * this will forbid "CALL :EOF"; however "CALL ::EOF" will work!
441  */
442  bc->current = Cmd;
443  ++firstword;
444 
445  /* Expand the label only! (simulate a GOTO command as in Windows' CMD) */
446  expLabel = DoDelayedExpansion(firstword);
447  ret = cmd_goto(expLabel ? expLabel : firstword);
448  if (expLabel)
449  cmd_free(expLabel);
450  }
451 
452  /* If we have created a new context, don't return
453  * until this batch file has completed. */
454  while (bc == &new && !bExit)
455  {
456  Cmd = ParseCommand(NULL);
457  if (!Cmd)
458  {
459  if (!bParseError)
460  continue;
461 
462  /* Echo the pre-parsed batch file line on error */
463  if (bEcho && !bDisableBatchEcho)
464  {
465  if (!bIgnoreEcho)
466  ConOutChar(_T('\n'));
467  PrintPrompt();
469  ConOutChar(_T('\n'));
470  }
471  /* Stop all execution */
472  ExitAllBatches();
473  ret = 1;
474  break;
475  }
476 
477  /* JPP 19980807 */
478  /* Echo the command and execute it */
479  bc->current = Cmd;
481  FreeCommand(Cmd);
482  }
483  if (bExit)
484  {
485  /* Stop all execution */
486  ExitAllBatches();
487  }
488 
489  /* Perform top-level batch cleanup */
490  if (!bc || bTopLevel)
491  {
492  /* Reset the top-level batch context type */
493  BatType = NONE;
494 
495 #ifdef MSCMD_BATCH_ECHO
496  bEcho = bBcEcho;
497 #endif
498  }
499 
500  /* Restore the FOR variables */
501  fc = saved_fc;
502 
503  /* Always return the last command's return code */
504  TRACE("Batch: returns %d\n", ret);
505  return ret;
506 }
INT nErrorLevel
Definition: cmd.c:158
#define NONE
Definition: ntddpar.h:94
#define CloseHandle
Definition: compat.h:598
TCHAR BatchFilePath[MAX_PATH]
Definition: batch.h:33
DWORD mempos
Definition: batch.h:31
BOOL bIgnoreEcho
Definition: cmd.c:155
#define _tcsicmp
Definition: xmlstorage.h:205
PTSTR DoDelayedExpansion(IN PCTSTR Line)
Definition: cmd.c:1638
Definition: batch.h:18
#define TRUE
Definition: types.h:120
VOID ConOutChar(TCHAR c)
Definition: console.c:123
INT cmd_goto(LPTSTR)
Definition: goto.c:36
INT ExecuteCommandWithEcho(IN PARSED_COMMAND *Cmd)
Definition: cmd.c:864
#define ConErrResPuts(uID)
Definition: console.h:39
VOID AddBatchRedirection(REDIRECTION **RedirList)
Definition: batch.c:508
#define debugstr_aw
Definition: precomp.h:43
BOOL bEcho
Definition: batch.c:73
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
PARSED_COMMAND * ParseCommand(IN PCTSTR Line)
Definition: parser.c:1461
int32_t INT
Definition: typedefs.h:58
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define FILE_SHARE_READ
Definition: compat.h:136
LPTSTR params
Definition: batch.h:34
VOID FreeCommand(IN OUT PARSED_COMMAND *Cmd)
Definition: parser.c:527
static BOOL BatchParams(IN PCTSTR Arg0, IN PCTSTR Args, OUT PTSTR *RawParams, OUT PTSTR *ParamList)
Definition: batch.c:120
#define FALSE
Definition: types.h:117
INT shiftlevel[10]
Definition: batch.h:36
VOID ExitAllBatches(VOID)
Definition: batch.c:262
struct _SETLOCAL * setlocal
Definition: batch.h:42
unsigned char BOOLEAN
VOID ExitBatch(VOID)
Definition: batch.c:223
#define OPEN_EXISTING
Definition: compat.h:634
Definition: batch.h:19
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
BATCH_TYPE BatType
Definition: batch.c:66
#define TRACE(s)
Definition: solgame.cpp:4
if(!(yy_init))
Definition: macro.lex.yy.c:714
static VOID ClearBatch(VOID)
Definition: batch.c:199
GLfloat param
Definition: glext.h:5796
#define MAX_PATH
Definition: compat.h:34
BOOL bDisableBatchEcho
Definition: cmd.c:160
#define SetLastError(x)
Definition: compat.h:611
struct _BATCH_CONTEXT * prev
Definition: batch.h:28
BOOL bEnableExtensions
Definition: cmd.c:161
PFOR_CONTEXT fc
Definition: for.c:57
int ret
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
const char * fullname
Definition: shader.c:1766
Definition: sacdrv.h:277
#define GetFullPathName
Definition: winbase.h:3661
#define GENERIC_READ
Definition: compat.h:135
_In_ HANDLE hFile
Definition: mswsock.h:90
BOOL bBcEcho
Definition: batch.c:70
char * mem
Definition: batch.h:29
LPTSTR raw_params
Definition: batch.h:35
#define cmd_free(ptr)
Definition: cmddbg.h:31
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
IN OUT PVCB OUT PDIRENT OUT PBCB IN BOOLEAN CreateFile
Definition: fatprocs.h:913
#define FILE_FLAG_SEQUENTIAL_SCAN
Definition: disk.h:43
PARSED_COMMAND * current
Definition: batch.h:41
#define NULL
Definition: types.h:112
BOOL bExit
Definition: cmd.c:152
_TCHAR * _tcsrchr(const _TCHAR *s, _XINT c)
Definition: tcsrchr.h:4
PBATCH_CONTEXT bc
Definition: batch.c:67
static void BatchFile2Mem(HANDLE hBatchFile)
Definition: batch.c:271
REDIRECTION * RedirList
Definition: batch.h:40
VOID PrintPrompt(VOID)
Definition: prompt.c:109
DWORD memsize
Definition: batch.h:30
BOOL bParseError
Definition: parser.c:90
VOID ConOutPuts(LPTSTR szText)
Definition: tee.c:27
#define STRING_BATCH_ERROR
Definition: resource.h:23
TCHAR ParseLine[CMDLINE_LENGTH]
Definition: parser.c:92

◆ BatchFile2Mem()

static void BatchFile2Mem ( HANDLE  hBatchFile)
static

Definition at line 271 of file batch.c.

272 {
273  TRACE("BatchFile2Mem()\n");
274 
275  bc->memsize = GetFileSize(hBatchFile, NULL);
276  bc->mem = (char *)cmd_alloc(bc->memsize+1); /* 1 extra for '\0' */
277 
278  /* if memory is available, read it in and close the file */
279  if (bc->mem != NULL)
280  {
281  TRACE ("BatchFile2Mem memory %08x - %08x\n",bc->mem,bc->memsize);
282  SetFilePointer (hBatchFile, 0, NULL, FILE_BEGIN);
283  ReadFile(hBatchFile, (LPVOID)bc->mem, bc->memsize, &bc->memsize, NULL);
284  bc->mem[bc->memsize]='\0'; /* end this, so you can dump it as a string */
285  bc->memfree=TRUE; /* this one needs to be freed */
286  }
287  else
288  {
289  bc->memsize=0; /* this will prevent mem being accessed */
290  bc->memfree=FALSE;
291  }
292  bc->mempos = 0; /* set position to the start */
293 }
DWORD mempos
Definition: batch.h:31
#define TRUE
Definition: types.h:120
#define FILE_BEGIN
Definition: compat.h:620
#define FALSE
Definition: types.h:117
#define TRACE(s)
Definition: solgame.cpp:4
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
BOOL memfree
Definition: batch.h:32
char * mem
Definition: batch.h:29
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define ReadFile(a, b, c, d, e)
Definition: compat.h:601
#define NULL
Definition: types.h:112
PBATCH_CONTEXT bc
Definition: batch.c:67
#define SetFilePointer
Definition: compat.h:602
DWORD memsize
Definition: batch.h:30

Referenced by Batch().

◆ BatchGetString()

BOOL BatchGetString ( LPTSTR  lpBuffer,
INT  nBufferLength 
)

Definition at line 528 of file batch.c.

529 {
530  LPSTR lpString;
531  INT len = 0;
532 #ifdef _UNICODE
533  lpString = cmd_alloc(nBufferLength);
534  if (!lpString)
535  {
536  WARN("Cannot allocate memory for lpString\n");
538  return FALSE;
539  }
540 #else
541  lpString = lpBuffer;
542 #endif
543  /* read all chars from memory until a '\n' is encountered */
544  if (bc->mem)
545  {
546  for (; (bc->mempos < bc->memsize && len < (nBufferLength-1)); len++)
547  {
548  lpString[len] = bc->mem[bc->mempos++];
549  if (lpString[len] == '\n' )
550  {
551  len++;
552  break;
553  }
554  }
555  }
556 
557  if (!len)
558  {
559 #ifdef _UNICODE
560  cmd_free(lpString);
561 #endif
562  return FALSE;
563  }
564 
565  lpString[len++] = '\0';
566 #ifdef _UNICODE
567  MultiByteToWideChar(OutputCodePage, 0, lpString, -1, lpBuffer, len);
568  cmd_free(lpString);
569 #endif
570  return TRUE;
571 }
DWORD mempos
Definition: batch.h:31
#define TRUE
Definition: types.h:120
#define WARN(fmt,...)
Definition: debug.h:112
char * LPSTR
Definition: xmlstorage.h:182
int32_t INT
Definition: typedefs.h:58
#define FALSE
Definition: types.h:117
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
VOID error_out_of_memory(VOID)
Definition: error.c:138
_In_ LPCSTR _In_opt_ LPCSTR _In_ DWORD nBufferLength
Definition: winbase.h:3034
UINT OutputCodePage
Definition: console.c:26
GLenum GLsizei len
Definition: glext.h:6722
char * mem
Definition: batch.h:29
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31
#define MultiByteToWideChar
Definition: compat.h:110
PBATCH_CONTEXT bc
Definition: batch.c:67
DWORD memsize
Definition: batch.h:30

Referenced by cmd_goto(), and ReadBatchLine().

◆ BatchParams()

static BOOL BatchParams ( IN PCTSTR  Arg0,
IN PCTSTR  Args,
OUT PTSTR RawParams,
OUT PTSTR ParamList 
)
static

Definition at line 120 of file batch.c.

125 {
126  PTSTR dp;
127  SIZE_T len;
128 
129  *RawParams = NULL;
130  *ParamList = NULL;
131 
132  /* Make a raw copy of the parameters, but trim any leading and trailing whitespace */
133  // Args += _tcsspn(Args, _T(" \t"));
134  while (_istspace(*Args))
135  ++Args;
136  dp = (PTSTR)Args + _tcslen(Args);
137  while ((dp > Args) && _istspace(*(dp - 1)))
138  --dp;
139  len = dp - Args;
140  *RawParams = (PTSTR)cmd_alloc((len + 1)* sizeof(TCHAR));
141  if (!*RawParams)
142  {
143  WARN("Cannot allocate memory for RawParams!\n");
145  return FALSE;
146  }
147  _tcsncpy(*RawParams, Args, len);
148  (*RawParams)[len] = _T('\0');
149 
150  /* Parse the parameters as well */
151  Args = *RawParams;
152 
153  *ParamList = (PTSTR)cmd_alloc((_tcslen(Arg0) + _tcslen(Args) + 3) * sizeof(TCHAR));
154  if (!*ParamList)
155  {
156  WARN("Cannot allocate memory for ParamList!\n");
158  cmd_free(*RawParams);
159  *RawParams = NULL;
160  return FALSE;
161  }
162 
163  dp = *ParamList;
164 
165  if (Arg0 && *Arg0)
166  {
167  dp = _stpcpy(dp, Arg0);
168  *dp++ = _T('\0');
169  }
170 
171  while (*Args)
172  {
173  BOOL inquotes = FALSE;
174 
175  /* Find next parameter */
176  while (_istspace(*Args) || (*Args && _tcschr(STANDARD_SEPS, *Args)))
177  ++Args;
178  if (!*Args)
179  break;
180 
181  /* Copy it */
182  do
183  {
184  if (!inquotes && (_istspace(*Args) || _tcschr(STANDARD_SEPS, *Args)))
185  break;
186  inquotes ^= (*Args == _T('"'));
187  *dp++ = *Args++;
188  } while (*Args);
189  *dp++ = _T('\0');
190  }
191  *dp = _T('\0');
192 
193  return TRUE;
194 }
#define TRUE
Definition: types.h:120
#define WARN(fmt,...)
Definition: debug.h:112
_TCHAR * _tcsncpy(_TCHAR *dst, const _TCHAR *src, size_t n)
Definition: tcsncpy.h:9
LPTSTR _stpcpy(LPTSTR, LPCTSTR)
Definition: misc.c:460
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
VOID error_out_of_memory(VOID)
Definition: error.c:138
char ** Args
Definition: acdebug.h:353
CHAR * PTSTR
Definition: xmlstorage.h:191
_TCHAR * _tcschr(const _TCHAR *s, _XINT c)
Definition: tcschr.h:4
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
GLenum GLsizei len
Definition: glext.h:6722
#define STANDARD_SEPS
Definition: cmd.h:348
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31
#define NULL
Definition: types.h:112
#define _istspace
Definition: tchar.h:1504

Referenced by Batch().

◆ ClearBatch()

static VOID ClearBatch ( VOID  )
static

Definition at line 199 of file batch.c.

200 {
201  TRACE("ClearBatch mem = %08x ; free = %d\n", bc->mem, bc->memfree);
202 
203  if (bc->mem && bc->memfree)
204  cmd_free(bc->mem);
205 
206  if (bc->raw_params)
208 
209  if (bc->params)
210  cmd_free(bc->params);
211 }
LPTSTR params
Definition: batch.h:34
#define TRACE(s)
Definition: solgame.cpp:4
BOOL memfree
Definition: batch.h:32
char * mem
Definition: batch.h:29
LPTSTR raw_params
Definition: batch.h:35
#define cmd_free(ptr)
Definition: cmddbg.h:31
PBATCH_CONTEXT bc
Definition: batch.c:67

Referenced by Batch(), and ExitBatch().

◆ ExitAllBatches()

VOID ExitAllBatches ( VOID  )

Definition at line 262 of file batch.c.

263 {
264  while (bc)
265  ExitBatch();
266 }
VOID ExitBatch(VOID)
Definition: batch.c:223
PBATCH_CONTEXT bc
Definition: batch.c:67

Referenced by Batch(), and ReadBatchLine().

◆ ExitBatch()

VOID ExitBatch ( VOID  )

Definition at line 223 of file batch.c.

224 {
225  ClearBatch();
226 
227  TRACE("ExitBatch\n");
228 
231 
232 #ifndef MSCMD_BATCH_ECHO
233  /* Preserve echo state across batch calls */
234  bEcho = bc->bEcho;
235 #endif
236 
237  while (bc->setlocal)
238  cmd_endlocal(_T(""));
239 
240  bc = bc->prev;
241 
242 #if 0
243  /* Do not process any more parts of a compound command */
244  bc->current = NULL;
245 #endif
246 
247  /* If there is no more batch contexts, notify the signal handler */
248  if (!bc)
249  {
251  BatType = NONE;
252 
253 #ifdef MSCMD_BATCH_ECHO
254  bEcho = bBcEcho;
255 #endif
256  }
257 }
BOOL CheckCtrlBreak(INT)
Definition: misc.c:132
#define NONE
Definition: ntddpar.h:94
BOOL bEcho
Definition: batch.c:73
INT cmd_endlocal(LPTSTR)
Definition: setlocal.c:110
struct _SETLOCAL * setlocal
Definition: batch.h:42
#define _T(x)
Definition: vfdio.h:22
BATCH_TYPE BatType
Definition: batch.c:66
#define TRACE(s)
Definition: solgame.cpp:4
static VOID ClearBatch(VOID)
Definition: batch.c:199
struct _BATCH_CONTEXT * prev
Definition: batch.h:28
VOID UndoRedirection(REDIRECTION *, REDIRECTION *End)
Definition: redir.c:142
BOOL bBcEcho
Definition: batch.c:70
PARSED_COMMAND * current
Definition: batch.h:41
#define BREAK_OUTOFBATCH
Definition: cmd.h:35
#define NULL
Definition: types.h:112
VOID FreeRedirection(REDIRECTION *)
Definition: redir.c:153
PBATCH_CONTEXT bc
Definition: batch.c:67
REDIRECTION * RedirList
Definition: batch.h:40

Referenced by Batch(), cmd_goto(), ExitAllBatches(), and ReadBatchLine().

◆ FindArg()

BOOL FindArg ( IN TCHAR  Char,
OUT PCTSTR ArgPtr,
OUT BOOL IsParam0 
)

Definition at line 85 of file batch.c.

89 {
90  PCTSTR pp;
91  INT n = Char - _T('0');
92 
93  TRACE("FindArg: (%d)\n", n);
94 
95  *ArgPtr = NULL;
96 
97  if (n < 0 || n > 9)
98  return FALSE;
99 
100  n = bc->shiftlevel[n];
101  *IsParam0 = (n == 0);
102  pp = bc->params;
103 
104  /* Step up the strings till we reach
105  * the end or the one we want. */
106  while (*pp && n--)
107  pp += _tcslen(pp) + 1;
108 
109  *ArgPtr = pp;
110  return TRUE;
111 }
LPCSTR PCTSTR
Definition: ntbasedef.h:489
#define TRUE
Definition: types.h:120
GLdouble n
Definition: glext.h:7729
int32_t INT
Definition: typedefs.h:58
LPTSTR params
Definition: batch.h:34
#define FALSE
Definition: types.h:117
INT shiftlevel[10]
Definition: batch.h:36
#define pp
Definition: hlsl.yy.c:1208
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
#define _T(x)
Definition: vfdio.h:22
#define TRACE(s)
Definition: solgame.cpp:4
#define NULL
Definition: types.h:112
PBATCH_CONTEXT bc
Definition: batch.c:67

Referenced by GetBatchVar().

◆ ReadBatchLine()

LPTSTR ReadBatchLine ( VOID  )

Definition at line 581 of file batch.c.

582 {
583  TRACE("ReadBatchLine()\n");
584 
585  /* User halt */
587  {
588  ExitAllBatches();
589  return NULL;
590  }
591 
593  {
594  TRACE("ReadBatchLine(): Reached EOF!\n");
595  /* End of file */
596  ExitBatch();
597  return NULL;
598  }
599 
600  TRACE("ReadBatchLine(): textline: \'%s\'\n", debugstr_aw(textline));
601 
602 #if 1
603  //
604  // FIXME: This is redundant, but keep it for the moment until we correctly
605  // hande the end-of-file situation here, in ReadLine() and in the parser.
606  // (In an EOF, the previous BatchGetString() call will return FALSE but
607  // we want not to run the ExitBatch() at first, but wait later to do it.)
608  //
609  if (textline[_tcslen(textline) - 1] != _T('\n'))
610  _tcscat(textline, _T("\n"));
611 #endif
612 
613  return textline;
614 }
BOOL CheckCtrlBreak(INT)
Definition: misc.c:132
#define BREAK_BATCHFILE
Definition: cmd.h:34
#define debugstr_aw
Definition: precomp.h:43
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
BOOL BatchGetString(LPTSTR lpBuffer, INT nBufferLength)
Definition: batch.c:528
VOID ExitAllBatches(VOID)
Definition: batch.c:262
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
VOID ExitBatch(VOID)
Definition: batch.c:223
TCHAR textline[BATCH_BUFFSIZE]
Definition: batch.c:76
#define _T(x)
Definition: vfdio.h:22
#define TRACE(s)
Definition: solgame.cpp:4
#define NULL
Definition: types.h:112
_TCHAR * _tcscat(_TCHAR *s, const _TCHAR *append)
Definition: tcscat.h:8

Referenced by ReadLine().

Variable Documentation

◆ BatType

BATCH_TYPE BatType = NONE

Definition at line 66 of file batch.c.

Referenced by Batch(), cmd_path(), cmd_prompt(), cmd_set(), CommandAssoc(), and ExitBatch().

◆ bBcEcho

BOOL bBcEcho = TRUE

Definition at line 70 of file batch.c.

Referenced by Batch(), and ExitBatch().

◆ bc

◆ bEcho

BOOL bEcho = TRUE

Definition at line 73 of file batch.c.

Referenced by Batch(), CommandEcho(), ExecuteCommandWithEcho(), ExitBatch(), ReadFromConsole(), and ReadLine().

◆ textline

TCHAR textline[BATCH_BUFFSIZE]

Definition at line 76 of file batch.c.

Referenced by cmd_goto(), and ReadBatchLine().