From: Eric Pouech epouech@codeweavers.com
No longer using batch file HANDLE as a key to join the two.
Signed-off-by: Eric Pouech epouech@codeweavers.com --- programs/cmd/batch.c | 25 +++++++------------------ programs/cmd/builtins.c | 6 +++--- programs/cmd/wcmd.h | 33 +++++++++++++++++---------------- 3 files changed, 27 insertions(+), 37 deletions(-)
diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c index d2ad690967d..776f2ea326f 100644 --- a/programs/cmd/batch.c +++ b/programs/cmd/batch.c @@ -22,8 +22,6 @@ #include "wcmd.h" #include "wine/debug.h"
-extern struct env_stack *saved_environment; - WINE_DEFAULT_DEBUG_CHANNEL(cmd);
/**************************************************************************** @@ -68,12 +66,12 @@ RETURN_CODE WCMD_batch(const WCHAR *file, WCHAR *command, const WCHAR *startLabe
prev_context = context; context = LocalAlloc (LMEM_FIXED, sizeof (BATCH_CONTEXT)); - context -> h = h; + context->h = h; context->batchfileW = xstrdupW(file); - context -> command = command; - memset(context -> shift_count, 0x00, sizeof(context -> shift_count)); - context -> prev_context = prev_context; - context -> skip_rest = FALSE; + context->command = command; + memset(context->shift_count, 0x00, sizeof(context->shift_count)); + context->prev_context = prev_context; + context->skip_rest = FALSE;
/* If processing a call :label, 'goto' the label in question */ if (startLabel) { @@ -106,17 +104,8 @@ RETURN_CODE WCMD_batch(const WCHAR *file, WCHAR *command, const WCHAR *startLabe } CloseHandle (h);
-/* - * If there are outstanding setlocal's to the current context, unwind them. - */ - while (saved_environment && saved_environment->batchhandle == context->h) { - WCMD_endlocal(); - } - -/* - * If invoked by a CALL, we return to the context of our caller. Otherwise return - * to the caller's caller. - */ + /* If there are outstanding setlocal's to the current context, unwind them. */ + while (WCMD_endlocal() == NO_ERROR) {}
free(context->batchfileW); LocalFree(context); diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 2654ad750fa..a728c4141b9 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -94,7 +94,7 @@ static const WCHAR externals[][10] = { };
static HINSTANCE hinst; -struct env_stack *saved_environment; +static struct env_stack *saved_environment; static BOOL verify_mode = FALSE;
/* set /a routines work from single character operators, but some of the @@ -2372,7 +2372,7 @@ RETURN_CODE WCMD_setlocal(WCHAR *args) env_copy->strings = WCMD_dupenv (env); if (env_copy->strings) { - env_copy->batchhandle = context->h; + env_copy->context = context; env_copy->next = saved_environment; env_copy->delayedsubst = delayedsubst; delayedsubst = newdelay; @@ -2407,7 +2407,7 @@ RETURN_CODE WCMD_endlocal(void)
/* setlocal needs a saved environment from within the same context (batch program) as it was saved in */ - if (!saved_environment || saved_environment->batchhandle != context->h) + if (!saved_environment || saved_environment->context != context) return ERROR_INVALID_FUNCTION;
/* pop the old environment from the stack */ diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h index c800da59821..9f983160b06 100644 --- a/programs/cmd/wcmd.h +++ b/programs/cmd/wcmd.h @@ -253,28 +253,29 @@ int evaluate_if_condition(WCHAR *p, WCHAR **command, int *test, int *negate);
/* Data structure to hold context when executing batch files */
-typedef struct _BATCH_CONTEXT { - WCHAR *command; /* The command which invoked the batch file */ - HANDLE h; /* Handle to the open batch file */ - WCHAR *batchfileW; /* Name of same */ - int shift_count[10]; /* Offset in terms of shifts for %0 - %9 */ - struct _BATCH_CONTEXT *prev_context; /* Pointer to the previous context block */ - BOOL skip_rest; /* Skip the rest of the batch program and exit */ - CMD_NODE *toExecute; /* Commands left to be executed */ +typedef struct _BATCH_CONTEXT +{ + WCHAR *command; /* The command which invoked the batch file */ + HANDLE h; /* Handle to the open batch file */ + WCHAR *batchfileW; /* Name of same */ + int shift_count[10]; /* Offset in terms of shifts for %0 - %9 */ + struct _BATCH_CONTEXT *prev_context; /* Pointer to the previous context block */ + BOOL skip_rest; /* Skip the rest of the batch program and exit */ } BATCH_CONTEXT;
/* Data structure to handle building lists during recursive calls */
struct env_stack { - struct env_stack *next; - union { - int stackdepth; /* Only used for pushd and popd */ - WCHAR cwd; /* Only used for set/endlocal */ - } u; - WCHAR *strings; - HANDLE batchhandle; /* Used to ensure set/endlocals stay in scope */ - BOOL delayedsubst; /* Is delayed substitution in effect */ + BATCH_CONTEXT *context; + struct env_stack *next; + union + { + int stackdepth; /* Only used for pushd and popd */ + WCHAR cwd; /* Only used for set/endlocal */ + } u; + WCHAR *strings; + BOOL delayedsubst; /* Is delayed substitution in effect */ };
/* Data structure to save setlocal and pushd information */