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

WAD @format has issues in v18.00.14

samintz

Scott Mintz
May 20, 2008
1,238
11
Solon, OH, USA
#1
In a separate thread discussing formatting line numbers in FFIND's output, I tried to use @format to format the number with leading zeros.
Using the Readme.txt in the TC18 install directory I did:
Code:
[C:\TC18] do l in /p ffind /l /v /t"Take" readme.txt (echo.%@rereplace["\[(\d+)\](.+)",[%@format[05,\1]]\2,%l])

---- C:\TC18\readme.txt
[0001]                        Take Command x64 v18.0
[00012] Greetings, and thanks for trying Take Command!
[00015] Take Command, including:
[00028]   Take Command version 18 is a major update -- we've added over 200 new
[00061]    Take Command gives you a 30-day evaluation period.  The number of days
[00068]    When you purchase a new or upgrade copy of Take Command, you will receive
[00069]    an email with your registration key.  Start Take Command, click on the
[00070]    "Options / Configure Take Command" menu entry, and select the "Register"
[00075]    to reinstall Take Command.  If you have lost your registration key, you
[00081]    The following files are included with Take Command x64 18.0:
[00083]      TCMD.EXE            Take Command program file
[00084]      TCC.EXE             Take Command Console program file
[00096]      IDE.EXE             Take Command IDE / debugger
[000104]      LICENSE.TXT         Take Command user license
[000108]      regid.2002-09.com.jpsoft_Take Command x64 18.0.swidtag
[000117]      TAKECMD.DLL         Shared DLL for Take Command and TCC
[000122]                            Take Command Folders and List View context menus.
[000123]      TCMD.CHM            Take Command / TCC online help
[000124]      TCMDHERE.BTM        Batch file to add "Take Command Prompt Here" to
[000165] Take Command is a registered trademark of JP Software Inc.  TCC is JP

  20 lines in      1 file
I expected the format to be 5 digits long in each case with leading zeroes.

TCC 18.00.14 x64 Windows 7 [Version 6.1.7601]
TCC Build 14 Windows 7 Build 7601 Service Pack 1
 
#3
@FORMAT seems OK to me. Here's another approach.
Code:
g:\tc18> do l in /p ffind /k /m /l /v /t"Take" readme.txt (echo [%@format[05,%@strip[^[^],%@word[0,%l]]]]^t%@word[1-100000,%l])
[00001] Take Command v18.0
[00012] Greetings, and thanks for trying Take Command!
[00015] Take Command, including:
[00028] Take Command version 18 is a major update -- we've added over 200 new
[00061] Take Command gives you a 30-day evaluation period.  The number of days
[00068] When you purchase a new or upgrade copy of Take Command, you will receive
[00069] an email with your registration key.  Start Take Command, click on the
[00070] "Options / Configure Take Command" menu entry, and select the "Register"
[00075] to reinstall Take Command.  If you have lost your registration key, you
[00082] The following files are included with Take Command 18.0:
[00084] TCMD.EXE  Take Command program file
[00085] TCC.EXE  Take Command Console program file (formerly 4NT.EXE)
[00097] IDE.EXE  Take Command IDE / debugger
[00106] LICENSE.TXT  Take Command user license
[00110] regid.2002-09.com.jpsoft_Take Command 18.0.swidtag
[00119] TAKECMD.DLL  Shared DLL for Take Command and TCC
[00124] Take Command Folders and List View context menus
[00125] TCMD.CHM  Take Command / TCC online help
[00128] TCMDHERE.BTM  Batch file to add "Take Command Prompt Here" to
[00169] Take Command is a registered trademark of JP Software Inc.  TCC is JP
 
#4
This is more faithful to the original.
Code:
g:\tc18> do l in /p ffind /k /m /l /v /t"Take" readme.txt (echo [%@formatn[05.0,%@strip[^[^],%@word[0,%l]]]]^t%@instr[%@len[%@word[0,%l]],,%l])
[00001]  Take Command v18.0
[00012]  Greetings, and thanks for trying Take Command!
[00015]  Take Command, including:
[00028]  Take Command version 18 is a major update -- we've added over 200 new
[00061]  Take Command gives you a 30-day evaluation period.  The number of days
[00068]  When you purchase a new or upgrade copy of Take Command, you will receive
[00069]  an email with your registration key.  Start Take Command, click on the
[00070]  "Options / Configure Take Command" menu entry, and select the "Register"
[00075]  to reinstall Take Command.  If you have lost your registration key, you
[00082]  The following files are included with Take Command 18.0:
[00084]  TCMD.EXE  Take Command program file
[00085]  TCC.EXE  Take Command Console program file (formerly 4NT.EXE)
[00097]  IDE.EXE  Take Command IDE / debugger
[00106]  LICENSE.TXT  Take Command user license
[00110]  regid.2002-09.com.jpsoft_Take Command 18.0.swidtag
[00119]  TAKECMD.DLL  Shared DLL for Take Command and TCC
[00124]  Take Command Folders and List View context menus
[00125]  TCMD.CHM  Take Command / TCC online help
[00128]  TCMDHERE.BTM  Batch file to add "Take Command Prompt Here" to
[00169]  Take Command is a registered trademark of JP Software Inc.  TCC is JP
 
#5
@FORMAT is for string formatting. You should be using @FORMATN for numbers.

You're also specifying the minimum number of characters in the output string, but not the maximum.
That seems worse.
Code:
g:\tc18> do l in /p ffind /l /v /t"Take" readme.txt (echo.%@rereplace["\[(\d+)\](.+)",[%@formatn[05.0,\1]]\2,%l])

---- G:\TC18\readme.txt
[00000]  Take Command v18.0
[00000] Greetings, and thanks for trying Take Command!
[00000] Take Command, including:
[00000]  Take Command version 18 is a major update -- we've added over 200 new
[00000]  Take Command gives you a 30-day evaluation period.  The number of days
[00000]  When you purchase a new or upgrade copy of Take Command, you will receive
[00000]  an email with your registration key.  Start Take Command, click on the
[00000]  "Options / Configure Take Command" menu entry, and select the "Register"
[00000]  to reinstall Take Command.  If you have lost your registration key, you
[00000]  The following files are included with Take Command 18.0:
[00000]  TCMD.EXE  Take Command program file
[00000]  TCC.EXE  Take Command Console program file (formerly 4NT.EXE)
[00000]  IDE.EXE  Take Command IDE / debugger
[00000]  LICENSE.TXT  Take Command user license
[00000]  regid.2002-09.com.jpsoft_Take Command 18.0.swidtag
[00000]  TAKECMD.DLL  Shared DLL for Take Command and TCC
[00000]  Take Command Folders and List View context menus
[00000]  TCMD.CHM  Take Command / TCC online help
[00000]  TCMDHERE.BTM  Batch file to add "Take Command Prompt Here" to
[00000] Take Command is a registered trademark of JP Software Inc.  TCC is JP

  20 lines in  1 file
 
#7
There's a strange interaction between the regex replacement strings and @format. For one thing, I'm getting 1 vewer characters than asked for.
Code:
g:\tc18> echo %@format[02,b]
0b

g:\tc18> echo %@rereplace[(b),%@format[01,\1],abc]
abc

g:\tc18> echo %@rereplace[(b),%@format[02,\1],abc]
abc

g:\tc18> echo %@rereplace[(b),%@format[03,\1],abc]
a0bc

g:\tc18> echo %@rereplace[(b),%@format[04,\1],abc]
a00bc
 
#9
It's pretty obvious that you can't put those replacements (\1) into variable functions reliably. The length is 1 but ...
Code:
g:\tc18> echo %@rereplace[(b*),\1 - %@len[\1],abc]
ab - 2c
 

rconn

Administrator
Staff member
May 14, 2008
10,315
93
#10
There's a strange interaction between the regex replacement strings and @format. For one thing, I'm getting 1 vewer characters than asked for.
Code:
echo %@rereplace[(b),%@format[01,\1],abc]
That's a nonsense command - you cannot pass a directive from one function (that only has meaning for that function) to a nested function. The \1 argument is NOT expanded before it's passed to @format.

The parser evaluates everything inside-out, so the result is:

1) Get outer function %@rereplace
2) If there's embedded functions (@format) or variables, call the variable expansion routines recursively
3) Evaluate @format, outputting the string "\1" using the formatting string "01"
4) Insert the result in @rereplace
5) Expand the resulting regular expression substitution
6) Be baffled at the bizarre result
 
#11
The \1 argument is NOT expanded before it's passed to @format.
Aha! I get it ...

Code:
g:\tc18> echo %@rereplace[(\d+),%@format[015,\1\1\1\1],123abc]
0000000123123123123abc
@FORMAT[015,\1\1\1\1] yields
Code:
0000000\1\1\1\1abc
Then we go back to @REREPLACE which substitutes 123 for \1. In the end it looks like @FORMAT didn't put in the right amount of padding, but not so!.

... VERY TRICKY!
 
Top Bottom