setdos /x-4 affects alias expansion v10 vs v13

May 31, 2008
382
2
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?
 
May 20, 2008
11,400
99
Syracuse, NY, USA
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,503
16
Solon, OH, USA
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
 
May 31, 2008
382
2
If you make cp an alias instead of an environment variable, then it behaves.
Thank you, Scott, it's a nice alternative and I'll keep it in mind. Unfortunately this particular script of mine needs cp to be a variable and run in TCC/LE also, where @ALIAS isn't available.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
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]"
 
May 20, 2008
11,400
99
Syracuse, NY, USA
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:\>
 
May 20, 2008
11,400
99
Syracuse, NY, USA
Very simply, why isn't "%path" expanded below? It is expanded in v10.

Code:
v:\> alias foo `%@if[1==1,echo,echo] %path`

v:\> setdos /x-4

v:\> foo
%path

v:\>
 
Similar threads
Thread starter Title Forum Replies Date
H How to? How can I say "if the command separator is not ~ then setdos /C~" Support 8
D Alias with setdos no longer works Support 21
H tcc 16 for in mystery, connected to setdos and/or else clause Support 1
C SETDOS query, I assume? Support 0
G possible bug in SETDOS Support 4
samintz SETDOS /V2 Support 2
D Can alias pass parameters to for command? Support 3
Jay Sage Issue with CD_ENTER Alias Support 37
Jay Sage Issue with CD_LEAVE Alias Support 3
Jay Sage WAD Failure of Alias Command with /Z Option Support 14
R @select inside alias gives different (insanely small) window Support 7
kb6ojs ALIAS with multiple commands? Support 9
vefatica Can I alias @@Ctrl-Shift-Alt-u? Support 4
vefatica TPIPE in an alias? Support 2
Peter Murschall TCC V26.01.3x Debugging has problems with Alias /R Support 1
Peter Murschall CMDebug 26.01.37 has problems with Alias Support 21
samintz How to? Alias or prompt? Support 1
MickeyF expand alias in cmdline with Ctrl-F in TCC Support 21
Jay Sage Directory Alias Access to FTP Servers Support 2
rps How to? Shralias and producing history.sav, alias.sav .. Support 6
J Alias @@F5 hotkey Support 2
vefatica alias.sav not accurate Support 8
Joe Caverly Using a Directory Alias with @iniwrite fails Support 14
N multiple command alias and redirection Support 0
vefatica SETLOCAL ... ALIAS ... pipes Support 2
B TCC 21.01.50 Problem with ALIAS /r and SET /r Support 2
rps How to? Alias/Command line use of *log on/off Support 2
MickeyF alias terminating before it should Support 3
JohnQSmith ALIAS /R in TCSTART.BTM Support 9
D Alias in batch file Support 3
vefatica Can't execute @ALIAS[...] Support 5
E How to? Load Alias File on Startup Support 3
I Windows 10 console does not allow alt-F4 alias to complete Support 1
MickeyF create an alias with optional parameter Support 4
nickles Alias expansion Support 7
T scrput `` in alias or function Support 2
vefatica Alias works differenltly v16 vs. v17 Support 13
B Alias with multi line definitions not assigned Support 6
jbanaszczyk Alias with space in the name Support 3
jbanaszczyk Alias for internal command Support 8
D Clear alias parameters Support 7
T Fixed multi-line alias issue Support 13
keithg1964 WAD 16.0027 Alias /rz bug Support 8
R In addition to ALIAS /Z and FUNCTION /Z, HISTORY /Z? Support 1
tmaynard How to? Control-U alias for Escape (command line editing) Support 5
C Alias ListEmptyFldrs=??? Support 4
M How to? Put logic into an alias... Support 6
G How to? v15: Can't alias Alt-Z Support 7
nikbackm v15: Problem with ALIAS in command group Support 10
vefatica WAD DO i=1 TO %# in an alias? Support 9

Similar threads