HP Pascal/iX Reference Manual (31502-90022)

10- 1
Chapter 10 Input and Output
Files
are the means by which a program receives input and produces
output. A file is a sequence of components of the same type. This may
be any type except a file type or a structured type with a file type
component.
Logical files
are files declared in a Pascal program.
Physical files
are
files that exist independently of a program and are controlled by the
operating system. Logical and physical files are associated so that a
program manipulates data objects external to itself.
The components of a file are indexed starting at component 1. Each file
has a current component and a buffer variable whose contents, if defined,
are accessible using a file buffer (^) selector. The standard procedure
read(
f,x
) copies the contents of the current component into
x
and
advances the current position to the next component. The procedure
write(
f,x
) copies
x
into the current component and, like read, advances
the current position.
The standard procedures reset, rewrite, append, or open are used to open
a file for input or output. Reset opens a file in the
input
state so
that writing is prohibited; rewrite and append open a file in the
output
state so that reading is prohibited; and
open
opens a file in the
direct
state so that both reading and writing are legal.
All files are automatically closed on exit from the block in which they
are declared whether by a normal exit or a nonlocal GOTO or escape.
Files allocated on the heap are automatically closed when the file or
structure containing the file is disposed, or the area in which the file
resides is released. All files are closed at the end of the program.
Files opened with reset, rewrite, or append are
sequential files
. In
sequential files, the current position advances only one component at a
time. Files opened with open are direct access files. The current
position may be relocated anywhere in the file using the procedure seek.
Direct access files have a maximum number of components determinable by
the standard function maxpos. The maximum number of components of a
sequential file, on the other hand, is not determinable with an HP Pascal
function.
Textfiles
are special predefined sequential files with char type
components. End-of-line markers are used to substructure textfiles into
lines. The standard procedure writeln creates these markers. The
standard files
input and output
are textfiles. Textfiles cannot be
opened for direct access.
Table 10-1 lists each HP Pascal file procedure or function together
with a brief description of its action. The third column of the table
indicates the permissible categories of files that a procedure or
function may reference.