
{
{ The access modes are passed in by the parameter, file_access_modes.
{ Share mode and open share mode are always set to (read, execute).
{ Create file attachment option is always set to FALSE.
{

  PROCEDURE [INLINE] clp$open_command_file
    (    file_reference: fst$file_reference;
*IF NOT $true(osv$unix)
         job_mode: jmt$job_mode;
*IFEND
         access_level: amc$record .. amc$segment;
         file_access_modes: clt$command_file_access_modes;
         attribute_validation: ^fst$file_cycle_attributes;
*IF NOT $true(osv$unix)
         allowed_device_classes: fst$device_classes;
*IFEND
     VAR file_id: amt$file_identifier;
     VAR sequence: ^SEQ ( * );
     VAR status: ost$status);

?? PUSH (LISTEXT := ON) ??

    VAR
*IF NOT $true(osv$unix)
      file_creation_attributes: array [1 .. 1] of fst$file_cycle_attribute,
      creation_attributes: ^fst$file_cycle_attributes,
      file_attr_override: array [1 .. 2] of fst$file_cycle_attribute,
      attribute_override: ^fst$file_cycle_attributes,
*IFEND
      file_attachment: ^fst$attachment_options,
      number_of_file_access_modes: integer,
      attachment_index: integer,
*IF NOT $true(osv$unix)
      segment: amt$segment_pointer,
*IFEND
      ignore_status: ost$status;

    status.normal := TRUE;


*IF NOT $true(osv$unix)
{ The second selector for file_attr_override is determined later.

    IF access_level = amc$record THEN
      file_attr_override [1].selector := fsc$file_organization;
      file_attr_override [1].file_organization := amc$byte_addressable;
      attribute_override := ^file_attr_override;
    ELSE
      attribute_override := NIL;
    IFEND;
*IFEND

    number_of_file_access_modes := UPPERBOUND (file_access_modes);
    PUSH file_attachment: [1 .. (number_of_file_access_modes + 5)];

    FOR attachment_index := 1 TO number_of_file_access_modes DO
      IF file_access_modes [attachment_index] = $fst$file_access_options
            [] THEN
        file_attachment^ [attachment_index].selector :=
              fsc$null_attachment_option;
      ELSE
        file_attachment^ [attachment_index].selector :=
              fsc$access_and_share_modes;
        file_attachment^ [attachment_index].access_modes.selector :=
              fsc$specific_access_modes;
        file_attachment^ [attachment_index].access_modes.value :=
              file_access_modes [attachment_index];
        file_attachment^ [attachment_index].share_modes.selector :=
              fsc$specific_share_modes;
        file_attachment^ [attachment_index].share_modes.value :=
              $fst$file_access_options [fsc$read, fsc$execute];
      IFEND;
    FOREND;

    attachment_index := number_of_file_access_modes + 1;
    file_attachment^ [attachment_index].selector := fsc$create_file;
    file_attachment^ [attachment_index].create_file := FALSE;
    attachment_index := attachment_index + 1;
    file_attachment^ [attachment_index].selector := fsc$open_share_modes;
    file_attachment^ [attachment_index].open_share_modes :=
          $fst$file_access_options [fsc$read, fsc$execute];
    attachment_index := attachment_index + 1;

*IF NOT $true(osv$unix)
    IF file_reference = clv$standard_files [clc$sf_command_file].
          path_handle_name THEN
      IF job_mode = jmc$batch THEN
        file_attr_override [2].selector := fsc$ring_attributes;
        file_attr_override [2].ring_attributes.r1 := osc$tsrv_ring;
        file_attr_override [2].ring_attributes.r2 := osc$user_ring_2;
        file_attr_override [2].ring_attributes.r3 := osc$user_ring_2;
        creation_attributes := NIL;
      ELSE
        file_creation_attributes [1].selector := fsc$ring_attributes;
        file_creation_attributes [1].ring_attributes.r1 := osc$user_ring_2;
        file_creation_attributes [1].ring_attributes.r2 := osc$user_ring_2;
        file_creation_attributes [1].ring_attributes.r3 := osc$user_ring_2;
        creation_attributes := ^file_creation_attributes;
        file_attr_override [2].selector := fsc$null_attribute;
      IFEND;

      file_attachment^ [attachment_index].selector := fsc$open_position;
      file_attachment^ [attachment_index].open_position :=
            amc$open_no_positioning;
      attachment_index := attachment_index + 1;

{  Attaching COMMAND without private_read prevents coordination
{  problems when more than 1 include_file of COMMAND is active
{  at the same time.

      file_attachment^ [attachment_index].selector := fsc$private_read;
      file_attachment^ [attachment_index].private_read := FALSE;
      attachment_index := attachment_index + 1;

    ELSE
      creation_attributes := NIL;
      file_attr_override [2].selector := fsc$null_attribute;
*IFEND
      file_attachment^ [attachment_index].selector :=
            fsc$null_attachment_option;
      attachment_index := attachment_index + 1;
      file_attachment^ [attachment_index].selector := fsc$null_attachment_option;
      attachment_index := attachment_index + 1;
*IF NOT $true(osv$unix)
    IFEND;

    file_attachment^ [attachment_index].selector := fsc$allowed_device_classes;
    file_attachment^ [attachment_index].allowed_device_classes := allowed_device_classes;
*ELSE
    file_attachment^ [attachment_index].selector := fsc$null_attachment_option;
*IFEND

  /open_command_file/
    BEGIN
      fsp$open_file (file_reference, access_level, file_attachment,
*IF NOT $true(osv$unix)
            creation_attributes, NIL, attribute_validation, attribute_override,
*IFEND
            file_id, status);
      IF NOT status.normal THEN
*IF NOT $true(osv$unix)
        CASE status.condition OF
        = ame$no_permission_for_access, fse$redundant_attach_conflict,
          fse$concurrent_access_conflict, pfe$usage_not_permitted =
          osp$set_status_abnormal ('CL', cle$command_file_not_executable, '', status);
          osp$append_status_file (osc$status_parameter_delimiter, file_reference, status);
        = ame$ring_validation_error =
          osp$set_status_abnormal ('CL', cle$command_file_not_callable, '', status);
          osp$append_status_file (osc$status_parameter_delimiter, file_reference, status);
        ELSE
          ;
        CASEND;
*IFEND
        EXIT /open_command_file/;
      IFEND;

*IF NOT $true(osv$unix)
      IF access_level = amc$segment THEN
        amp$get_segment_pointer (file_id, amc$sequence_pointer, segment,
              status);
        IF NOT status.normal THEN
          fsp$close_file (file_id, ignore_status);
          EXIT /open_command_file/;
        IFEND;
        sequence := segment.sequence_pointer;
      ELSE
*IFEND
        sequence := NIL;
*IF NOT $true(osv$unix)
      IFEND;
*IFEND
    END /open_command_file/;

  PROCEND clp$open_command_file;

*copyc amt$file_identifier
*copyc fst$file_reference
*copyc clc$standard_file_names
*copyc cle$ecc_command_processing
*IF NOT $true(osv$unix)
*copyc clk$procedure_keypoints
*IFEND
*copyc clt$command_file_access_modes
*IF NOT $true(osv$unix)
*copyc fst$device_classes
*IFEND
*copyc fst$file_cycle_attributes
*IF NOT $true(osv$unix)
*copyc jmt$job_mode
*IFEND
*copyc ost$status
?? POP ??
*IF NOT $true(osv$unix)
*copyc amp$get_segment_pointer
*copyc clv$standard_files
*IFEND
*copyc fsp$close_file
*copyc fsp$open_file
*IF NOT $true(osv$unix)
*copyc osp$append_status_file
*IFEND
*copyc osp$set_status_abnormal
