Accessing Files Programmer's Guide (32650-90885)

Chapter 9 133
Reading from a File
Reading From $STDIN
Reading From $STDIN
You can read data from your program's standard input device ($STDIN) by using one of the
following intrinsics:
READ
READX
FREAD
The job/session input device is the source of all MPE/iX commands relating to a job or
session and is the primary source of all ASCII information input to the job or session. You
can read a string of ASCII characters from the job/session input device into an array in
your program with the READ and READX intrinsics. The READ and READX intrinsics are
identical, except that the READX intrinsic reads input from $STDINX instead of $STDIN. The
$STDINX file is equivalent to $STDIN, except that records with a colon (:) in the first column
of a line indicate the end-of-file to $STDIN, and only the commands :EOD, and EOF indicate
the end of file for $STDINX.
NOTE
The READ and READX intrinsics are limited in their usefulness in that FILE
commands are not allowed. In addition, you cannot use the FCHECK intrinsic
to determine error conditions encountered by READ or READX. You may find it
more convenient (and a better programming practice) to use the
HPFOPEN/FOPEN intrinsic to open the files $STDIN or $STDINX, then issue
FREAD calls against these files.
If the standard input device ($STDIN) and the standard list device ($STDLIST) are opened
with an HPFOPEN/FOPEN intrinsic call, the FREAD and FWRITE intrinsics can be used with
these devices. For example, the FREAD intrinsic can be used to transfer information entered
from a terminal to a buffer in the stack, and the FREAD intrinsic can be used to transfer
information from your stack directly to the standard list device.
Example 9-3 is an HP Pascal/iX code segment that uses the PRINT intrinsic to prompt a
user for a file designator, then uses the READ intrinsic to read the input from $STDIN.
Assume that the file designator is then returned to a procedure that calls HPFOPEN to
open a file with the
formaldesignator option
passing the file name specified by the user.
Example 9-3. Reading from $STDIN Using READ
procedure get_file_designator (var file_name : packed array [1..80] of
char);
var
message : packed array [..80] of char; {holds prompt to user }
length : shortint; {length of prompt }
control_code : shortint; {required by PRINT }
read_length : shortint; {length read by READ }
expected_length : shortint; {size of message array}
begin