Requesting Waited Reads
Accessing Files
107365 Tandem Computers Incorporated
4–3
Use the routine in Figure 4-1,
waited_read
, to perform waited reads from the file
specified in the first argument in the invocation and display the records on the
terminal. To invoke this routine, load the file and type:
waited_read
filename
The routine stops when it detects an error or end-of-file.
Figure 4-1. Performing a Waited Read
?SECTION waited_read ROUTINE
#FRAME
#PUSH open_error read_error read_data read_prompt line
#PUSH read_file rslt
#SET rslt [#ARGUMENT /VALUE read_file/ FILENAME OTHERWISE]
[#CASE [rslt]
|1|
== Open the file:
#SET open_error [#REQUESTER /WAIT/ READ [read_file]
read_error read_data read_prompt]
[#IF [open_error] |THEN|
#OUTPUT *** Error opening [read_file]: [open_error]
#RETURN
]
#SET read_error 0
[#LOOP |WHILE| NOT [read_error] |DO|
#APPEND read_prompt *start*
#EXTRACTV read_data line
#OUTPUTV line
]
|OTHERWISE|
#OUTPUT *** Error: Invalid file ***
#RETURN
] == end #CASE
[#IF read_error = 1 |THEN|
#OUTPUT *** End of file ***
|ELSE|
#OUTPUT *** Error reading [read_file]: [read_error]
]
SINK [#REQUESTER/WAIT/CLOSE read_data]
#UNFRAME