Accessing Files Programmer's Guide (32650-90885)

Appendix A 213
Pascal/XL Program Examples
Program Example A-2
{************************************************************************}
{* PURPOSE: *}
{* This routine prompts the user for a file name and opens a *}
{* NEW disk file using the given name. *}
{* PARAMETERS: *}
{* file_num (output) *}
{* - file number of the open disk file *}
{************************************************************************}
const
{* define HPFOPEN item numbers *}
formal_designator_option = 2;
access_type_option = 11;
ascii_binary_option = 53;
var
{* define HPFOPEN items *}
update : integer;
ascii : integer;
file_name : pac80;
{* define scratch variables *}
index : integer;
msgbuf : pac80;
read_length : integer;
status : status_type;
begin {* open_disk_file *}
{* prompt user for a file name a read the user-specified name *}
{***************************************************************}
msgbuf := 'Name of new disk file to be created?';
PRINT (msgbuf, -36, 0);
read_length := READ (file_name, -8);
{* shift file name one character to the right to make room for the *}
{* delimiters *}
{************************************************************************}
for index := read_length downto 1 do
file_name[index + 1] := file_name[index];
{* add delimiters to file name *}
{*******************************}
file_name[1] := '&';
file_name[read_length + 2] := '&';
{* set up the remaining item values for the HPFOPEN intrinsic *}
{**************************************************************}
ascii := 1; {* the disk file is to be an ASCII file *}
update := 5; {* update access will be used to write to the disk file*}
HPFOPEN (file_num, status, formal_designator_option, file_name,
ascii_binary_option, ascii,
access_type_option, update);