Accessing Files Programmer's Guide (32650-90885)

Appendix A 221
Pascal/XL Program Examples
Program Example A-4
{************************************************************************}
{ procedure close_disk_file is a disk file closing procedure that allowsa }
{ you to specify the final disposition of the file you are closing. }
{************************************************************************}
var
msgbuf : pac80;
begin
FCLOSE (file_num, disp, 0);
if ccode = ccl then
handle_file_error (file_num, 6);
end; { end close_disk_file }
{************************************************************************}
{ Main Program }
{************************************************************************}
begin
filename := '&dataone&';
open_disk_file (old_file, filename, permanent); { STEP 1 }
filename := '&datatwo&';
open_disk_file (new_file, filename, new); { STEP 1 }
outbuf := 'Employee Data File';
label_len := 9;
label_id := 0;
write_user_label(new_file, outbuf, label_len, label_id); { STEP 2 }
copy_oldfile_to_newfile(new_file, old_file); { STEP 3 }
close_disk_file(new_file, temp); { STEP 4 }
close_disk_file (old_file, delete); { STEP 4 }
end.
Program Example A-4
This HP Pascal/XL program illustrates how you can use the FREADSEEK intrinsic to
improve I/O performance during random access reads. The program opens a permanent
disk file containing data, and $STDLIST. Even numbered records are read from the data
file and printed to $STDLIST.
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 (FOPEN) both the the Permanent disk file and $STDLIST (see procedure
open_files).
2. Read (FREADLABEL) the user label from the disk file and write (FWRITE)itto$STDLIST