Operating System - OpenVMS
1838671 Members
6073 Online
110128 Solutions
New Discussion

Re: Printing comments from the com script

 
SOLVED
Go to solution
nipun_2
Regular Advisor

Printing comments from the com script

Hi,
I am using VMS 7.3-2. I have a simple com script which requires P1 and P2.

I have written comments from the first line of the script till I hit =====
so...
Example.com script
$! xxxx
$! xxxxx
$! xxxxx
$! USAGE:
.
.
.
$! ==============================

Now in case a user does not pass p1 I want an error message which basically types up the above comments.

I was thinking of using search or type command to read till "====" but I am not sure how I can open or search the current file. Since I will be executing the script and trying to type the comments on the screen.

I am aware of $write sys$output ---
But that will be a bit tedious and am looking for a neater method.

Nipun
13 REPLIES 13
Robert Gezelter
Honored Contributor

Re: Printing comments from the com script

Nipun,

A common enough requirement. The solution is to use the TYPE command in conjunction with SYS$INPUT, not comments. For example:

$ IF F$LENGTH(P1) .EQ. 0
$ THEN
$ TYPE SYS$INPUT
You omitted the parameter to this file. Please supply a parameter of the form ...

$ ENDIF

I re-typed this, my apologies in advance if I have introduced some typographical errors.

- Bob Gezelter, http://www.rlgsc.com
Steven Schweda
Honored Contributor

Re: Printing comments from the com script

alp $ type x.com
$!
$ goto start
$!
$ usage:
$!
$ type sys$input
Text line 1.
Text line 2.
$!
$ return
$!
$ start:
$ if (p1 .eqs. "")
$ then
$ gosub usage
$ exit
$ endif
$!
$ write sys$output "Normal."
$!

alp $ @ x.com xxx
Normal.

alp $ @ x.com
Text line 1.
Text line 2.
nipun_2
Regular Advisor

Re: Printing comments from the com script

Hi Bob,
I this script is helpful. But there is one problem.

I have been using these scripts in the past so I have put all the comments preceeing with a

$!

So those lines don't get out. Now I have 15-20 lines in several scripts so it would be very painful for me to manual change that.

Would there be a better way ?

Nipun
Steven Schweda
Honored Contributor

Re: Printing comments from the com script

> Now I have 15-20 lines in several scripts
> so it would be very painful for me to
> manual change that.

This sounds like a few seconds worth of work
in any text editor. Adding the TYPE command
should require more time. Your idea of
"very painful" seems to differ from mine.
Robert Gezelter
Honored Contributor

Re: Printing comments from the com script

Nipun,

I would recommend the change, iterating through a series of files and making this type of change is not too difficult. You can use the command DIRECTORY/OUTPUT/NOHEAD/NOTRAIL to produce a list of files to be edited and make a command file out of them. You will also need to insert an ASSIGN/USER TT SYS$INPUT before each invocation of your favorite editor. This is not too difficult to do, unless you have hundreds of files (in which case a command file can generate the command file).

A quick (and VERY UGLY) fix is to use the DECK command to supress the behavior of the leading dollar signs for the display of the comments. You will also need to insert the trailing marker as described in the HELP text. Would I use this method? NO.

- Bob Gezelter, http://www.rlgsc.com
nipun_2
Regular Advisor

Re: Printing comments from the com script

Hi Steve,
My response was for Bob not yours.
Your response must have come while I was typing mine.

Nipun
Hein van den Heuvel
Honored Contributor

Re: Printing comments from the com script

I agree with Steve.
The real solution is to make the comments be the usage text. It really is a minor edit and the scripts will look better:

----------------------------------------
$if p1.nes."" then goto got_p1
$type sys$input

xxxx
xxxxx
xxxxx
USAGE:
==============================

$got_p1:


Now if you insist on using the crummy, yet firmly established and widely followed comment construct, might I recommend perl?:

--------------------------------
$! xxxx
$! xxxxx
$! xxxxx
$! USAGE:
$! ==============================
$if p1.eqs."" then perl -ne -
"exit 268435472 if /====/; print if (s/^\$! / /)" 'F$ENV("PROCEDURE")
$!all is well...

Enjoy!
Hein.
Steven Schweda
Honored Contributor

Re: Printing comments from the com script

Or, the easy way, if you don't object to the
"$! " in the output:

alp $ type x2.com
$!
$ goto start
$!
$ usage:
$!
$ type sys$input
$ deck /dollars = "$END"
$! Text line 1.
$! Text line 2.
$END
$!
$ return
$!
$ start:
$ if (p1 .eqs. "")
$ then
$ gosub usage
$ exit
$ endif
$!
$ write sys$output "Normal."
$!

alp $ @ x2.com xxx
Normal.

alp $ @ x2.com
$! Text line 1.
$! Text line 2.


I _do_ like DECK.
jaw_1
New Member

Re: Printing comments from the com script

Sounds like you want something like:

search /nohighlight /window=(99,0) 'F$ENVIRONMENT("procedure") "==''=="

Adjust search string as necessary to not produce undesirable matches with other content in the command file(s).

James
Aaron Sakovich
Super Advisor

Re: Printing comments from the com script

James makes an excellent suggestion. Here's a simple way to clean it up even more:

Using the EachLine script (from dcl.openvms.org), and the pipe command, you can get rid of the $! and $! =======... too.

$ pipe search 'f$env("Procedure") "$! ===="/wind=(99,0) | search sys$pipe "$! ===="/match=nor | eachline in "write sys$output in-""$!"""

This one-liner will give you the contents of the comments without the prefix on each line, and without the end-comment line.
nipun_2
Regular Advisor

Re: Printing comments from the com script

Thanks James and Aaron,
I am still exploring different options. Your suggestions look directly applicable to my current problem.


I will try to test this in a day or two and provide an update.

Thank you everyone for your feedback ...as I mentioned will provided an update in a day or two...

Nipun
nipun_2
Regular Advisor

Re: Printing comments from the com script

Hi James,
I tried the routine you suggested however,
the output comes out to be the entire script.
I think it doesn't stop the search at the first instance of the ====== sign but rather on the search command below which has the specified line "===="


I executed the following line
search /nohighlight /window=(99,0) 'F$ENVIRONMENT("procedure") "==''=="

I also changed the wind =(0,0)
but it didn't make a different. I am attaching the script file for feedback
Hein van den Heuvel
Honored Contributor
Solution

Re: Printing comments from the com script

Yeah, you are latching on to your own search string.

Try this:

$!========================================
$ IF P1 .EQS ""
$ THEN
$ x="======"
$ search /nohighlight /window=(99,0) 'F$ENVIRONMENT("procedure") 'x''x'

Or how is this for cute:


$!
$i="======================================"
$ IF P1 .EQS ""
$ THEN
$ search /nohighlight /window=(99,0) 'F$ENVIRONMENT("procedure") 'i


Still... did you try the PERL solution I showed? It gives SO MUCH control. Trivial to only do comments, trivial to remove the actual comment introducer, and so on.

And show about a re-write into the $type sys$input variant?
A simple (perl!?) script could easily do this on all your dcl scripts.

Regards,
Hein.