HP Pascal/iX Reference Manual (31502-90022)

10- 5
associate
Usage
associate
(f, num, option_str)
Parameters
f
A variable of type file.
num
The system-provided file number of a previously opened
file.
option_str
Must be one of the following:
READ associate to sequential access file
with read access.
WRITE associate to sequential access file
with write access.
READ, DIRECT associate to direct access file with
read access.
WRITE, DIRECT associate to direct access file with
write access.
READ, WRITE, DIRECT associate to direct access file with
read/write access.
DIRECT same as READ, WRITE, DIRECT.
NOREWIND associate to a file without changing
the current file position.
Description
The procedure associate
(f,num,option_str)
allows the opened file
num
to
be used with Pascal input/output routines through
f
. The file must
already be open as the result of a direct call to an operating system
routine or as the result of a call to a non-Pascal procedure. The file
cannot be opened as a result of a Pascal append, associate, open, reset,
or rewrite. Therefore, the Pascal function fnum cannot be used to
determine the file number of a file opened by Pascal. The file must also
be open.
One of the above-mentioned combinations must appear in
option_str
. It is
also an error to specify read or write access if the physical file is not
opened for read or write access, respectively.
Other options legal for opening a file, such as those in the
HP Pascal/iX
Programmer's Guide
or the
HP Pascal/HP-UX Programmer's Guide
, are
ignored.
Associate places the current file position at the first component of the
file unless NOREWIND is specified. The contents of
f
, if any, are
undisturbed, and
f
is undefined. If the
option_str
parameter specifies
WRITE, then eof(
f
) returns true, even though the actual end of file
remains at the end of any previously existing data in the file. If the
option_str
parameter specifies read access for a sequential file or read
or write access for a direct access file, eof(
f
) returns false after the
call to associate. If the file is empty and is associated to read
access, a subsequent read causes an error.
Example
associate(file_var,file_number,option_str)
Illustration
Suppose examp_file is an opened logical file of char with three
components. To read sequentially from examp_file, we call associate: