The miscellaneous routines are generally used when dealing with sequential access files. In some cases, they can be used on direct or keyed access files.
1 – EOF
The EOF (end of file) function indicates whether the file
pointer is positioned after the last component in a file by
returning a Boolean value.
Syntax:
EOF[[( file_variable )]]
The 'file_variable' is the name of the file variable associated
with the input file. If you omit the name of the file, the
default is INPUT.
The file can be in either inspection or generation mode before
EOF is called; however, end-of-file must be defined. The input
operations GET, RESET, and FINDK are guaranteed to leave
end-of-file defined. The file mode does not change after EOF
has been executed.
EOF returns TRUE when the file pointer is positioned after the
last component in the file, and returns FALSE up to and
including the time when the last component of the input file is
read into the file buffer. You must attempt to retrieve another
file component after the last to determine whether the file is
positioned at end-of-file.
When EOF is tested for a file with relative organization opened
for direct access, the result is TRUE if the file is in
inspection mode and the last GET or RESET operation positioned
the file beyond the last existing component. If the file is in
generation or undefined mode, the result of EOF is undefined.
When EOF is tested for a file with indexed organization opened
for keyed access, the result is TRUE if the file is in
inspection mode and the last FINDK, GET, RESET, or RESETK
operation positioned the file beyond the last component with the
current key number. Successful attempts at FINDK, GET, RESET,
and RESETK cause EOF to be FALSE. If the file is not in
inspection mode, EOF is undefined.
If you attempt to read a file after EOF becomes TRUE, an error
occurs.
See the "HP Pascal Language Reference Manual" for a complete
description of the EOF function.
2 – STATUS
The STATUS function indicates the status of a file following the
last operation performed on it.
Syntax:
STATUS( file_variable )
The 'file_variable' is the name of the file variable associated
with the file to be tested.
The file can be in any mode before STATUS is called; unless an
error occurs, STATUS does not change the file mode upon
execution.
The STATUS function returns integer codes indicating the
previous operation's effect on the file. If the operation is
successful, 0 is returned. If end-of-file is encountered, -1 is
returned. If an error is encountered, a positive integer is
returned. (The actual number is environmental specific and
indicates the exact error that occured.)
A test by the STATUS function on a TEXT file causes delayed
device access to occur, thus filling the file buffer with the
next file component. Therefore, EOF, EOLN, UFB, and STATUS
never return an error code following a successful STATUS
function call.
See the "HP Pascal Language Reference Manual" for a complete
description of the STATUS function.
3 – TRUNCATE
The TRUNCATE procedure indicates that the current file component
and all components following it are to be deleted. TRUNCATE can
only be used on a file that has sequential organization.
Syntax:
TRUNCATE( file_variable [[, ERROR := error-recovery]] );
The 'file_variable' is the name of the file variable associated
with the file to be truncated.
The 'error-recovery' specifies the action to be taken if an
error occurs during execution of the routine. By default, after
the first error, the error message is printed and execution is
stopped.
The file must be in inspection mode before TRUNCATE is called.
After the procedure has been executed, the mode is set to
generation so that you can write to the file.
After the appropriate components have been deleted, the file
remains positioned at the new end-of-file, but the file buffer
itself is undefined. Thus, EOF and UFB are both set to TRUE.
See the "HP Pascal Language Reference Manual" for a complete
description of the TRUNCATE procedure.
4 – UFB
The UFB (undefined file buffer) function returns a Boolean value
that indicates whether the last file operation gave the file
buffer an undefined status.
Syntax:
UFB( file_variable )
The 'file_variable' is the name of the file variable associated
with the file whose buffer is being tested.
The file can be in any mode before UFB is called; execution of
UFB does not change the file mode.
UFB tests the effect of the last I/O operation done to the file.
UFB returns FALSE if a successful GET, FIND, FINDK, RESET, or
RESETK operation has filled the file buffer. GET, FIND, FINDK,
RESET, and RESETK procedure calls that do not fill the file
buffer set UFB to TRUE.
UFB also returns TRUE after DELETE, EXTEND, LOCATE, PUT,
REWRITE, TRUNCATE, and UPDATE procedures have left the contents
of the file buffer unknown.
Assigning a new value to the file buffer with an assignment
statement does not change the value of UFB.
See the "HP Pascal Language Reference Manual" for a complete
description of the UFB function.
5 – UNLOCK
The UNLOCK procedure releases the current file component for
access by other processes.
Syntax:
UNLOCK( file_variable [[, ERROR := error-recovery]] );
The 'file_variable' is the name of the file variable associated
with the file whose component is to be unlocked.
The 'error-recovery' specifies the action to be taken if an
error occurs during execution of the routine. By default, after
the first error, the error message is printed and execution is
stopped.
The file must be in inspection mode before UNLOCK is called; it
remains in inspection mode after UNLOCK has executed.
If the component at which the file pointer is positioned has
been locked, the UNLOCK procedure releases it.