Reactos
at listview 84 lines 2.3 kB view raw
1/* 2 * BATCH.H - A structure to preserve the context of a batch file 3 */ 4 5#pragma once 6 7/* 8 * This batch type enumeration allows us to adjust the behaviour of some commands 9 * depending on whether they are run from within a .BAT or a .CMD file. 10 * The behaviour is selected when the top-level batch file is loaded, 11 * and it remains the same for any child batch file that may be loaded later. 12 * 13 * See https://ss64.com/nt/errorlevel.html for more details. 14 */ 15typedef enum _BATCH_TYPE 16{ 17 NONE, 18 BAT_TYPE, /* Old-style DOS batch file */ 19 CMD_TYPE /* New-style NT OS/2 batch file */ 20} BATCH_TYPE; 21 22 23/* Enable this define for Windows' CMD batch-echo behaviour compatibility */ 24#define MSCMD_BATCH_ECHO 25 26typedef struct _BATCH_CONTEXT 27{ 28 struct _BATCH_CONTEXT *prev; 29 char *mem; /* batchfile content in memory */ 30 DWORD memsize; /* size of batchfile */ 31 DWORD mempos; /* current position to read from */ 32 BOOL memfree; /* true if it need to be freed when exitbatch is called */ 33 TCHAR BatchFilePath[MAX_PATH]; 34 LPTSTR params; 35 LPTSTR raw_params; /* Holds the raw params given by the input */ 36 INT shiftlevel[10]; 37#ifndef MSCMD_BATCH_ECHO 38 BOOL bEcho; /* Preserve echo flag across batch calls */ 39#endif 40 REDIRECTION *RedirList; 41 PARSED_COMMAND *current; 42 struct _SETLOCAL *setlocal; 43} BATCH_CONTEXT, *PBATCH_CONTEXT; 44 45typedef struct _FOR_CONTEXT 46{ 47 struct _FOR_CONTEXT *prev; 48 TCHAR firstvar; 49 UINT varcount; 50 LPTSTR *values; 51} FOR_CONTEXT, *PFOR_CONTEXT; 52 53 54/* 55 * The stack of current batch contexts. 56 * NULL when no batch is active. 57 */ 58extern BATCH_TYPE BatType; 59extern PBATCH_CONTEXT bc; 60extern PFOR_CONTEXT fc; 61 62#ifdef MSCMD_BATCH_ECHO 63extern BOOL bBcEcho; 64#endif 65 66extern BOOL bEcho; /* The echo flag */ 67 68#define BATCH_BUFFSIZE 8192 69 70extern TCHAR textline[BATCH_BUFFSIZE]; /* Buffer for reading Batch file lines */ 71 72 73BOOL 74FindArg( 75 IN TCHAR Char, 76 OUT PCTSTR* ArgPtr, 77 OUT BOOL* IsParam0); 78 79VOID ExitBatch(VOID); 80VOID ExitAllBatches(VOID); 81INT Batch(LPTSTR, LPTSTR, LPTSTR, PARSED_COMMAND *); 82BOOL BatchGetString(LPTSTR lpBuffer, INT nBufferLength); 83LPTSTR ReadBatchLine(VOID); 84VOID AddBatchRedirection(REDIRECTION **);