Accessing Files Programmer's Guide (32650-90885)

98 Chapter5
Opening a File
Opening a System-Defined File
If the HPFOPEN call is successful, a positive integer value is returned in inputfile_num,
and status returns a value of zero. The file is now open and can be read from. If an error
or warning condition is encountered by HPFOPEN, status returns a nonzero value, thus
invoking the error-handling procedure handle_file_error. For more information about
HPFOPEN parameters, refer to the MPE/iX Intrinsics Reference Manual.
Opening $STDLIST
Example 5-4 is an HP Pascal/iX code segment containing an HPFOPEN intrinsic call that
uses the
formaldesignator option
to open the system-defined file $STDLIST.
$STDLIST is the file designator associated with your job or session's standard list device.
For an interactive session, $STDLIST is nearly always a terminal screen. For a batch job,
$STDLIST is usually a line printer. You can also open $STDLIST using the HPFOPEN
designator option
(illustrated in Example 5-3).
Example 5-4. Opening $STDLIST Using HPFOPEN
formaldesignator option
procedure open_standard_list_device
const
formal_designator_option = 2; {defines HPFOPEN
itemnum
2}
type
pac80 = packed array [1..80] of char;
var
listfile_num : integer; {required HPFOPEN
filenum
parameter}
status : integer; {returns info if error/warning occurs }
file_name : pac80; {declares HPFOPEN
item
2 }
begin
listfile_num := 0;
status := 0;
file_name := '$stdlist'; {Specifies system-defined file }
{Blank is used as delimiter }
HPFOPEN (listfile_num, status,
formal_designator_option, file_name,
{
formaldesignator option
}
);
if status <>0 then handle_file_error (listfile_num, status);
end;
If the HPFOPEN call is successful, a positive integer value is returned in listfile_num, and
status returns a value of zero. The standard list device is now open and can be written to.
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 $STDLIST. For more information about HPFOPEN parameters, refer to the MPE/iX
Intrinsics Reference Manual.