Jason Edmeades : cmd: Correct handling of %~0 for batch call.

Alexandre Julliard julliard at winehq.org
Wed Aug 29 16:10:45 CDT 2018


Module: wine
Branch: master
Commit: 987fee3791d24a63aacc0b49f59275b62c943815
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=987fee3791d24a63aacc0b49f59275b62c943815

Author: Jason Edmeades <us at edmeades.me.uk>
Date:   Mon Aug 27 20:41:53 2018 +0100

cmd: Correct handling of %~0 for batch call.

When a batch label is called, %0 and %~0 should be the label being
called, and if you start adding modifiers to it (eg %~d0) then you get
details of the batch program containing the label.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=44369
Signed-off-by: Jason Edmeades <us at edmeades.me.uk>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 programs/cmd/batch.c                     | 23 +++++++++++++----------
 programs/cmd/tests/test_builtins.cmd     |  9 +++++++++
 programs/cmd/tests/test_builtins.cmd.exp |  3 +++
 3 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c
index 1ed5197..5b05d88 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -460,10 +460,19 @@ void WCMD_HandleTildaModifiers(WCHAR **start, BOOL atExecute)
   }
   if (lastModifier == firstModifier) return; /* Invalid syntax */
 
-  /* Extract the parameter to play with */
-  if (*lastModifier == '0') {
+  /* So now, firstModifier points to beginning of modifiers, lastModifier
+     points to the variable just after the modifiers. Process modifiers
+     in a specific order, remembering there could be duplicates           */
+  modifierLen = lastModifier - firstModifier;
+  finaloutput[0] = 0x00;
+
+  /* Extract the parameter to play with
+     Special case param 0 - With %~0 you get the batch label which was called
+     whereas if you start applying other modifiers to it, you get the filename
+     the batch label is in                                                     */
+  if (*lastModifier == '0' && modifierLen > 1) {
     strcpyW(outputparam, context->batchfileW);
-  } else if ((*lastModifier >= '1' && *lastModifier <= '9')) {
+  } else if ((*lastModifier >= '0' && *lastModifier <= '9')) {
     strcpyW(outputparam,
             WCMD_parameter (context -> command,
                             *lastModifier-'0' + context -> shift_count[*lastModifier-'0'],
@@ -473,12 +482,6 @@ void WCMD_HandleTildaModifiers(WCHAR **start, BOOL atExecute)
     strcpyW(outputparam, forloopcontext.variable[foridx]);
   }
 
-  /* So now, firstModifier points to beginning of modifiers, lastModifier
-     points to the variable just after the modifiers. Process modifiers
-     in a specific order, remembering there could be duplicates           */
-  modifierLen = lastModifier - firstModifier;
-  finaloutput[0] = 0x00;
-
   /* 1. Handle '~' : Strip surrounding quotes */
   if (outputparam[0]=='"' &&
       memchrW(firstModifier, '~', modifierLen) != NULL) {
@@ -728,7 +731,7 @@ void WCMD_call (WCHAR *command) {
       li.QuadPart = 0;
       li.u.LowPart = SetFilePointer(context -> h, li.u.LowPart,
                      &li.u.HighPart, FILE_CURRENT);
-      WCMD_batch (param1, command, TRUE, gotoLabel, context->h);
+      WCMD_batch (context->batchfileW, command, TRUE, gotoLabel, context->h);
       SetFilePointer(context -> h, li.u.LowPart,
                      &li.u.HighPart, FILE_BEGIN);
 
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index b36afa4..de9c889 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -687,6 +687,15 @@ echo '%~xs1'
 goto :eof
 :endEchoFuns
 
+echo ------------ Testing parameter zero ------------
+call :func parm1 parm2
+goto :endParm0
+:func
+echo %~0 %~1
+echo [%0] [%~d0] [%~p0] [%~n0] [%~x0] [%~s0]
+goto :EOF
+:endParm0
+
 echo ------------ Testing variable delayed expansion ------------
 rem NT4 doesn't support this
 echo --- default mode (load-time expansion)
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 764e454..3829318 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -578,6 +578,9 @@ N
 @drive@
 ''
 '.eh'@or_broken@''
+------------ Testing parameter zero ------------
+:func parm1
+[:func] [@drive@] [@path@] [test] [.cmd] [@drive@@shortpath at test.cmd]
 ------------ Testing variable delayed expansion ------------
 --- default mode (load-time expansion)
 foo




More information about the wine-cvs mailing list