Accessing Files Programmer's Guide (32650-90885)

94 Chapter5
Opening a File
Opening a Disk File
following examples show how you can use the HPFOPEN intrinsic to open a disk file:
"Opening a new disk file" shows an example of an HPFOPEN call that creates a new disk
file (see example 5-1).
"Opening a permanent disk file" shows an example of an HPFOPEN call that opens a
permanent disk file that is to be shared among multiple concurrent accessors (see
example 5-2).
Opening a new disk file
Example 5-1 is an HP Pascal/iX code segment containing an HPFOPEN intrinsic call that
opens a new disk file to be used with a text editor. The text editor accesses only standard
ASCII text files with fixed-length records, each record 80 bytes in size.
Knowing this, you can specify the appropriate HPFOPEN options, and allow others
(specifically,
domain option
,
record format option
, and
file type option
) to default
to the desired characteristics. Note that the HPFOPEN
final
disposition option
is specified to indicate that the file is to be saved as a temporary file
at close time.
Example 5-1. Opening a New Disk File
procedure open_new_disk_file;
const
formal_designator_option = 2; {defines HPFOPEN
itemnum
2 }
record_size_option =19; {defines HPFOPEN
itemnum
19 }
final_disposition_option =50; {defines HPFOPEN
itemnum
50 }
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 }
line_len : integer; {declares HPFOPEN
itemnum
19 }
save_perm : integer; {declares HPFOPEN
itemnum
50 }
ascii : integer; {declares HPFOPEN
itemnum
53 }
begin
file_num :=0;
status :=0;
file_name :='&myfile/lock.mygroup&'; (
filereference
format}
line_len :=80; {maximum record/line length }
save_temp :=2; {make temp file at close }
ascii :=1; {label indicates ASCII code }
HPFOPEN (file_num, status,
formal_designator_option,file_name, {
formal designator option
}
record_size_option, line_len, {
record size option
}
final_disp_option, save_temp, {
final disposition option
}