?? RIGHT := 110 ??
?? NEWTITLE := 'INSTALL_SOFTWARE Utility: RAP$OPEN_PACKING_LIST_USING_ICR Interface.' ??
MODULE ram$open_packing_list_using_icr;

{ PURPOSE:
{   This module contains the interface that opens the packing list using an
{   installation control record.
{
{ DESIGN:
{   The compiled module resides in RAF$LIBRARY.
{
{ NOTES:
{

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc rae$install_software_cc
*copyc rac$control_job_identifier
*copyc rac$packing_list_level
*copyc rac$pacs_processor_version
*copyc fst$path
*copyc rat$installation_control_record
*copyc rat$packing_list_sequence
*copyc rat$sequence_descriptor_types
?? POP ??
*copyc amp$get_segment_pointer
*copyc clp$trimmed_string_size
*copyc fsp$close_file
*copyc fsp$open_file
*copyc osp$establish_block_exit_hndlr
*copyc osp$disestablish_cond_handler
?? OLDTITLE ??
?? NEWTITLE := '[XDCL] rap$open_packing_list_using_icr', EJECT ??

{ PURPOSE:
{   This interface opens the packing list specified by the installation
{   control record.
{
{ DESIGN:
{   The packing list is expected to reside in the installation database as
{   defined by the installation control record.  The file is opened and a
{   pointer to the packing list sequence is registered in the installation
{   control record.
{
{   A boolean declaring when the packing list is open and the file
{   identifier are returned.
{
{ NOTES:
{

  PROCEDURE [XDCL] rap$open_packing_list_using_icr
    (VAR installation_control_record {input, output} : rat$installation_control_record;
     VAR packing_list_fid: amt$file_identifier;
     VAR file_opened: boolean;
     VAR status: ost$status);


    VAR
      attachment_options: array [1 .. 3] of fst$attachment_option,
      ignore_status: ost$status,
      length: integer,
      packing_list_path: fst$path,
      segment_pointer: amt$segment_pointer;


?? NEWTITLE := 'abort_handler', EJECT ??

{ PURPOSE:
{   This procedure cleans up when an abort situation occurs within the
{   block structure.
{
{ DESIGN:
{   The function of this condition handler is to close the packing list
{   file when an abort condition arises.
{
{ NOTES:
{

    PROCEDURE abort_handler
      (    condition: pmt$condition;
           condition_information: ^pmt$condition_information;
           save_area: ^ost$stack_frame_save_area;
       VAR handler_status: ost$status);

      VAR
        ignore_status: ost$status;

      fsp$close_file (packing_list_fid, ignore_status);

    PROCEND abort_handler;

?? OLDTITLE, EJECT ??

    status.normal := TRUE;

    attachment_options [1].selector := fsc$access_and_share_modes;
    attachment_options [1].access_modes.selector := fsc$specific_access_modes;
    attachment_options [1].access_modes.value := $fst$file_access_options [fsc$read];
    attachment_options [1].share_modes.selector := fsc$determine_from_access_modes;
    attachment_options [2].selector := fsc$create_file;
    attachment_options [2].create_file := FALSE;
    attachment_options [3].selector := fsc$wait_for_attachment;
    attachment_options [3].wait_for_attachment.wait := osc$wait;
    attachment_options [3].wait_for_attachment.wait_time := fsc$longest_wait_time;

{  Assemble the path to the packing list using the installation database path and the packing list name. }

    STRINGREP (packing_list_path, length, installation_control_record.processing_header_p^.
          installation_defaults.installation_database.path (1,
          installation_control_record.processing_header_p^.installation_defaults.installation_database.size),
          '.', installation_control_record.processing_header_p^.
          packing_list_name (1, clp$trimmed_string_size (installation_control_record.processing_header_p^.
          packing_list_name)));

    osp$establish_block_exit_hndlr (^abort_handler);

  /main/
    BEGIN

      file_opened := TRUE;
      fsp$open_file (packing_list_path (1, length), amc$segment, ^attachment_options, NIL, NIL, NIL, NIL,
            packing_list_fid, status);
      IF NOT status.normal THEN
        file_opened := FALSE;
        EXIT /main/;
      IFEND;

      amp$get_segment_pointer (packing_list_fid, amc$sequence_pointer, segment_pointer, status);
      IF NOT status.normal THEN
        EXIT /main/;
      IFEND;

      installation_control_record.packing_list_pointers.sequence_p := segment_pointer.sequence_pointer;

    END /main/;

    IF NOT status.normal AND file_opened THEN
      fsp$close_file (packing_list_fid, ignore_status);
      file_opened := FALSE;
    IFEND;

    osp$disestablish_cond_handler;

  PROCEND rap$open_packing_list_using_icr;

MODEND ram$open_packing_list_using_icr;
