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

Fixed @REREPLACE bug

Discussion in 'Support' started by Gilad Raz, Jul 24, 2012.

  1. Gilad Raz

    Joined:
    Jul 21, 2012
    Messages:
    32
    Likes Received:
    0
    (Using version TCC 14.00.29 x64 on Windows 7)

    For some reason, the following rereplace pattern outputs corrupt data and potentially crashes TCC:
    do a in *
    echo "%@rereplace["(?i)( )(..|r5)",\1,%a]"​
    enddo

    Further investigation shows that the back reference is probably the culprit of a memory overrun. Try:
    echo %@rereplace["(.)","\1",r2gggr1]​
     
  2. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    I don't understand what you're trying to do here -- why are you using a single back reference, and what do you expect to see as a result?
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,938
    Likes Received:
    30
    I figure
    echo "%@rereplace["(?i)( )(..|r5)",\1,%a]"​
    is supposed to replace a space followed by any two characters ( "|r5" is redundant) with the space alone. It's an odd thing to do and there are easier ways to do it (%@rereplace[" .."," ",%a]). And "|r5" being redundant makes (?i) needless.

    This one was given as a test.
    echo %@rereplace["(.)","\1",r2gggr1]
    All it does is replace every character with itself(!!). But it does show that something's wrong with @REREPLACE.
     
  4. Gilad Raz

    Joined:
    Jul 21, 2012
    Messages:
    32
    Likes Received:
    0
    :)

    The original intent was to perform a sub-string rename of specific files:

    The result was that the loop ran for about 1-20 cycles and then crashed TCC. I then replaced the ren line to the following:
    Which worked. Now, in order to report on the problem, I tried to reproduce it with the simplest conditions I could, and my top post is the result. So, no - there's not much sense in using the original patterns per se. Just for bug reproduction... :)

    Cheers,
    Gilad
     
  5. Gilad Raz

    Joined:
    Jul 21, 2012
    Messages:
    32
    Likes Received:
    0
    Just updated to v14.00.30 x64.
    I still get a crash and burn when I run the following command:

    Code:
    move ::"(.*)win\.*" ::"\1"
    REN works fine though.
     
  6. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    I have no idea what you're trying to do here.
     
  7. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    I interpret move ::"(.*)win\.*" ::"\1" as...

    move all files named...
    Code:
    (.*)   {grouping}zero_or_more_characters{/grouping}
    win    followed by the characters "win"
    \.*    followed by zero_or_more_periods
    ... to ...
    Code:
    \1    previous_grouping_of_zero_or_more_characters (which may or may not actually consist of any characters)
    Basically... I don't understand it either.
     
  8. Gilad Raz

    Joined:
    Jul 21, 2012
    Messages:
    32
    Likes Received:
    0
    Ooops - now I see my typo - should have been
    move ::"(.*)win\..*" ::"\1"

    Basically, rename any file with "*win.*" to the contents of the first asterisk. Originally I also move the target to ..\ directory, but for simplicity sake of bug reproduction I've omitted that part.
     
  9. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    In that case, the first regex part of your command should be
    Code:
    ::"(.+)win\..*"
    which is...
    Code:
    (.+)    {group}one_or_more_characters{/group} to make sure that there is a destination
    win     the characters "win"
    \.      dot
    .*      zero_or_more_characters
    
     
  10. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    Yeah, regexes are REALLY persnickety.
     
  11. Gilad Raz

    Joined:
    Jul 21, 2012
    Messages:
    32
    Likes Received:
    0
    :)
    I'm fine with your correction John, though in my case I knew I only had files with text in front of the "win" so it doesn't really matter. Nonetheless, even with that correction, TCC crashes. Try the following in Windows\System32:

    move /n ::"win(.+)\..*" ::"\1"

    Mine crashes on sight.
     
  12. Stefano Piccardi

    Joined:
    May 31, 2008
    Messages:
    376
    Likes Received:
    2
    I suspect that MOVE supports targets with simple asterisk wildcards only (not regex).
    Code:
    C:\temp>dir /b ::csb
    csb
    csbcmd.txt
    csbtcc.txt
     
    C:\temp>move /n ::(csb) ::x\1
    TCC: Can't COPY or MOVE file to itself "C:\temp\csb"
    0 files would be moved
     
    C:\temp>move /n ::(csb) x\1
    C:\temp\csb -> C:\temp\x\1
    TCC: Can't create "C:\temp\x\1"
    1 file would be moved
     
    C:\temp>move /n ::(csb) x*  & rem note that x replaces c
    C:\temp\csb -> C:\temp\xsb
    C:\temp\csbcmd.txt -> C:\temp\xsbcmd.txt
    C:\temp\csbtcc.txt -> C:\temp\xsbtcc.txt
    3 files would be moved
    
     
  13. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,938
    Likes Received:
    30
    From v14's help:
    Code:
    MOVE supports regular expression back references in the target name.  If you are using back references, you must also use a regular expression in the source name. The syntax is:
    move ::filename ::target
    It works OK in a very simple test.
    Code:
    v:\test> dir /k /m /h
    2012-08-01  00:54              0  abc.bat
    2012-08-01  00:54              0  def.bat
     
    v:\test> ren ::(.*\.)bat ::\1btm
    V:\test\abc.bat -> V:\test\abc.btm
    V:\test\def.bat -> V:\test\def.btm
        2 files renamed
     
    v:\test> dir /k /m /h
    2012-08-01  00:54              0  abc.btm
    2012-08-01  00:54              0  def.btm
     
    v:\test> ren ::"(.*\.)btm" ::"\1bat"
    V:\test\abc.btm -> V:\test\abc.bat
    V:\test\def.btm -> V:\test\def.bat
        2 files renamed
     
  14. Stefano Piccardi

    Joined:
    May 31, 2008
    Messages:
    376
    Likes Received:
    2
    Vince, you quoted the help entry for MOVE and used REN in your example. Move gives an error message here, TCC 14.00.30
    Code:
    C:\temp>move ::(.*\.bat) ::\1.btm
    TCC: Can't COPY or MOVE file to itself "C:\temp\abc.bat"
    0 files moved
     
    C:\temp>ren ::(.*\.bat) ::\1.btm
    C:\temp\abc.bat -> C:\temp\abc.bat.btm
    C:\temp\def.bat -> C:\temp\def.bat.btm
    2 files renamed
     
  15. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,938
    Likes Received:
    30
    Oops! The help for REN says the same thing. But it seems REN works while MOVE doesn't.

    Your example is a little strange (what does "." refer to in the target?). But it still doesn't work.

    This makes TCC disappear (no GPF file)!
    Code:
    v:\test> dir /k /m /h
    2012-08-01  00:54              0  abc.btm
    2012-08-01  00:54              0  def.btm
     
    v:\test> move ::(.*)\.btm ::d:\\\1\.bat
     
  16. Stefano Piccardi

    Joined:
    May 31, 2008
    Messages:
    376
    Likes Received:
    2
    Just a typo while copying your example.
     

Share This Page