[comp.os.vms] PIPE command files

JON@UCLASTRO.BITNET (08/24/87)

For all to see,
        There were enough requests (>2) for the PIPE com files so
here they are.  There are three files, PIPE.COM, TNOP.COM, and ARGSTR.COM.
The last two files can both be easily incorporated into PIPE.COM if
calling more com files bothers anyone.  The only disk dependence is
that the temporary files are written to SYS$SCRATCH.  This is not the
fastest (use of mailboxes would be much better) but it gets the simple
stuff done.  If anyone makes any improvements (like a REAL pipe), send them
to me (motto: find someone else to do it).  I hope this works for people.

                                        Jonathan Eisenhamer
                                        UCLA Astronomy
                                        JON@UCLASTRO.BITNET
                                        BONNIE::JON (SPAN 5828)
                                        (213) 206-8596 (a phone? what's that?)

File PIPE.COM
============== CUT HERE ================= CUT HERE ======================
$! This command file mimics a simple pipe operation.  The command is as follows:
$!
$!      @PIPE  command | command ....
$!
$! The point of this command is to easily create temporary files so that the
$! output of the first command can be used as the input to the next.  The
$! indicator to use the previous output is "`".  For example, if there is
$! a large directory and you want to look at it a page at a time, you would
$! type:
$!      $ @PIPE DIR | TYPE/PAGE `
$!
$! If you do not specify "`" for any command (except the first), then the
$! output of the previous command will be the first argument to the second
$! command.  Thus, the above example could have been rewritten:
$!      $ @PIPE DIR | TYPE/PAGE
$!
$! and you would have gotten the same results.
$! The only limitation is that you can only have eight (8) seperate arguments,
$! delimited by spaces.  (I.e. the first example uses 4 arguments and the
$! second example uses three arguments).  A way to conserve arguments is
$! remember that the "|" is a separator.  Thus the command above can be
$! written using only one argument:
$!      $ @PIPE DIR|TYPE/PAGE
$
$! Set control y so that things can get cleaned up.
$ on control_y then goto done
$
$! Put the arguments into a string
$ @argstr 'p1' 'p2' 'p3' 'p4' 'p5' 'p6' 'p7' 'p8'
$
$! Set the intial input file to null.
$ infile = ""
$
$Loop:
$! Start the main loop. Get the next command from the command line
$ pos = f$locate("|", argstr)
$ command = f$edit(f$extract(0, pos, argstr),"TRIM")
$ if f$length(command) .le. 0 then goto done
$ argstr = f$edit(f$extract(pos+1, f$length(argstr), argstr),"TRIM")
$
$! Indicate that no "`" was found.
$ inmark = 0
$
$loop1:
$! Search for the input file indicator "`".  If there are any, replace them
$! with INFILE.  If there are none, then place INFILE as the first argument.
$ pos = f$locate("`", command)
$ if pos .eq. f$length(command) then goto skip1
$ tcom = f$extract(0, pos, command)
$ tcom = tcom + infile + " "
$ tcom = tcom + f$extract(pos+1, f$length(command), command)
$ command = tcom
$ inmark = 1
$ goto loop1
$
$skip1:
$! If no input marker was found, then place the input file as the first
$! argument.
$ if inmark .ne. 0 then goto skip2
$ pos = f$locate(" ", command)
$ tcom = f$extract(0, pos, command) + " " + infile + " "
$ if pos .lt. f$length(command) then tcom = tcom + -
                            f$extract(pos, f$length(command), command)
$ command = tcom
$
$skip2:
$! Create the output file.  If this is the last command on the line, then
$! set the output to the original output.
$ @tnop
$ outfile = "sys$scratch:" + tnop + ".pip"
$ if f$length(argstr) .gt. 0 then $ define sys$output 'outfile'
$
$! Peform the command
$ 'command'
$
$! Now set the output to the input of the next
$ infile = outfile
$
$! Release the output file
$ deassign sys$output
$
$! Get the next command
$ goto loop
$
$done:
$! That's all folks
$ delete sys$scratch:*.pip;*
$ exit
==============CUT HERE=======================CUT HERE=======================

File TNOP.COM
==============CUT HERE=======================CUT HERE=======================
$! This cli file creates a string containing the day, month, hour, minute,
$! and second without any punctuation.  The call to this routine is as
$! follows:
$!
$!      @TNOP
$!
$! The string is called TNOP.
$!
$ time = f$time()
$ str = f$cvtime(time,,"DAY") -
        + f$cvtime(time,,"MONTH") -
        + f$cvtime(time,,"HOUR") -
        + f$cvtime(time,,"MINUTE") -
        + f$cvtime(time,,"SECOND")
$ tnop == str
$!
$ exit
==============CUT HERE=======================CUT HERE=======================

File ARGSTR.COM
==============CUT HERE=======================CUT HERE=======================
$! This cli file takes all the arguments from the command line and
$! creates a string.  The call is a follows:
$!
$!      ARGSTR
$!
$! The string is returned through the symbol ARGSTR.
$!
$ test = p1 + " " + p2 + " " + p3 + " " + p4 + " " + p5 + " " + p6  -
         + " " + p7 + " " + p8
$ argstr == f$edit(test, "TRIM")
$!
$ exit
==============CUT HERE=======================CUT HERE=======================