
> I hope someone can come up with a 4DOSian solution to this. I wanted
> to develop a system to add line numbers to a BAT/BTM so that that I
> can refer to them when describing it. Here is what I tried:

[ text of .BTM file omitted ]

> 1. The design was unduly complicated because of the need to have an
> intermediate file e.g. TEST.!!! between TEST.BAT and the line
> numbered TEST.LIN. This was because of the irritating @LINE bug that
> has reoccurred in v3.03 where it keeps rereading the last line.

When I heard about that a while back, I resolved to stick with version 
3.02!

> 2. @LINE has problems with leading spaces in lines it reads. From
> memory, only one leading space is preserved. Then "ECHO line >>
> file" finishes the job off by not preserving any.

I didn't run across the problems you mention with respect to leading spaces 
and the %@LINE function. Maybe this is again because I'm using 3.02? 
Anyway, here was a sample input file I used for testing:

this is line one (0 leading spaces)
this is line two (0 leading spaces)
 this is line three (1 leading space)
  this is line 4 (2 leading spaces)
   this is line 5 (3 leading spaces)
    this is line 6 (4 leading spaces)
this is line 7 (0 leading spaces)

Here is a test .BTM file I made to add the line numbers. In the 
following, "test" is the input file shown just above, and "test.out" 
is the output file.

............... tear here ................
setlocal ^ set LN=0 ^ set NBR=1

:LOOP
IFF "%@line[TEST,%LN%]" == "" THEN
  cls ^ type TEST.OUT ^ CANCEL
ENDIFF
:: Of course this is a very simple-minded example and
:: doesn't stop to consider lines that are intentionally
:: blank in the source file. So adding "-EOF-" or some
:: such thing to the original is probably required in any case.

echo [%NBR%] %@line[test,%LN%]>> test.out

set LN=%@eval[%LN% + 1]
set NBR=%@eval[%NBR% + 1]
goto LOOP
............... tear here ................

The result:

[1] this is line one (0 leading spaces)
[2] this is line two (0 leading spaces)
[3]  this is line three (1 leading space)
[4]   this is line 4 (2 leading spaces)
[5]    this is line 5 (3 leading spaces)
[6]     this is line 6 (4 leading spaces)
[7] this is line 7 (0 leading spaces)

The leading spaces were preserved, and of course one additional space 
was added (on account of:   echo [%NBR%]  followed by a single space 
and THEN the relevant line from file TEST.

Much faster and simpler alternative: Use the AWK utility. This AWK 
script worked fine:

{print "["NR"]" FS FS $0}

It doesn't include any instruction for NOT numbering a blank line, but 
that would be easy enough to add.

> 3. I had lots of problems with inadvertent parameter and EV function
> expansion in the lines I was trying to process.

My test .BTM file above doesn't deal with that problem, I realize. If I 
had a 300-line .BTM file to process, I'd definitely use AWK. I have 
found that "%@LINE" becomes horribly slow when it gets down past about 
line 30 or 40 of an input file and you're doing one of these looping 
routines. I don't know why it slows down so much, but it's quite 
irritating that way. I suppose that if I had a '386 I wouldn't notice 
the slowing-down at all.

