1753768 Members
5139 Online
108799 Solutions
New Discussion юеВ

help in goto (csh)

 
jitou
Occasional Contributor

help in goto (csh)

I'm porting some scripts from DCL(VMS) to csh, and need some help.

A script with "goto" doesn't work the way I expect.

-------------------------------------------
#!/usr/bin/csh
echo inside script

LabelA:
echo this is Label A

# blah blah blah
# (lots of comments and scripts in between)
# blah blah blah

echo jumping to Label A
goto LabelA

exit
-------------------------------------------

When the comments and scripts between "LabelA" and "goto" is less than 2KB, it seems to work fine.
But when it's over 3KB, script says it can't find the "LabelA".
Is there any limit to the size ?
And is there any way to work around ?

Thanks
jitou
8 REPLIES 8
Peter Godron
Honored Contributor

Re: help in goto (csh)

Jitou,
I think the problem is that script langauages are basically sequential langauages.

So a goto actually is a 'rollback your instructions until you find this label'.
In your case the buffer accesable for rollback seems to be between 2 and 3K.

Can you try and have your command block in a nother file and execute that command block from ./command_file after your goto label.
Mark Ellzey
Valued Contributor

Re: help in goto (csh)

Jitou,

I hate to be a wet blanket here, but why would you want to use a 'goto' in the first place?

Whether in csh, or any scripting or programming language, use of the 'goto' statement is usually a sign of shoddy/lazy programming.

You may want to analyze the scripts you are porting and revise the logic so that you don't have to use goto's.

(you may also want to convert the scripts to posix shell or ksh).

Regards,
Mark
jitou
Occasional Contributor

Re: help in goto (csh)

Thank you, Peter, Mark.

I know that "goto" isn't the best option.
But there are soooo many DCLs with "goto" that we have to port, and some people have poor knowledge of neither csh nor DCL.

So this was the idea:
"Before restructuring spaghetti DCLs, why not port to csh and if anything goes wrong, let's take a look at that script."

This is the reason I asked for a work around.

And also, if I was to change the method above, I wanted to know the real reason why csh says someting weird.

Thanks
jitou
Mark Ellzey
Valued Contributor

Re: help in goto (csh)

Jitou,

Ok, I understand. You may then want to use Peter's solution of putting all the comments in a separate file and calling them from the script as:

source ./comment.file

For the scripts that run in between the Label/goto, you could, once again as Peter says, create separate script files and call them.

As I'm not an expert in csh, I don't know if that will work or not. Be worth a try though...

(Ugh, hate csh!).

Regards,
Mark
Maxim Yakimenko
Super Advisor

Re: help in goto (csh)

Sorry me for defeating your worldview, but I have the same problem on some ia64-hpux1123, while on others ia64-hpux1123 boxes I dont have this problem. Reason,I think, not in amount of comments, but in pathces or something like this - other words it is not a limitation of csh but software flaw. Also, I can recomend trying tcsh as the replacement, as it is said "tcsh is son of csh, it adds file name completion"
Peter Nikitka
Honored Contributor

Re: help in goto (csh)

Hi,

it is really not the amount of comments but the amount of data (>n KB). To strip comments is one method to reduce the amount of data.

I suggest to install the TCSH package - tcsh is highly compatible to csh but is not so 'fixed buffer programmed' like the old fashioned csh.
Perhaps you can overcome this 'goto' problem with it.
Look at

http://gatekeep.cs.utah.edu/hppd/hpux/Shells/tcsh-6.14.05/

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Maxim Yakimenko
Super Advisor

Re: help in goto (csh)

What amount?
I run the same script on two different boxes
with the same OS, but different patch sets
and have this scripts successfuly completed on one and broken on another - why the SAME script on the SAME OS but different patches has different results?
A. Clay Stephenson
Acclaimed Contributor

Re: help in goto (csh)

You don't other to identify your OS version but PHCO_34714 addresses your problem. However, the csh man page clearly states "the shell rewinds the input as much as possible and searches for a line of the form label:". It gets more complicated if the shell's input file is not a seekable file (ie being read from a pipe) then the backward seeks are limited to the size of csh internal buffer. In this case, the man page clearly states "To the extent that this allows (ie the internal buffer), backeward gotos succeed on non-seekable inputs.

I would think a better use of your time would be creating a translator for converting your existing scripts into something like Perl.


In any event, you are an accident waiting to happen. Your time
If it ain't broke, I can fix that.