Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Documentation Filename Specification in GOSUB Command

Jun
760
16
The GOSUB command is supposed to support an optional filename to indicate that the subroutine is to be found in another file. In my experience, the filename specification is not properly parsed. Specifically, directory aliases are not expanded. I wrote something like:

gosub "bat:position.dat" label args

That resulted in an error message that the file "bat:position.dat" could not be found. If I changed the command to the following, it worked:

gosub "%@full[bat:position.dat]" label args

Since GOSUB is a TCC command, it really ought to recognize directory aliases, extended parent directories, etc.

The documentation could also be improved by providing more details about the requirements for "filename". When "bat:position.dat" failed, I thought that perhaps the file had to have an extension of btm, bat, or cmd. Does the file always have to have a full path? If not, how is the file found? Does the calling batch file look in the directory in which the calling batch file resides? The drive and directory from which the calling batch file was called? Is a file extension required, or does TCC look for default extensions in some specified order?
 
This is a feature request; I've added it to the suggestion list. (If the documentation doesn't say that the parser does not do something, that doesn't imply that it does do it!) Directory aliases are not universal, they need to be explicitly enabled everywhere they are wanted. And nobody ever wanted it in a GOSUB before.

There are no requirements for "filename". TCC searches the PATH for a matching filename if it is not found in the current directory and doesn't have an existing partial or full path. The extension is irrelevant.
 
I found this answer very strange. When I suggested that the help for the @FULL function mention that it expands directory aliases, you wrote: "@FULL calls the same filename expansion code used everywhere else in TCC, so it gets directory aliases, home directories, shell folders, URLs, etc. I don't know that it would be especially useful to explicitly mention that in several hundred places in the help." Now you say that the filename expansion code in the GOSUB command does not work the way it does everywhere else in TCC.
 
There is no filename expansion code in GOSUB, just a check for the local directory and for the PATH.
I understand, but that's not what I would have expected, both from what you wrote about file specs in functions and intrinsically.

Here's another small issue. When a reference to an internal label is not found, an error message is generated and the script aborts.

Code:
[TCC33.00.20 | C:\commands\bat]
>type test.btm
gosub MissingLabel
echo Code after missing label.
quit

[TCC33.00.20 | C:\commands\bat]
>test.btm
TCC: C:\commands\bat\test.btm [3]  Label not found "MissingLabel"

[TCC33.00.20 | C:\commands\bat]

However, when there is a reference to a file that cannot be found, there is an error message but the script continues. It seems to me that the behavior should be consistent (and probably the first behavior, aborting of the script).

Code:
[TCC33.00.20 | C:\commands\bat]
>type test.btm
gosub "MissingFile" label
echo Code after missing label.
quit

[TCC33.00.20 | C:\commands\bat]
>type test.btm
gosub "MissingFile" label
echo Code after missing label.
quit

[TCC33.00.20 | C:\commands\bat]
>test.btm
TCC: (Sys) C:\commands\bat\test.btm [1]  The system cannot find the file specified.
 "MissingFile"
Code after missing label.

[TCC33.00.20 | C:\commands\bat]
 
I note that with the CALL FILE command, the file spec is expanded as expected with TCC (and can have an alias directory prefix). So why not GOSUB?

Are there any other file specs in TCC commands that do not expand the file spec in the usual TCC manner?
 
Back
Top