Accessing Files Programmer's Guide (32650-90885)

Appendix A 223
Pascal/XL Program Examples
Program Example A-4
begin
printfileinfo (filenum);
quit (quitnum);
end; {end error_handler }
procedure open_files;
{************************************************************************}
{ procedure open_files opens the data file and $STDLIST using the FOPEN }
{ intrinsic. }
{************************************************************************}
const
permanent = 5;
read_write = 4;
stdlist = 12;
write = 1;
begin
datafile_name:= 'datafile ';
listfile_name:= 'listfile ';
datafile:= fopen(datafile_name,permanent,read_write,-80);
if ccode <> CCE then error_handler(datafile,1);
listfile:= fopen(listfile_name,stdlist,write);
if ccode <> CCE then error_handler(listfile,2);
end; {end open_files }
procedure read_user_label;
{************************************************************************}
{procedure read_user_label reads the user label located in the }
{user-defined label portion of the data file, then prints it to $STDLIST.}
{************************************************************************}
begin
freadlabel(datafile,buffer,-80);
if ccode <> CCE then error_handler(datafile,101);
fwrite (listfile,buffer,-80,0);
if ccode <> CCE then error_handler(listfile,102);
end; {end read_user_label }
procedure read_from_datafile;
{************************************************************************}
{ procedure read_from_data_file first calls procedure read_user_label to }
{ print the label to $STDLIST, then enters a loop to select only even }
{ numbered records from the data file and writing them to $STDLIST. }
{************************************************************************}
var end_of_file: boolean;
begin
end_of_file:= false; {initialize loop control }
record_num:= 0;
{ enter loop, random access read even }
{ numbered record, freadseek next }