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.
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:
Rexx I/O is done using CSL calls, so it is pretty efficient.
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
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 ]
]