Accessing Files Programmer's Guide (32650-90885)
208 AppendixA
Pascal/XL Program Examples
Program Example A-2
begin
open_unlabeled_tape_file (tape_file); { STEP 1 }
filename := '&$stdlist&'; { STEP 1 }
open_file (std_list, filename, permanent,write); { STEP 1 }
filename := '&dataone&'; { STEP 1 }
open_file (disk_file, filename, new,update); { STEP 1 }
copy_tapefile_to_discfile(tape_file,disk_file); { STEP 2 }
close_file(disk_file, save_temp); { STEP 3 }
close_file(tape_file, save_perm); { STEP 3 }
end. {end program }
Program Example A-2
This Pascal/XL program example illustrates how you can use the HPFOPEN intrinsic to open
a labeled magnetic tape file, then open a new disk file with a user-supplied name. After
records are sequentially copied from the tape file to the disk file, both files are closed, the
disk file is closed as a Permanent file. If the file system determines that another file of the
same name exists in the permanent file directory, the user is allowed to specify alternate
file names until the file close operation is successful.
Program Algorithm
The task specified above is accomplished using six steps. 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) labeled magnetic tape file (see procedure open_tape_file).
2. Read from $STDIN (READ) a user-supplied file name, then open (HPFOPEN) a new disk
file using the given name (see procedure open_disk_file).
3. Read (FREADLABEL) the user label from the tape file and then print (PRINT) the label to
$STDLIST (see procedure print_user_label).
4. In a loop, use sequential access method to read (FREAD) records from tape file and write
(FWRITE) them to the disk file (see procedure copy_file_from_tape_to_disc).
5. Close (FCLOSE) the tape file (see procedure close_tape_file).
6. Close (FCLOSE) the new disk file as a permanent file (see procedure
close_disk_file). If an error occurs during the FCLOSE call, the user is given the
opportunity (CAUSEBREAK) to interactively fix the problem (see procedure
handle_fclose_error) before the program again attempts to close the disk file as a
permanent file.
This program makes extensive use of error handling routines to:
• return to the user a file system error number (FCHECK) associated with a file system
intrinsic error (refer to procedure print_fserr).
• interpret and return to the user error information returned by the status parameter of
a failed HPFOPEN call (see procedure print_hpfopen_error).