Accessing Files Programmer's Guide (32650-90885)

138 Chapter10
Updating a File
{ procedure update_disk_file updates records in the disk file }
{ with the replacement records read from $STDIN }
{**************************************************************}
var
dummy : integer;
inbuf : array [1..80] of char;
end_of_file : boolean;
read_length : integer;
begin
{Lock the file and suspend }
end_of_file := false;
FLOCK (disk_file_num, 1);
if ccode = ccl then
handle_file_error (disk_file_num, 0);
{Begin loop }
repeat
{ Read record from disk file, then write record to $STDLIST; }
{ read updated record number from $STDIN and update }
{ the disk file with the input record and unlock disk file. }
read_length := FREAD (disk_file_num, inbuf, 128);
{read in record}
if ccode = ccg then
end_of_file := true {exit condition }
else
begin
FWRITE (std_list, inbuf, -20, octal('320'));
{user reviews record}
if ccode <> cce then
handle_file_error (std_list, 5);
dummy := FREAD (std_in, inbuf[20], 5);
{input updated field}
if ccode = ccl then
handle_file_error (std_list, 6);
else
if ccode = ccg then
end_of_file := true; {exit condition}
FUPDATE (disk_file_num, inbuf, 128); {update record }
if ccode <> cce then
handle_file_error (disk_file_num, 7);
end
until end_of_file; {test for EOF }
FUNLOCK (disk_file_num); {final unlock of disk file}
if ccode <> cce then
handle_file_error (disk_file_num, 2);
end: {end update_file }