1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

setdos /x-4 affects alias expansion v10 vs v13

Discussion in 'Support' started by Stefano Piccardi, Sep 21, 2011.

  1. Stefano Piccardi

    Joined:
    May 31, 2008
    Messages:
    376
    Likes Received:
    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?
     
  2. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,058
    Likes Received:
    30
    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.
     
  3. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,201
    Likes Received:
    11
    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
     
  4. Stefano Piccardi

    Joined:
    May 31, 2008
    Messages:
    376
    Likes Received:
    2
    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.
     
  5. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,021
    Likes Received:
    84
    I get exactly the same results with v12 and v13 (both display the usage
    error for "_action /do".
     
  6. Stefano Piccardi

    Joined:
    May 31, 2008
    Messages:
    376
    Likes Received:
    2
    Could a plugin affect what Vince and I are seeing and you're not seeing?
     
  7. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,058
    Likes Received:
    30
    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. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,058
    Likes Received:
    30
    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:\>
     
  9. vefatica

    Joined:
    May 20, 2008
    Messages:
    8,058
    Likes Received:
    30
    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:\>
     

Share This Page