Accessing Files Programmer's Guide (32650-90885)

224 AppendixA
Pascal/XL Program Examples
Program Example A-5
{ selection, then sequential write }
{ to $STDLIST, till EOF. }
while not end_of_file do
begin
freaddir(datafile,buffer,-80,record_num);
if ccode <> CCE then error_handler(datafile,103);
record_num:= record_num + 2;
freadseek(datafile,record_num);
if ccode = CCL then error_handler(datafile,104) else
if ccode = CCG then end_of_file:= true;
fwrite(listfile,buffer,-80,0);
if ccode <> CCE then error_handler(listfile,105);
end;
end; {end read_from_datafile }
procedure close_files;
{************************************************************************}
{ procedure close_files calls the fclose intrinsic twice to close bot }
{ files previously opened by procedure open_files. }
{************************************************************************}
begin
fclose(datafile,0,0);
if ccode <> CCE then error_handler(datafile,1001);
fclose(listfile,0,0);
if ccode <> CCE then error_handler(listfile,1002);
end;
{************************************************************************}
{ MAIN PROGRAM }
{************************************************************************}
begin
open_files; { STEP 1 }
read_user_label; { STEP 2 }
read_from_datafile; { STEP 3 }
close_files; { STEP 4 }
end. {end main program }
Program Example A-5
This HP Pascal/XL program example illustrates how you can update a particular record of
a shared data file. In addition, this program example uses file system locking intrinsics
(FLOCK, FUNLOCK) to ensure exclusive access to the file while the update occurs.