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

One line IFF ... Then ... Else ... EndIFF Statement issue in V17

Discussion in 'Support' started by cgunhouse, Nov 12, 2014.

  1. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    I have following aliases:

    xd=`iff %@index[%@attrib[%1],D] eq 4 THEN %+ cd %1 %+ ELSE %+ nd %1 %+ ENDIFF`
    nd=md /s %1 && %1\​


    If I am in a directory where "Test" does NOT exist and run the following with echo on:

    xd Test​

    V16:

    iff %@index[%@attrib[Test],D] eq 4 THEN
    md /s Test
    Test\​

    *** It creates the directory and I end up in the new directory.

    V17:

    iff %@index[%@attrib[Test],D] eq 4 THEN​

    *** Nothing happens

    If I change the xd alias to the following:

    xd=`iff %@index[%@attrib[%1],D] ne 4 THEN %+ nd %1 %+ ELSE %+ cd %1 %+ ENDIFF`​

    Now I run:

    xd Test​

    V16:

    iff %@index[%@attrib[Test],D] ne 4 THEN
    md /s Test
    Test\​

    V17:

    iff %@index[%@attrib[Test],D] ne 4 THEN
    md /s Test
    Test\​


    This tells me that V17 ignores the "%+ ELSE %+ nd %1 %+ ENDIFF" part of the alias.

    I am using Build 51 for V17
     
  2. Jay Sage

    Joined:
    Jun 2, 2008
    Messages:
    284
    Likes Received:
    1
    I may have seen the same or a similar problem. An iff-then-else-endiff alias that used %+ as the command separator started failing with version 17. Since Rex said something about %+ being deprecated in version 17 (and requiring spaces before and after) and being discontinued in the future, I bit the bullet, changed my configuration to the default settings, and edited all my aliases and batch files to use explicit characters for multiple commands (&) and escapes (^). I have not noticed any problems since.
     
  3. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    I changed it to

    xd=`iff %@index[%@attrib[%1],D] ne 4 THEN && nd %1 && ELSE && cd %1 && ENDIFF`

    and it works in both V16 and V17 but if you just type "xd" and return on the command line V16 will generate an error message about the syntax of "IFF" and returns to the command prompt but V17 generates the same error but never returns to the command prompt. The IFF failed because a syntax error and so the "&&" would cause the parser to ignore the rest of the line, that is a problem for the parser that is now looking for a "Else" or "EndIFF", but V17 parser doesn't handle it correctly and never returns to the prompt.

    Probably the correct way to write this alias is:

    xd=`iff %@index[%@attrib[%1],D] ne 4 THEN & nd %1 & ELSE & cd %1 & ENDIFF`

    and Yes it works when there is a parameter, both V16 and V17 generate errors when there is no parameter and both return.
     
  4. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,809
    Likes Received:
    82
    && is a conditional AND; you should be using &.
     
  5. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    Yes, I mentioned this in my previous email, and I even gave a reason I believe it failed, but the command line parser failed to return to the prompt when using the "&&" in the alias. The only way to terminate it was to kill the TCC session.
     
  6. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,016
    Likes Received:
    0
    Why not just use ISDIR "%1" - it reads cleaner ....
     
  7. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,809
    Likes Received:
    82
    Although I'm actively trying to discourage people from using %+, there is *some* support remaining in v17. I've added another kludge to support it in one line IFF / THEN / ELSE statements. But that kludge will go away in v18.
     
  8. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,809
    Likes Received:
    82
    I am not able to reproduce that in build 52.
     
  9. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,888
    Likes Received:
    30
    I got it on the first try. No prompt, and no amount of banging on Ctrl-C gets it back. And TCC is using all of one processor.
    Code:
    v:\> ver
    
    TCC  17.00.52  Windows 7 [Version 6.1.7601]
    
    v:\> alias xd=`iff %@index[%@attrib[%1],D] ne 4 THEN && nd %1 && ELSE && cd %1 && ENDIFF`
    
    v:\> xd
    TCC: (Sys) The parameter is incorrect.
    ""
    Usage : IFF [NOT] condition [.AND. | .OR. | .XOR. [NOT] condition ...] THEN & commands
    
     
  10. Charles G

    Joined:
    Apr 2, 2011
    Messages:
    1,016
    Likes Received:
    0
    Why not for

    xd=`iff %@index[%@attrib[%1],D] ne 4 THEN && nd %1 && ELSE && cd %1 && ENDIFF`

    try this

    xd=`iff not isdir "%1" then && nd "%1" && else cd "%1" && endiff
     
  11. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    Well I tested it again using build 52 and it doesn't return to the prompt.

    upload_2014-11-13_8-30-18.png

    Seems to die at the "&&" when it reaches "iff %@index[%@attrib[%1],D] ne 4 THEN && nd %1 &&"
     
    #11 cgunhouse, Nov 13, 2014
    Last edited: Nov 13, 2014
  12. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    Thanks this wasn't my original definition for the alias either. Your version is both cleaner and does a better job of indicating what it does, but strangely I was looking for complexity and in some case the unusual because I have actually been testing the new V17 parser. I have actually been trying to break the TCC parser, for example the xd alias with "&&" may have the correct syntax but since "&&" is a short circuit conditional, how would the parser handle the fact that the IFF may or may not be terminated with a "EndIFF".
     
  13. Jay Sage

    Joined:
    Jun 2, 2008
    Messages:
    284
    Likes Received:
    1
    I can confirm that I see the same behavior. That instance of TCC locks up and cannot be recovered using ESC or Ctrl-C.
     
  14. cgunhouse

    Joined:
    Dec 2, 2008
    Messages:
    209
    Likes Received:
    2
    Command line parser does not crash as of Build 53
     
    gwgaston likes this.

Share This Page