Accessing Files Programmer's Guide (32650-90885)

Appendix A 215
Pascal/XL Program Examples
Program Example A-2
inbuf : pac80;
msgbuf : pac80;
end_of_file : boolean;
read_length : integer;
begin {* copy_file_from_tape_to_disk *}
end_of_file := false;
repeat
{* copy a buffer from the tape file to the disk file until the *}
{* end of the tape file is reached *}
{*********************************************************************}
read_length := FREAD (tape_file, inbuf, 40);
{* read buffer from tape *}
if ccode = ccl then {* check for error condition *}
begin
msgbuf := 'Can''t read tape file';
PRINT (msgbuf, -20, 0);
print_fserr (tape_file);
handle_file_error (tape_file, 4);
end
else
if ccode = ccg then {* check for end of file condition *}
end_of_file := true
else
begin
FWRITE (disk_file, inbuf, read_length, 0);
{* write buffer to disk *}
if ccode <> cce then {* check for error condition *}
begin
msgbuf := 'Can''t write to disk file';
PRINT (msgbuf, -24, 0);
print_fserr (disk_file);
handle_file_error (disk_file, 5);
end;
end;
until end_of_file;
end; {* copy_file_from_tape_to_disk *}
procedure close_tape_file
(
file_num : integer
);
{************************************************************************}
{* PURPOSE: *}
{* This routine closes the tape file. *}
{* PARAMETERS: *}
{* file_num (input) *}
{* - file number of open tape file *}
{************************************************************************}
var