HP Pascal/iX Programmer's Guide (31502-90023)

3- 12
Table 3-4. Characteristics of Sequential I/O Procedures
------------------------------------------------------------------------------------------------
| |||||
| Procedure | get | read | put | write |
| |||||
------------------------------------------------------------------------------------------------
||||
| State that file must | Read-only or read-write | Write-only or read-write |
|bein* | | |
||||
------------------------------------------------------------------------------------------------
| | |||
| Assigns value of | Current component | Buffer | Specified |
| | | | variable |
| | |||
------------------------------------------------------------------------------------------------
| ||| |
| To | Buffer | Specified | Current component |
| | | variable | |
| ||| |
------------------------------------------------------------------------------------------------
|| |
| Advances current | To next component ** |
| position index | |
|| |
------------------------------------------------------------------------------------------------
||||
| After call, buffer | No | Yes |
| is undefined | | |
||||
------------------------------------------------------------------------------------------------
* For sequential I/O, the state must be read-only or write-only. The
state read-write is included here because these sequential I/O
procedures work the same way on direct (read-write) files (see
"Direct Input/Output" ).
** For all the procedures except
get
, the current position index is
advanced to the component after the assignment. See the explanation
of
deferred get
that follows this table.
The procedures get and read assign values to the buffer with
deferred
get
. Deferred get allows HP Pascal to maintain the original Pascal
definition of get while avoiding unexpected behavior with input from
interactive I/O devices (such as terminals).
The procedure get advances the current position index to the next
component and moves the next component into the buffer variable.
The procedure reset opens a file for sequential input, positions the file
at the first component, and performs a get.
If the get (Pascal definition) is performed after a reset to a terminal,
a physical read is required to fill the buffer variable. Consequently, a
program is paused for input from the terminal before the program requests
an input operation.
The deferred get avoids this problem. With deferred get, the procedure
get advances the current position index to the next component and, on the
next reference to the buffer variable, moves the current component into
the buffer variable. The reference to the buffer variable can be
explicit (f^) or implicit. For example, read(f,v) or eof(f).
Example 1
PROGRAM prog;
TYPE
seqfile = FILE OF char;