Skip to content
Snippets Groups Projects
Commit 7c425976 authored by Jason Edmeades's avatar Jason Edmeades Committed by Michael Stefaniuc
Browse files

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: default avatarJason Edmeades <us@edmeades.me.uk>
Signed-off-by: Alexandre Julliard's avatarAlexandre Julliard <julliard@winehq.org>
(cherry picked from commit 987fee37)
Signed-off-by: default avatarMichael Stefaniuc <mstefani@winehq.org>
parent 929778fc
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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)
......
......@@ -577,6 +577,9 @@ N
@drive@
''
'.eh'@or_broken@''
------------ Testing parameter zero ------------
:func parm1
[:func] [@drive@] [@path@] [test] [.cmd] [@drive@@shortpath@test.cmd]
------------ Testing variable delayed expansion ------------
--- default mode (load-time expansion)
foo
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment