HP 3000 Manuals

Opening a File Mapped [ Accessing Files Programmer's Guide ] MPE/iX 5.0 Documentation


Accessing Files Programmer's Guide

Opening a File Mapped 

Example 11-1 illustrates how a file is created and opened with
short-mapped access.  This HP Pascal/XL program segment opens the file,
then writes data to the file with assignments to the array structure.
The procedure then sets the EOF and closes the file.

The file is then reopened short-mapped, and data is retrieved before the
file is closed and purged.

Example 11-1.  Opening a Mapped File 

     procedure Mapped_File_Example;
     type
       record_t = record               {** defines an 80-byte record **}

                    a_record : packed array [1..80] of char;
                  end;
       file_t = array [1..50000] of record_t;
                                       {** define a 4,000,000 byte array **}
     var
       access,domain       : integer;
       dummy               : shortint;
       file_name           : packed array [1..20] of char;
       file_number         : integer;
       file_ptr            :^file_t; {** pointer to the file **}
       filesize            : integer;
       index, rec          : integer;
       create_domain_perm  : integer;
       read_write_access   : integer;
       domain_old          : integer;
       status              : record
                               case integer of
                                 0:    (all:    integer);
                                 1:    (info:   shortint;
                                        subsys:  shortint);
                             end;
     const
       file_name_option     =   2;
       domain_option        =   3;
       filesize option      =  35;
       short_mapped_option  =  18;
       access_type_option   =  11;

     begin
                     {** initialize item values for the HPFOPEN **}
          file_name           := '%EXAMPLE%';
          create_domain_PERM  := 4;
          domain_OLD          := 3;
          filesize            := 15265;
          read_write_access   := 4;

                      {** create a short-mapped file **}
          HPFOPEN (
                    file_number, status,
                    file_name_option, file_name
                    domain_option,create_domain_PERM,
                    filesize option, filesize,
                    short_mapped_option, file_ptr,
                    access_type_option, read_write_access,
                  );
                      {** put some data into the file **}
          for rec := 1 to 100 do
               for index := 1 to 80 do
                    file_ptr^[rec].a_record[index] :=
                              Chr (((rec - 1) Mod 26) + 65);

                         {** set the logical record pointer **}
          FPOINT (file_number, 33);
          FCONTROL (file_number, 6, dummy);        {** set the EOF **}
          FCLOSE (file_number, 0, 0);            {**close the file **}

                            {** re-open the same short-mapped file **}
          HPFOPEN (
                    file_number, status,
                    file_name_option, file_name,
                    domain_option, domain_OLD,
                    short_mapped_option, file_ptr,
                  );

                            {** retrieve some data you put in file **}
          for rec := 1 to 100 do
          begin
               write ('Record-', rec:4, ' ');
               for index := 1 to 20 do
                    write (file_ptr^[rec].a_record[index];
               writeln;
          end;
                                      {** close and purge the file **}
          FCLOSE (file_number, 4, 0);
     end;



MPE/iX 5.0 Documentation