Accessing Files Programmer's Guide (32650-90885)

Appendix A 225
Pascal/XL Program Examples
Program Example A-5
Program Algorithm
The task specified above is accomplished by following the steps described below. Also
indicated are the intrinsics used to accomplish file access tasks and the name of the
procedure where the task is accomplished:
1. Open (HPFOPEN) three files, $STDLIST, $STDIN, and a permanent disk file containing
data to update (see procedure open_file).
2. In a loop, lock (FLOCK) a shared data file; read (FREAD) data from disk file; write
(FWRITE) data to $STDLIST; read (FREAD) new data from $STDIN; update (FUPDATE)
shared data file with data read from $STDIN. The loop ends when EOF of disk file is
reached (see procedure update_file).
3. Close (FCLOSE) the disk file (see procedure close_disk_file); let normal program
termination close the other files.
If a file system intrinsic returns an unsuccessful condition code, procedure
handle_file_error is called to print file information (PRINTFILEINFO) and then abort
(QUIT) the program.
Source code listing
Example A-5. Updating a Shared File
$standard_level 'hp3000'$
$lines 100$
$code_offsets on$
$tables on$
$list_code on$
program access_file3(input,output);
{************************************************************************}
{ DECLARATION PART }
{************************************************************************}
const
ccg = 0; { condition code warning }
ccl = 1; { condition code warning }
cce = 2; { condition code successful }
{ HPFOPEN item values}
permanent = 1;
read = 0;
write = 1;
update = 5;
save = 1;
shared = 4;
locking = 1;
type
pac256 = packed array [1..256] of char;
pac80 = packed array [1..80] of char;
{ HPFOPEN status type }
status_type = record
case integer of
0 : (info : shortint;