HP 3000 Manuals

Using MPE XL Command I/O Redirection [ COMMUNICATOR 3000/XL XL RELEASE 2.1 ] MPE/iX Communicators


COMMUNICATOR 3000/XL XL RELEASE 2.1

Using MPE XL Command I/O Redirection 

by Scott Cressler 
Commercial Systems Division 

FEATURES OF CIOR 

Command I/O Redirection (CIOR) is a new feature of the MPE XL Command
Interpreter (CI) with this XL release.  CIOR allows the redirection of
the input and output of CI commands.  A CI command is a "built-in"
command (such as :SHOWOUT or :SHOWME), a command file, a user-defined
command (UDC), or a program.  CIOR allows the output of a CI command to
be sent to a file or the input of a CI command, which reads from the
terminal, to be taken from a file.

HOW TO USE CIOR 

CIOR provides the following functionality.  There are three forms of
redirection specifications (character sequences which are interpreted by
the CI as requests for I/O redirection):

 *  Use of >fname in a CI command line results in the output of the
    command being written to a temporary file called FNAME. This file
    will either be created, if it doesn't exist, or overwritten if it
    does.

 *  Use of <fname in a CI command line results in the input of the
    command being redirected to a file called FNAME.

 *  Use of >>fname in a CI command line results in the output of the
    command being appended to a temporary file called FNAME. If this file
    doesn't exist, it will be created and written to.

When creating a file that does not exist, the following defaults are
used:

 *  256 byte, variable length, ASCII records

 *  DISC = 10000

 *  TEMP file

 *  NOCCTL

A file equation may be back-referenced to override the defaults used by
CIOR when finding and creating files.  If *fname is used in place of
fname in a redirection specification, the file equation for FNAM will be
applied to opening while performing the redirection.

There are two new MPE XL predefined CI variables that are related to
CIOR.

 *  HPSTDIN: Contains the filename of the file to that input has been
    redirected, or "$STDIN" if input has not been redirected.

 *  HPSTDLIST: Contains the filename of the file that output has been
    redirected, or "$STDLIST" if output has not been redirected.

EXAMPLES 

Here are some examples of the use of CIOR:

     :SHOWME >SHOWFILE
     :PRINT SHOWFILE
     USER: #S285,SCOTT.ACCT,HOME       (NOT IN BREAK)
     RELEASE:...

     :LISTFTEMP SHOWFILE,2

     TEMPORARY FILES FOR SCOTT.ACCT,HOME

     ACCOUNT=  ACCT        GROUP= HOME

     FILENAME  CODE  ------------LOGICAL RECORD-----------  ----SPACE----
                       SIZE  TYP        EOF      LIMIT R/B  SECTORS #X MX

     SHOWFILE          256B  VA          30      10000   1      304  1  * (TEMP)

     :

CIOR can be used to quickly and easily create simple command files or
input files.  For example, to create and use an input file to automate a
common editing operation, you could perform the following:

     :PRINT >MYINPUT
     t file1
     change "old" to "new" in all
     k file1
     y
     :EOD
     tdp <myinput >$null

The file MYINPUT is created by using the :PRINT command to read from
$STDINX (the default when no first parameter to :PRINT is provided) and
write to $STDLIST, which has been redirected to the new TEMP file,
MYINPUT. TDP is then executed with its input redirected to the file and
its output redirected to $NULL.

An easy way to add a line to the file is to use the :ECHO command as
follows:

     :ECHO EXIT >>MYINPUT
     :PRINT MYINPUT
     t file1
     change "old" to "new" in all
     k file1
     y
     exit

The string ">>myinput" results in the output of the :ECHO command being
appended to the MYINPUT file.

This last example is much more complex and uses some of the new features
of XL Release 2.0 and 2.1.  This example shows the power and flexibility
of the CI Command Language when using CIOR to create a software
development tool.

Assume the following command file is named COMP:

     setvar _comp_num_lines finfo(HPSTDIN,'eof')
     while setvar(_comp_num_lines,_comp_num_lines-1) >= 0 and &
           setvar(_comp_next_filename,input())
     " do
       pasxl !_comp_next_filename,Y![rht(_comp_next_filename,&
                                         len(_comp_next_filename)-1)]
     endwhile

This command file is designed to read filenames from a file and compile
each one.  If a file named COMPFILS existed and contained the name of a
file in each record, the COMP command file could be used as follows:

     :FILE LASER;DEV=EPOC
     :COMP <COMPFILS >*LASER

This command file works as follows.  The first command, a :SETVAR, will
initialize the _COMP_NUM_LINES variable to the number of lines in the
input file.  The new HPSTDIN variable provides the name of the input
file, and the FINFO() function is used to get the "end of file" of that
file.  A new feature for XL Release 2.1 of the FINFO() function is used;
strings instead of numbers specify which piece of information is to be
retrieved.

The :WHILE command uses the SETVAR() and INPUT() functions.  The first
SETVAR() function decrements the _COMP_NUM_LINES variable by one and
tests that the result is non-negative.  When this variable becomes
negative, the :WHILE loop will be exited, and every line in the input
file will have been processed.  The other part of the :WHILE expression
reads the next line from the input file, using the INPUT() function, and
sets the _COMP_NEXT_FILENAME variable to that string.  If a line is
empty, the :WHILE loop is exited.

The next command uses PASXL to compile the file named by the
_COMP_NEXT_FILENAME variable.  The name of the source file to compile is
substituted into the PASXL command line using variable substitution.  The
name of the target object file is inserted in the command line using
expression substitution.  A 'Y' is prepended to the file name without the
first letter in the name.  For example, if the contents of the
_COMP_NEXT_FILENAME variable was the string 'OMYSRC.MYGRP.MYACCT', the
PASXL command would become:

     pasxl OMYSRC.MYGRP.MYACCT,YMYSRC.MYGRP.MYACCT

Each file in the input file will be compiled into a file with the same
name except that the first character will be changed to a "Y." The
listing will be sent, one after the other, to the laser printer.



MPE/iX Communicators