WAD @format has issues in v18.00.14

samintz

Scott Mintz
May 20, 2008
1,488
15
Solon, OH, USA
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
 
May 20, 2008
11,285
95
Syracuse, NY, USA
@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
 
May 20, 2008
11,285
95
Syracuse, NY, USA
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
 
May 20, 2008
11,285
95
Syracuse, NY, USA
@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
 
May 20, 2008
11,285
95
Syracuse, NY, USA
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
 
May 20, 2008
11,285
95
Syracuse, NY, USA
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
12,312
147
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
 
May 20, 2008
11,285
95
Syracuse, NY, USA
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!
 
Similar threads
Thread starter Title Forum Replies Date
sully9 How to? Unexpected %DATE% CMD variable format (vs DATE /T format) in CMDebug Support 1
T Date format date different from cmd Support 7
vefatica @TIMER's format ... Support 2
T Elapsed time format in prompt changed in TCC 25 Support 10
Joe Caverly DATE format 4 Support 7
M Fixed Set "VAR=VAL" format causes problems Support 12
fpefpe touch - date format Support 2
T Problems with the new help format Support 18
mikea How to? Detecting clipboard format Support 7
fishman@panix.com Help file in Kindle format? Support 5
M PDir format question... Support 3
A Is TCC help available in PDF format? Support 2
S TIME /S report format Support 3
S Vince - forum format revisited Support 1
D No "Format" in right-click menu for DVD Support 11
nikbackm Change format of DIR totals Support 3
C OT: Music file format checker Support 0
S Enhancement suggestion: @format and @formatn Support 0
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
D TCC has much more elegant ways for usebackq. What ways? Support 12
D Pasting Unicode data has different behavior on TCC and CMD Support 2
D [cosmetic] Shortcut for v24 still has v23 in its comment Support 1
D Envar _tcexit has value, even with /IX startup parameter Support 0
Charles Dye Functions which no-one has ever tried to use.... Support 5
C "Take Command has stopped working" Support 1
C "TakeCommand has stopped working" Support 3
R Fixed set /r has stopped working in build 35 Support 4
D Help index has GUNZIP Support 0
D Fixed @FORMATNC has changed. Support 6
D Fixed Dir /Nm:n has changed Support 1
V Fixed CD ~ has trash characters in it Support 5
vefatica Has NthArgument changed? Support 7
S Documentation KEYSTACK - has this feature been dropped? Support 5
forbin Fixed OSD /C has no effect Support 14
H Documentation Help for head has ... Support 0
D Documentation @ISPUNCT has rogue links Support 2
J Extended directory search has stopped working Support 9
old coot TC DIR command has trouble on my SSD Support 2
vefatica WAD TPIPE.EXE has stopped working Support 13
vefatica TakeCommand has stopped working Support 6
ehab aboudaya WAD starting tcmd.exe with dir that has Boost C++ Libraries zip file delays Support 2
Alan Strader Take Command IDE/Debugger has stopped working Support 5
M A new problem that has actually got me a little panicky... Support 10
cgunhouse NTVDM CPU has encountered an illegal instruction. Support 2
S PDIR has trouble processing filenames with embedded percent sign Support 3
nikbackm Find out when a process has stopped Support 5
C Utilities menu has gone ? Support 7
S Issues with version v26.02.42 x64 Support 0
Jay Sage Issues With TCMD File Explorer Support 0

Similar threads