setdos /x-4 affects alias expansion v10 vs v13

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
May 31, 2008
376
2
#1
I'm back from another thread with a modified script. SETDOS /X-4 behaves differently between v10 and v13 wrt aliases. In simple parsing cases the two versions behave the same, but when the alias is more complicated they behave differently, and I'm partial to the way v10 works, which seems correct to me.
HTML:
@echo off
setlocal
setdos /X-4
alias _action=`%@if["/echo"=="%1",echo ]%[cp] %2 %@if[defined fDbg,/N] "%[src]%@if[%@len[%@ascii[%3]] GT 0,\%@unquotes[%3$]]" "%[tgt]"`
alias _action
set cp=copy /n
_action /echo src tgt
_action /do src tgt
unalias _action
endlocal
Run in v10 TCC/LE:
HTML:
E:\>tccle10\tcc.exe /LA /I c:\temp\qwqw.btm

TCC LE  10.00.74   Windows XP [Version 5.1.2600]

%@if["/echo"=="%1",echo ]%[cp] %2 %@if[defined fDbg,/N] "%[src]%@if[%@len[%@ascii[%3]] GT 0,\%@unquotes[%3$]]" "%[tgt]"
copy /n src  "\tgt" ""
TCC: (Sys) C:\temp\qwqw.btm [8]  The system cannot find the file specified.
 ""
     0 files would be copied
E:\...\tipi>
Don't worry that it can't find the file, there's none to find in this case. Just note that the _action alias expands to COPY /n src "\tgt" "". Version 13 won't perform that expansion. Let's see. Run in v13 TCC:
HTML:
E:\>tcmd13\tcc.exe /LA /I c:\temp\qwqw.btm

TCC  13.00.21   Windows XP [Version 5.1.2600]

%@if["/echo"=="%1",echo ]%[cp] %2 %@if[defined fDbg,/N] "%[src]%@if[%@len[%@ascii[%3]] GT 0,\%@unquotes[%3$]]" "%[tgt]"
%[cp] src %@if[defined fDbg,/N] "%[src]\tgt" ""
TCC: C:\temp\qwqw.btm [8]  Unknown command "%[cp]"

E:\>
Now comment out SETDOS /X-4 and run the script again in v13
HTML:
E:\>tcmd13\tcc.exe /LA /I c:\temp\qwqw.btm

TCC  13.00.21   Windows XP [Version 5.1.2600]

%@if["/echo"=="%1",echo ]%[cp] %2 %@if[defined fDbg,/N] "%[src]%@if[%@len[%@ascii[%3]] GT 0,\%@unquotes[%3$]]" "%[tgt]"
copy /n src  "\tgt" ""
TCC: (Sys) C:\temp\qwqw.btm [8]  The system cannot find the file specified.
 ""
     0 files would be copied

E:\>
The help file for version 13 doesn't say that SETDOS /X-4 disables variable expansion in aliases, but it does while it didn't in version 10.
Version 13 WAD or bug?

Regardless, I'd prefer to adapt my alias so it worked in v13 as in v10, with SETDOS /X-4 enabled. How could I rewrite my alias, any suggestions?

In fact, my script uses SETDOS /X-4 to allow for % in file pathnames. (yes! it's for a real use case). I've used Safecopy.dll before and would consider using it in this script, too. But how to use safecopy to deal with variables %[src] and %[tgt], which need expansion in the _action alias?
 
#2
Here's a slimmed-down version using (first) TCC 13 and (second) TCC 12. It might not be exactly what Stefano was getting at but it does show a peculiar discrepancy.

Code:
v:\> type stefano.btm
setdos /X-4
alias _action=`%@if["/echo"=="%1",echo ]%[cp]`
alias _action
set cp=copy /n
_action /echo
_action /do
unalias _action

v:\> stefano.btm
%@if["/echo"=="%1",echo ]%[cp]
%[cp]
TCC: V:\stefano.btm [6]  Unknown command "%[cp]"

v:\> start /b d:\tc12\tcc.exe /c stefano.btm

v:\> %@if["/echo"=="%1",echo ]%[cp]
%[cp]
V:\stefano.btm [6]  Usage : COPY [/A:[[-][+]rhsdaecjot] /CDEFGH /FTP:A /I"text"
/JKLM /MD /N[dejnst] /O:[-]adegnrstu /OPQR /Sn /TUVWXZ] source [+] ... [/A /B] [
TO:] destination [...] [/A /B]
Of the four opportunities to expand %[cp], it is only done by v12 and only when the @IF is false.
 

samintz

Scott Mintz
May 20, 2008
1,228
11
Solon, OH, USA
#3
If you make cp an alias instead of an environment variable, then it behaves.

PHP:
setlocal
setdos /X-4
alias _action=`%@if["/echo"=="%1",echo ,]cp`
alias _action
alias cp=copy /n
_action /echo
_action /do
endlocal
That may not be what you were asking for, but it is an alternative.
-Scott
 
#7
Today I'm seeing something different, but the same in TC12 and TC13, both started with no plugins. "%[cp]" is not expanded so I get unknown_cmd. Here's the script.

Code:
setdos /X-4
alias _action=`%@if["/echo"=="%1",echo] %[cp]`
alias _action
set cp=copy /n
_action /echo
_action /do
unalias _action
setdos /x+4
Here's it's output under TCC v13 (no plugins).

Code:
v:\> stefano.btm
%@if["/echo"=="%1",echo] %[cp]
%[cp]
TCC: V:\stefano.btm [6]  Unknown command "%[cp]"
... and with TCC v12 (no plugins).

Code:
v:\> stefano.btm
%@if["/echo"=="%1",echo] %[cp]
%[cp]
TCC: V:\stefano.btm [6]  Unknown command "%[cp]"
 
#8
Let's start over. Here's the script

Code:
v:\> type stefano.btm
setdos /X-4
alias _action=`%@if["/echo"=="%1",echo] %[cp]`
alias _action
set cp=copy /n
_action /echo
_action /do
unalias _action
setdos /x+4
When invoked directly at the command line the result is the same in both versions (no plugins); "%[cp]" is never expanded.

Code:
v:\> stefano.btm
%@if["/echo"=="%1",echo] %[cp]
%[cp]
TCC: V:\stefano.btm [6]  Unknown command "%[cp]"

v:\>
When invoked with the START command, the result is the same in both versions; "%[cp]" is expanded in the "/do" call and not in the "/echo" call.

Code:
v:\>  start /b d:\tc12\tcc.exe /c stefano.btm
%@if["/echo"=="%1",echo] %[cp]
%[cp]
V:\stefano.btm [6]  Usage : COPY [/A:[[-][+]rhsdaecjot] /CDEFGH /FTP:A /I"text" /JKLM /MD /N[dejnst] /O:[-]adegnrstu /OPQR /Sn /TUVWXZ] source [+] ... [/A /B] [TO:] destination [...] [/A /B]

v:\>