Jason Edmeades : cmd: Correct handling of %~0 for batch call.
Alexandre Julliard
julliard at winehq.org
Thu Nov 29 15:09:37 CST 2018
Module: wine
Branch: stable
Commit: 7c425976069ebfac09ed3a7c6d6dd9cad1bb69fc
URL: https://source.winehq.org/git/wine.git/?a=commit;h=7c425976069ebfac09ed3a7c6d6dd9cad1bb69fc
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>
(cherry picked from commit 987fee3791d24a63aacc0b49f59275b62c943815)
Signed-off-by: Michael Stefaniuc <mstefani 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 1a78b55..d1b4dda 100644
--- a/programs/cmd/batch.c
+++ b/programs/cmd/batch.c
@@ -459,10 +459,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'],
@@ -472,12 +481,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) {
@@ -719,7 +722,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 dcc4eb7..1e4997a 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -685,6 +685,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 78cbcf1..a3eca74 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -577,6 +577,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