Accessing Files Programmer's Guide (32650-90885)

Chapter 5 95
Opening a File
Opening a Disk File
ASCII_binary_option, ascii {
ASCII/binary option
}
);
if status <> 0 then handle_file_error (file_num, status);
end;
If the HPFOPEN call is successful, a positive integer value is returned in file_num, and
status returns a value of zero. The new disk file is now open and can be accessed with
system intrinsics. If an error or warning condition is encountered by HPFOPEN, status
returns a nonzero value, thus invoking the error-handling procedure handle_file_error.
In appendix A, "HP Pascal/iX Program Examples," Example A-1 uses a similar procedure
to open a new disk file. For more information about HPFOPEN parameters, refer to the
MPE/iX Intrinsics Reference Manual.
Opening a permanent disk file
Example 5-2 is an HP Pascal/iX code segment containing an HPFOPEN intrinsic call that
opens a permanent disk file that is to be shared among multiple concurrent accessors. Note
the use of the
dynamic locking option
to enable the use of file-locking intrinsics (FLOCK
and FUNLOCK) with this file. The file is opened update access to allow opening the file with
Read/Write access without affecting the current EOF. Thus, current data in the file is
retained.
Example 5-2. Opening a Permanent Disk File
procedure open_permanent_disk_file;
const
formal_designator_option = 2; {defines HPFOPEN
itemnum
2 }
domain_option = 3; {defines HPFOPEN
itemnum
3 }
access_type_option =11; {defines HPFOPEN
itemnum
11 }
dynamic_locking_option =12; {defines HPFOPEN
itemnum
12 }
exclusive_option =13; {defines HPFOPEN
itemnum
13 }
ASCII_binary_option =53; {defines HPFOPEN
itemnum
53 }
type
pac80 = packed array [1..80] of char;
var
file_num : integer; {required HPFOPEN
filenum
parameter }
status : integer; {returns info if error/warning occurs}
file_name : pac80; {declares HPFOPEN
itemnum
2 }
permanent : integer; {declares HPFOPEN
itemnum
3 }
update : integer; {declares HPFOPEN
itemnum
11 }
lockable : integer; {declares HPFOPEN
itemnum
12 }
shared : integer; {declares HPFOPEN
itemnum
13 }
ascii : integer; {declares HPFOPEN
itemnum
53 }
begin
file_num :=0;
status :=0;
file_name :='&datafile/![FINFO("datafile",33)].!hpgroup&';
permanent :=1; {search in permanent file directory}