Dan Kegel : cmd: %~dp0 should expand to the directory containing the batch file, not the current directory.

Alexandre Julliard julliard at winehq.org
Wed Feb 3 09:33:03 CST 2010


Module: wine
Branch: master
Commit: 60fe4dae7a8c93c6e9575f29ef7a6c1824b251bb
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=60fe4dae7a8c93c6e9575f29ef7a6c1824b251bb

Author: Dan Kegel <dank at kegel.com>
Date:   Tue Feb  2 16:56:38 2010 -0800

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 deletions(-)

diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index 21d8694..28744d4 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 00bada2..2fde678 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 */




More information about the wine-cvs mailing list