[MVMRUG Logo]

REXX I/O from the Developer's Point of View

by Gary Brodock - C. W. Costello & Associates, Inc.

In this session, Gary provided us with some insights into the design approach that his team took when adding I/O support to Rexx. Along the way we got a good basic education on Rexx I/O functions and took home a few examples of Rexx programs that used them.

The team's basic approach was to follow the Rexx language standard for I/O and apply it in a way that would make sense in a VM environment. Seven new built-in functions were added, a variant on the PARSE instruction was added, and support was added in the SIGNAL and CALL instructions.

  1. New Functions

    1. Line-based Functions

      • LINEIN retrieves lines (records) from an input stream
      • LINEOUT writes lines (records) to an output stream
      • LINES returns the number of lines remaining in an input stream

    2. Character-based Functions

      • CHARIN returns a specified number of characters from an input stream
      • CHAROUT writes a specified number of characters to an output stream
      • CHARS indicates whether there are more characters in a stream

    3. STREAM function returns information (ERROR, READY/NOTREADY, UNKNOWN) about an I/O stream, or performs an action (OPEN, CLOSE, LINEPOS, QUERY) on an I/O stream.

  2. Streams

    Streams are some source of or destination for information. We typically think of I/O being done to files, but Rexx I/O support allows us to work with other sources and destinations. The various type of streams supported include:

    1. RDR
    2. PUNCH
    3. PRINTER
    4. SFS file (directory need not be accessed)
    5. MINIDISK file
    6. PROGRAM STACK

    Rexx I/O is done using CSL calls, so it is pretty efficient.

  3. Related Instructions

    1. PARSE LINEIN obtains the value of the next input line and parses it according to normal template parsing rules.

    2. SIGNAL detects conditions set by Rexx I/O, allowing programs to trap situations such as an I/O stream that is NOTREADY.

  4. Examples:

    1. Example #1

      Here is a very simple example that copies one stream to another.

      /* COPYIT EXEC - Invoke as: copyit(stream1,stream2)
      /* This routine copies the stream of file named by the first */
      /* argument to the stream or file named by the second, as lines. */

      Parse arg inname, outname
      Do while lines(inname) > 0
      call lineout outname, linein(inname)
      End

    2. Example #2

      Who doesn't have an exec that generates random gems of wisdom?

      /* GETSAY EXEC */
      /* Read the first line of the input file and get the number of */
      /* lines in the file. Generate a random number from 2 to the */
      /* number of lines in the file and then read that line. */
      /* Display this message to the user. */

      infile = 'SAYINGS SCRIPT A'
      Parse value stream(infile,'c',"open read") with ok handle
      If ok = 'READY:' then nop
      Else Do
          'MSG Error in opening' infile
          'MSG Description string =' stream(infile,'d')
          Exit 100
      End
      How_many = word(linein(handle,1),1)
      num = random(2,how_many)
      Say linein(infile,num)


[ [ Home | About MVMRUG | Meeting Schedule ] ]


Last revised: May 5,1997 by J. P. Ake (ake@timken.com)