Accessing Files Programmer's Guide (32650-90885)

96 Chapter5
Opening a File
Opening a Disk File
update :=5; {enable update access to file }
lockable :=1; {enable dynamic locking option }
shared :=3; {allow concurrent access by all }
ascii :=1; {label will indicate ASCII code }
HPFOPEN (file_num, status,
formal_designator_option,file_name, {
formaldesignator option
}
domain_option, permanent, {
domain option
}
access_type_option, update, {
access type option
}
dynamic_locking_option, lockable, {
dynamic locking option
}
exclusive_option, shared, {
exclusive option
}
ASCII_binary_option, ascii {
ASCII/binary option
}
);
if status <> 0 then handle_file_error (file_num, status);
end;
The file name passed in the
formaldesignator option
contains MPE/iX command
interpreter variables and expressions that are evaluated by HPFOPEN before the file name
is parsed and evaluated. HPFOPEN substitutes ![FINFO(datafile",33)] with the
lockword associated with file datafile (if the security provisions in effect enable you to
obtain the file's password). The exclamation point (!) before the variable name hpgroup
instructs HPFOPEN to substitute the value of the variable in place of the variable name. For
more information about using command interpreter variables and expressions, refer to the
Command Interpreter Access and Variables Programmer's Guide.
If the HPFOPEN call is successful, a positive integer value is returned in file_num, and
status returns a value of zero. The file is now open and can be accessed with file 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-5 uses a similar procedure to
open a permanent disk file. For more information about HPFOPEN parameters, refer to the
MPE/iX Intrinsics Reference Manual.