Here's one approach:
Code:
@echo off
setlocal
set i=0
do line in @con:
echo Line %@format[3,%i]: %line
set i=%@inc[%i]
enddo
endlocal
Note that TCC isn't really a programming language; it's a command shell, and you will get into trouble if the input text contains special characters like percent signs, ampersands, greater-than and less-than signs, and so on. SETDOS can help you work around some /such issues. This may also be useful:
http://www.unm.edu/~cdye/plugins/safechars.html
Charles, thank you for your response!!! That
does (
almost!!!!) completely work when the input is coming from a
file or a
pipe. (Which kind of
surprises me, because I would have
guessed that "@con:" was an actual
device, and therefore
could not be replaced by input from a file or the output of a "pipe").
But the reason for the "(almost) completely" qualifier is that it does
not, in my opinion, work "completely" in
two different ways (
one of which I find to
just be very strange, the other of which just essentially makes the technique
useless!!!!) when the input is coming from one of two
other sources, one of which goes to the very
heart of its intended use:
To list these two situations:
1. (The just plain "
strange" one) If I redirect the input of the command from the .btm file
itself, the <cn.btm"><cn.btm") the="">
response is:
Line 0: @echo off
...
Line 4: do line in @con:
(after a relatively long wait:)
TCC: Z:\cn.btm [6] Command line too long
Line 6: set i=7
...
Line 9: endlocal
I imagine this is some kind of
recursion, but I have to admit I don't
completely understand this...
2. Just the command "cn" getting its input from the actual
console:
[input something...]
[output same thing]
[input something...]
[output same thing]
...
[input something...]
[output same thing]
Ctrl-Z
→
Ctrl-Z
→
...
Ctrl-C
TCC session immediately
terminates without notice. (I.E, the TCC window
completely disappears.)
This makes this technique somewhat
less than useful for the purposes for which I
intended to use these .btm files.
</cn.btm")></cn.btm">As far as "TCC isn't really a programming language; it's a command shell" goes, while you are
technically correct, it is such a
powerful language in general that that distinction is
almost (but obviously not
completely) irrelevant. (I will note that I have turned a fair number of TCC capabilities into general functions that I can call from a C++ program. Examples are: AddCommas, EXISTS, ExceptionHandling..., GetValidResponse, ResolveDirectoryJunctionOrSymbolicLink, TrueTrueName, WildCardMatch (using TCC syntax), and possibly
others that I don't remember...)
<cn.btm"><cn.btm") the="">
And finally, two
almost unrelated but again
really rather strange things:
The command "Notepad con.btm" yields a new instance of Notepad with a message box that states (and I quote) "The handle is invalid"!
So if after dismissing that "message box" you enter some text into the now "Untitled" Notepad window and then try to save the resulting file to "con.btm", you get still
another (
even stranger!!!!) message box: con.btm - This file name is reserved for use by Windows. Choose another name and try again.
Further rather "strange" (but no longer
really surprising) things along the same line:
ren cn.btm con.btm
Z:\cn.btm -> Z:\con.btm
TCC: (Sys) Cannot create a file when that file already exists.
"Z:\cn.btm"
0 files renamed 1 failed
dir con.btm
Volume in drive Z is RAM disk Serial number is ...
TCC: (Sys) The system cannot find the file specified.
"Z:\con.btm"
0 bytes in 0 files and 0 dirs
193,519,616 bytes free
Well, I guess that's
enough for now...
</cn.btm")></cn.btm">