HP 3000 Manuals

Ch 10. Input and Output [ HP Pascal/iX Reference Manual ] MPE/iX 5.0 Documentation


HP Pascal/iX Reference Manual

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.

          Table 10-1.  File Procedures and Functions 

-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
|   Procedure or    |                       Action                        | Permissible Files |
|     Function      |                                                     |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| append            | Opens file in output state.  Current position is    | any               |
|                   | after last component and eof is true.               |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| associate         | Associates a logical file with an open physical     | any               |
|                   | file.                                               |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| close             | Closes a file.                                      | any               |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| disassociate      | Disassociates a logical file from it's associated   | any               |
|                   | open physical file.                                 |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| eof               | Returns true if file opened in output state, if no  | any               |
|                   | component exists for sequential input, or if        |                   |
|                   | current position in direct access file is greater   |                   |
|                   | than lastpos.                                       |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| eoln              | Returns true if the current position of a text file | input textfiles   |
|                   | is at a line marker.                                |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| get               | Allows assignment of current component to buffer    | input or direct   |
|                   | and, in some cases, advances current position.      | files             |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| lastpos           | Returns index of highest written component of       | direct access     |
|                   | direct access file.                                 | files             |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| linepos           | Returns number of characters read from or written   | textfiles         |
|                   | to a textfile since the last line marker.           |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| maxpos            | Returns maxint or the maximum component possible to | direct access     |
|                   | read or write.  Check implementation.               | files             |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| open              | Opens file in direct access state.  Current         | any file except a |
|                   | position is 1 and eof is false.  Eof is true if     | textfile          |
|                   | file is empty.                                      |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| overprint         | A form of write which causes the next line of a     | output textfiles  |
|                   | textfile to print over the current line.            |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| page              | Causes skip to top of new page when a textfile is   | output textfiles  |
|                   | printed.                                            |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| position          | Returns integer indicating the current component of | any file except a |
|                   | a non-text file.                                    | textfile          |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------

          Table 10-1.  File Procedures and Functions (cont.) 

-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
|   Procedure or    |                       Action                        | Permissible Files |
|     Function      |                                                     |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| prompt            | A form of write which assures textfile buffers have | output textfiles  |
|                   | been written to the device.  No line marker is      |                   |
|                   | written.                                            |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| put               | Assigns the value of the buffer variable to the     | output or direct  |
|                   | current component and advances the current          | access files      |
|                   | position.                                           |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| read              | Copies current component into specified variable    | input or direct   |
|                   | parameter and advances current position.            | access files      |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| readdir           | Moves current position of a direct access file to   | direct access     |
|                   | designated component and then performs read.        | files             |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| readln            | Performs read on textfile and then skips to next    | input textfiles   |
|                   | line.                                               |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| reset             | Opens file in input state.  Current position is 1.  | any               |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| rewrite           | Opens file in output state.  Current position is 1  | any               |
|                   | and eof is true.  Old components discarded.         |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| seek              | Places current position of direct access file at    | direct access     |
|                   | specified component number.                         | files             |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| write             | Assigns parameter value to current file component   | output or direct  |
|                   | and advances current position.                      | access files      |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| writedir          | Advances current position in direct access file to  | direct access     |
|                   | designated component and performs a write.          | files             |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------
|                   |                                                     |                   |
| writeln           | Assigns parameter value to current textfile         | output textfiles  |
|                   | component, appends a line marker and advances       |                   |
|                   | current position.                                   |                   |
|                   |                                                     |                   |
-----------------------------------------------------------------------------------------------



MPE/iX 5.0 Documentation