- May
- 62
- 1
I'm pretty much a neophyte when it comes to TCC programming. At the moment, I'm trying to understand the working of ON ERRORMSG when it's used inside a DO loop.
As for the DO construct itself: Is there any difference between these two constructs? (Leading question, as my examples below show that yes, there is.)
On to ON ERRORMSG. This .btm file accepts multiple filenames as input parameters, iterates through them in a DO loop, and performs different commands depending on whether each file exists. (Yes, I know that doing a DIR isn't a good way to test whether a file exists; but it's a good way to confound my understanding of the ON ERRORMSG construct as used within the loop.)
It's easy for you to run this file and see the output. Here's a summary when run against one file that exists and one that doesn't:
Parentheses version:
ENDDO version:
If I remove all error handling and the goto labels (in other words, all the useful stuff):
then the code works as expected.
If I add one extraneous label back in:
then the code will loop forever on the first file in the list if I use the parentheses construct; but will process all files in the list if I use the ENDDO construct.
As you can see, I have a lot to learn here. Any help would be appreciated.
As for the DO construct itself: Is there any difference between these two constructs? (Leading question, as my examples below show that yes, there is.)
Code:
do while condition (
commands
...
)
do while condition
commands
...
enddo
On to ON ERRORMSG. This .btm file accepts multiple filenames as input parameters, iterates through them in a DO loop, and performs different commands depending on whether each file exists. (Yes, I know that doing a DIR isn't a good way to test whether a file exists; but it's a good way to confound my understanding of the ON ERRORMSG construct as used within the loop.)
Code:
echo at start, parms are %$
do while (%1) ne ()
echo at top of do, parm is %1
on errormsg goto BAD_FILESET
dir %1
on errormsg
echo process valid fileset %1 here...
goto NEXT_FILESET
:BAD_FILESET
on errormsg
echo process bad fileset %1 here...
:NEXT_FILESET
echo on to next fileset
shift
enddo
It's easy for you to run this file and see the output. Here's a summary when run against one file that exists and one that doesn't:
Parentheses version:
foo fgood fbad
: processes fgood correctly, stops at end of first iteration through loopfoo fbad fgood
: processes fbad correctly, aborts with "Unknown command" on final parenthesis. (If I move the parenthesis up to after the shift, it gives no error, but still stops the DO loop.)ENDDO version:
foo fgood fbad
: processes fgood correctly, aborts with "Unknown command" on the enddo.foo fbad fgood
: processes fbad correctly, aborts with "Unknown command" on the enddo.If I remove all error handling and the goto labels (in other words, all the useful stuff):
Code:
echo at start, parms are %$
do while (%1) ne () (
echo at top of do, parm is %1
dir %1
echo on to next fileset
shift )
If I add one extraneous label back in:
Code:
echo at start, parms are %$
do while (%1) ne () (
echo at top of do, parm is %1
dir %1
:FURBLE
echo on to next fileset
shift )
As you can see, I have a lot to learn here. Any help would be appreciated.