iff ... endswitch

#1
Hi,
This batch file;

Code:
@setlocal
@echo off
iff %# ne 3 then
  echo You need 3 command line arguments
else
  echo Okay
endswitch
echo At the end of the program
endlocal
works, without displaying an error. I had converted a switch/endswitch group to an iff/endiff group in another .btm, and had forgotten to replace the endswitch with an endiff.

So, I made up this test batch file to see if it was true, that I could use iff and endswitch together. It appears that I can, with no error being generated.

However, regardless of the results of the iff condition, the final message;

Code:
echo At the end of the program
should be executed. If there is not 3 command line arguments, the final message

Code:
echo At the end of the program
is not executed.

I could not figure out why my other .btm code was not working. Finally, I used bdebugger to step through the code. When I reached the

Code:
iff %# ne 3 then
bdebugger would not allow me to continue stepping through the program, and ended execution of the .btm

It was at this point that I noticed my coding error. Of course, an iff/endswitch should not work.

This is my fault, for not having a matching iff/endiff, but I thought that some kind of error message would have been displayed because of my use of iff/endswitch.

I am using;

Code:
TCC  15.01.52   Windows Vista [Version 6.0.6002]
TCC Build 52   Windows Vista Build 6002  Service Pack 2
Registered to Joe Caverly - 1 System License
Joe
 
#2
Joe:
Same results here. Of course, correcting the code results in the final command's echo. Same TCC build, 32-b WinXP Pro SP3. I tried the other faulty variant, too - with SWITCH/ENDIFF:

@setlocal
@echo off
switch %#
case 3
echo Okay
default
echo You need 3 command line arguments
endiff
echo At the end of the program
endlocal

In this variant, the penultimate command was ignored only when there were exactly 3 parameters, but (the good news) in the default case (i.e., parameter count not 3) the You need 3... message was followed by the TCC error message Unknown command "endiff" and by the At the end... messages. Note that in many of the cases if you define the UNKNOWN_CMD alias the results differ from TCC's normal error handling, both the issue of reporting the error, and of continuing to execute the program.

Rex:
Could error reports be enhanced when an out of place ENDDO/ENDIFF/ENDSWITCH/ENDTEXT is found to be analogous to the Missing SETLOCAL message generated by ENDLOCAL? Currently ENDSWITCH is just ignored; the other three generate technically incorrect messages: Unknown command "end..." ?
 
#5
Whether or not ENDIFF and ENDSWITCH are technically commands, if the parser expects a command and finds a misplaced one of these keywords, it currently reports Unknown command ... As Vince reported, this particular error also terminates processing the batch file. Obviously the parser has detected that the keyword actually found is not a valid program control flow. All I am suggesting the error report include that reason.
 
#6
In fact, I cannot, in a batch file, get any of the following to produce an error/syntax message, regardless of their position or appropriateness.

SWITCH (with/without an expression)
CASE (with/without value)
DEFAULT
ENDSWITCH
 
#8
Do they cause termination of batch execution when inappropriate?
IIRC, SWITCH/ENDSWITCH, when out of context do nothing. CASE and DEFAULT seem to cause a search for an ENDSWITCH ... if found, execution continues after the ENDSWITCH ... if not found, the batch file seems to terminate, probably because it searched to the end.

In one sense this is moot; we're talkng about bad (even absurd) syntax. OTOH, we are (I am) so used to
Code:
TCC: V:\eswitch.btm [5]  Unknown command "endiff"
TCC: V:\eswitch.btm [6]  Unknown command "enddo"
TCC: V:\eswitch.btm [8]  Unknown command "iterate"
TCC: V:\eswitch.btm [9]  Unknown command "leave"
that the complete lack of syntax messages from SWITCH (and friends) seems wrong, at least not in keeping with what we (I) have come to expect.
 
#9
In one sense this is moot; we're talkng about bad (even absurd) syntax. OTOH, we are (I am) so used to
Code:
TCC: V:\eswitch.btm [5]  Unknown command "endiff"
TCC: V:\eswitch.btm [6]  Unknown command "enddo"
TCC: V:\eswitch.btm [8]  Unknown command "iterate"
TCC: V:\eswitch.btm [9]  Unknown command "leave"
that the complete lack of syntax messages from SWITCH (and friends) seems wrong, at least not in keeping with what we (I) have come to expect.
It is also my expectation... One cannot have too many "invalid syntax" messages. Way preferred to silent death.
 
#10
Sorry, apparently my logitech trackball "clicked" more than once for a single button depression (Windows did not do a good debouncing), and XenForo did not detect that there was no input between them so they must be the same. Anyone who has authority please delete the 2nd, 3rd and 4th copies of my last post (and this one, too).
You should be able to edit or delete your own posts. I can. When on the web forums, "Edit, Delete, Report, Bookmark" appears under my posts.

Mouse buttons are dirt cheap. If you're any good with a solderer ...

I recently replaced the left button switch in my TrackMan Marble ... good for another 10 years (or until the laser dies). I truly dread the day my trackball dies, or I wear out my four Gateway2000 AnyKey keyboards.

P.S. (this is an edit) Yours was precisely the symptom that made me replace the mouse button switch. It just keeps getting worse.
 
#11
I just deleted the duplicate/triplicate posts. The "Edit, Delete, ..." message in diminishing size, never noticed them.

3 Trackman Marbles on my desk - one for each computer. Two with the retaining ring, one with the snap-in mounting. I will need to look carefully at the one becoming flaky and check RadioShack for replacement switches. Thanks for the tip!