Welcome!

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

SignUp Now!

gosub variables

Feb
16
0
The help for tc10 states that:

:Sub1 [str n world]

when called with:

Gosub Sub1 abc 15 "Hello World"

will result in

str=abc
n=15
world="Hello World"

This is fine. I love gosub vars. Furthermore, if the sub is called with:

Gosub Sub1 abc 15

that results in:

str=abc
n=15
world=

However, if you call the sub like this:

Gosub Sub1 abc 15 My World

then you get this:

str=abc
n=15
world=My

Did I miss something? Is there no way to make the last variable "greedy"? The result I would like to see is:

world=My World

I can't find a way to do this, but if I've missed it do tell! And if it's just not there, then add it to the wishlist :-)

Thx
 
On Sat, 16 May 2009 19:54:28 -0500, grimblefritz <> wrote:

|Gosub Sub1 abc 15 My World

I'd try

GOSUB Sub1 abc 15 `My World`
--
- Vince
 
grimblefritz wrote:


> However, if you call the sub like this:
>
> Gosub Sub1 abc 15 My World
>
> then you get this:
>
> str=abc
> n=15
> world=My
>
> Did I miss something? Is there no way to make the last variable "greedy"? The result I would like to see is:
>
> world=My World
>
> I can't find a way to do this, but if I've missed it do tell! And if it's just not there, then add it to the wishlist :-)

WAD - and changing this would break a LOT of existing code. (Would you
expect batch variable %3 to include %4 - %n?)

You can use double quotes around any args you want to combine.

Rex Conn
JP Software
 
WAD - and changing this would break a LOT of existing code. (Would you
expect batch variable %3 to include %4 - %n?)

Just because it WAD doesn't mean AD is the best it can be :-)

No, I expect %3 to include only %3. However, I DO expect %3$ to include %4 - %n.

So why not allow %pvar$, when %pvar is the last parameter of a gosub, to behave the same? That would be a NEW convention would break NO existing code.

You can use double quotes around any args you want to combine.

Yes, but then you have to write extra code to check for and strip quotes.

So, speaking of quotes, I wish tcc had a true quote that combined enclosures, allowed variable and function expansion, protected from other special characters, but did not ADD the quotes themselves to the content. Basically a combination of " and `. Maybe ""string""? Such a quoting mode would make so many things so much easier -- instead of having to constantly account for whether or not things picked up extra content as a result of quoting. Especially nice if there was an option to swap the " and "" usage :-) But, after a couple decades (yes, I started with 4DOS 1.0) of dealing with it you get used to the quotes, but it makes them no less annoying.

All that said, until something changes I will continue to WAR the existing limitations. TCC is still by far the best command shell for Windows.

Thanks!
 
On Tue, 19 May 2009 10:04:02 -0500, grimblefritz <> wrote:

|---Quote---
|You can use double quotes around any args you want to combine.
|---End Quote---
|
|Yes, but then you have to write extra code to check for and strip quotes.

SET arg=%@UNQUOTE[%arg], no checking necessary.
--
- Vince
 
Just FYI to follow up on this post and especially the quoting issue.

A few months ago I decided to use TCC to code the back end of a small web project, fronted by the Abyss server. It is not too difficult for the most part. I've coded quite a bit of php, and contributed code to the haserl project, so between the two I have a good idea how to manage the data flow and other issues. Except for some http and cgi specific situations, TCC is up to the task.

Nonetheless, I have shot the TCC effort in the head and reverted to PHP.

I was able to WAR several problems, such as special character handling (via frequent calls to setdos), the lack of being able to reading scripts from stdin, and the absence of a meaningful array capability (especially associative arrays.) It is, however, the lack of a real quoting system in TCC that creates far more points for potential execution and security flaws than are worth the effort to WAR.

With the addition of some of the features I've suggested, here and in other threads, it would be quite possible to code a decent web back end using TCC.
 
This issue still seems to be a problem to me.

How can I pass parameters (e.g. partial directory paths) containing spaces to a subroutine in a useful way?
1. The help is actually wrong - it shows that abc and "Hello World" results in the same type of variable value (saying abc yields "abc" and "Hello World" yields "Hello World" but in fact abc yields a value of abc without quotes).
2. The post above suggesting redefining the parameter using set is specifically listed as not working in a subroutine in help, so %@UNQUOTE has to be sprinkled everywhere you reference the argument.
3. backquotes have no special meaning when assigning parameter values to a subroutine, so `Hello World` yields a value of `Hello

Any better suggestions? There really should be a way to reassign a subroutine parameter value, and/or a way to pass space containing parameter values to subroutines.
 
Assign the parameters to local variables and go from there.
Code:
:foo [_arg1]
set arg1=%unquote[%_arg1]
rem do something with %arg1
return
 
You can put the multi-word parameter in a variable and pass the name of the variable to the subroutine.

Code:
set param=one two three
gosub foo param
quit

:foo [varname]
echo %[%varname]
return
 
Back
Top
[FOX] Ultimate Translator
Translate