From 60fe4dae7a8c93c6e9575f29ef7a6c1824b251bb Mon Sep 17 00:00:00 2001 From: Dan Kegel Date: Tue, 2 Feb 2010 16:56:38 -0800 Subject: [PATCH] cmd: %~dp0 should expand to the directory containing the batch file, not the current directory. --- programs/cmd/batch.c | 6 +++++- programs/cmd/wcmd.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c index 21d8694c2ff..28744d4391d 100644 --- a/programs/cmd/batch.c +++ b/programs/cmd/batch.c @@ -91,6 +91,7 @@ void WCMD_batch (WCHAR *file, WCHAR *command, int called, WCHAR *startLabel, HAN prev_context = context; context = LocalAlloc (LMEM_FIXED, sizeof (BATCH_CONTEXT)); context -> h = h; + context->batchfileW = WCMD_strdupW(string); context -> command = command; memset(context -> shift_count, 0x00, sizeof(context -> shift_count)); context -> prev_context = prev_context; @@ -122,6 +123,7 @@ void WCMD_batch (WCHAR *file, WCHAR *command, int called, WCHAR *startLabel, HAN * to the caller's caller. */ + HeapFree(GetProcessHeap(), 0, context->batchfileW); LocalFree (context); if ((prev_context != NULL) && (!called)) { prev_context -> skip_rest = TRUE; @@ -382,7 +384,9 @@ void WCMD_HandleTildaModifiers(WCHAR **start, WCHAR *forVariable, WCHAR *forValu if (lastModifier == firstModifier) return; /* Invalid syntax */ /* Extract the parameter to play with */ - if ((*lastModifier >= '0' && *lastModifier <= '9')) { + if (*lastModifier == '0') { + strcpyW(outputparam, context->batchfileW); + } else if ((*lastModifier >= '1' && *lastModifier <= '9')) { strcpyW(outputparam, WCMD_parameter (context -> command, *lastModifier-'0' + context -> shift_count[*lastModifier-'0'], NULL)); } else { diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h index 00bada249dd..2fde678d5ff 100644 --- a/programs/cmd/wcmd.h +++ b/programs/cmd/wcmd.h @@ -118,6 +118,7 @@ void WCMD_execute (WCHAR *orig_command, WCHAR *redirects, WCHAR *parameter, typedef struct { 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 */ void *prev_context; /* Pointer to the previous context block */ BOOL skip_rest; /* Skip the rest of the batch program and exit */