?? NEWTITLE := 'NOSVE Basic Access Method : Validate Attachments' ??
MODULE fsm$validate_attachments;
?? RIGHT := 110 ??

?? NEWTITLE := 'Global Declarations', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc fsc$longest_wait_time
*copyc ame$attribute_validation_errors
*copyc clt$file
*copyc fst$attachment_options
*copyc fst$file_reference
*copyc fst$status_reporting_procedure
?? POP ??
*copyc clp$convert_string_to_file_ref
*copyc clp$only_validate_name
*copyc osp$append_status_integer
*copyc osp$append_status_parameter
*copyc osp$set_status_abnormal
*copyc pmp$change_legible_date_format
*copyc rmp$validate_ansi_string
*copyc amv$message_control

?? TITLE := '[XDCL] fsv$attachment_names', EJECT ??

  VAR
    fsv$attachment_names: [XDCL, READ, oss$job_paged_literal] ^array [1 .. * ] of ost$name :=
          ^attachment_names,

    attachment_names: [STATIC, READ, oss$job_paged_literal] array
          [fsc$access_and_share_modes .. fsc$allowed_device_classes] of ost$name := [

{fsc$access_and_share_modes .... = 001} 'ACCESS_AND_SHARE_MODES       ',
{fsc$allowed_exceptions ........ = 002} 'ALLOWED_EXCEPTIONS           ',
{fsc$create_file ............... = 003} 'CREATE_FILE                  ',
{fsc$delete_data ............... = 004} 'DELETE_DATA                  ',
{fsc$error_exit_procedure ...... = 005} 'ERROR_EXIT_PROCEDURE         ',
{fsc$error_exit_procedure_name . = 006} 'ERROR_EXIT_PROCEDURE_NAME    ',
{fsc$error_limit ............... = 007} 'ERROR_LIMIT                  ',
{fsc$explicit_detach_allowed ... = 008} 'EXPLICIT_DETACH_ALLOWED      ',
{fsc$file_server_options ....... = 009} 'FILE_SERVER_OPTIONS          ',
{fsc$hide_attachment ........... = 010} 'HIDE_ATTACHMENT              ',
{fsc$label_exit_procedure ...... = 011} 'LABEL_EXIT_PROCEDURE         ',
{fsc$label_exit_procedure_name . = 012} 'LABEL_EXIT_PROCEDURE_NAME    ',
{fsc$message_control ........... = 013} 'MESSAGE_CONTROL              ',
{fsc$null_attachment_option .... = 014} 'NULL_ATTACHMENT_OPTION       ',
{fsc$open_position ............. = 015} 'OPEN_POSITION                ',
{fsc$open_share_modes .......... = 016} 'OPEN_SHARE_MODES             ',
{fsc$password .................. = 017} 'PASSWORD                     ',
{fsc$private_read .............. = 018} 'PRIVATE_READ                 ',
{fsc$scope ..................... = 019} 'SCOPE                        ',
{fsc$sequential_access ......... = 020} 'SEQUENTIAL_ACCESS            ',
{fsc$tape_attachment ........... = 021} 'TAPE_ATTACHMENT              ',
{fsc$tape_error_options ........ = 022} 'TAPE_ERROR_OPTIONS           ',
{fsc$transfer_size ............. = 023} 'TRANSFER_SIZE                ',
{fsc$validation_ring ........... = 024} 'VALIDATION_RING              ',
{fsc$wait_for_attachment ....... = 025} 'WAIT_FOR_ATTACHMENT          ',
{fsc$free_behind ............... = 026} 'FREE_BEHIND                  ',
{fsc$exception_detection........ = 027} 'EXCEPTION_DETECTION          ',
{fsc$allowed_device_classes..... = 028} 'ALLOWED_DEVICE_CLASSES       '];

?? TITLE := '[XDCL] fsp$validate_attachments', EJECT ??

  PROCEDURE [XDCL] fsp$validate_attachments
    (    attachments: ^fst$attachment_options;
         status_reporting_procedure_ptr: fst$status_reporting_procedure;
     VAR status: ost$status);

    VAR
      fsv$allowed_device_classes: [STATIC, READ, oss$job_paged_literal] fst$device_classes :=
            -$fst$device_classes [],
      fsv$file_access_options: [STATIC, READ, oss$job_paged_literal] fst$file_access_options :=
            [fsc$execute, fsc$read, fsc$append, fsc$modify, fsc$shorten],
      fsv$cycle_damage_symptoms: [STATIC, READ, oss$job_paged_literal] fst$cycle_damage_symptoms :=
            -$fst$cycle_damage_symptoms [],
      fsv$file_access_conditions: [STATIC, READ, oss$job_paged_literal] fst$file_access_conditions :=
            -$fst$file_access_conditions [];

    VAR
      attachment_p: ^fst$attachment_option,
      attachment_key_is_good: boolean,
      attachment_value_is_good: boolean,
      i: integer,
      ignore_file: fst$parsed_file_reference;

    status.normal := TRUE;
    IF attachments = NIL THEN
      RETURN; {----->
    IFEND;

    FOR i := 1 TO UPPERBOUND (attachments^) DO
      attachment_key_is_good := TRUE;
      attachment_value_is_good := TRUE;
      attachment_p := ^attachments^ [i];

      CASE attachment_p^.selector OF
      = fsc$access_and_share_modes =
        IF (attachment_p^.access_modes.selector < LOWERVALUE (fst$access_mode_choices)) OR
              (attachment_p^.access_modes.selector > UPPERVALUE (fst$access_mode_choices)) THEN
          attachment_value_is_good := FALSE;
        ELSE
          IF attachment_p^.access_modes.selector = fsc$specific_access_modes THEN
            attachment_value_is_good := (attachment_p^.access_modes.value <= fsv$file_access_options) AND
                  (attachment_p^.access_modes.value <> $fst$file_access_options []);
          IFEND;
        IFEND;
        IF (attachment_p^.share_modes.selector < LOWERVALUE (fst$share_mode_choices)) OR
              (attachment_p^.share_modes.selector > UPPERVALUE (fst$share_mode_choices)) THEN
          attachment_value_is_good := FALSE;
        ELSE
          IF attachment_p^.share_modes.selector = fsc$specific_share_modes THEN
            attachment_value_is_good := (attachment_p^.share_modes.value <= fsv$file_access_options);
          IFEND;
        IFEND;
      = fsc$allowed_device_classes =
        attachment_value_is_good := (attachment_p^.allowed_device_classes <= fsv$allowed_device_classes);
      = fsc$allowed_exceptions =
        attachment_value_is_good := (attachment_p^.allowed_exceptions.access_conditions <=
              fsv$file_access_conditions) AND (attachment_p^.allowed_exceptions.damage_symptoms <=
              fsv$cycle_damage_symptoms);
      = fsc$exception_detection =
        attachment_value_is_good := (attachment_p^.exception_detection <= fsv$cycle_damage_symptoms);
      = fsc$tape_attachment =
        attachment_key_is_good := f$valid_tape_attachment (attachment_p^.tape_attachment);
      = fsc$create_file =
        attachment_value_is_good := (attachment_p^.create_file >= LOWERVALUE (boolean)) AND
              (attachment_p^.create_file <= UPPERVALUE (boolean));
      = fsc$delete_data =
        attachment_value_is_good := (attachment_p^.delete_data >= LOWERVALUE (boolean)) AND
              (attachment_p^.delete_data <= UPPERVALUE (boolean));
      = fsc$error_exit_procedure =
        ;
      = fsc$error_exit_procedure_name =
        IF attachment_p^.error_exit_procedure_name <> NIL THEN
          IF attachment_p^.error_exit_procedure_name^.entry_point <> osc$null_name THEN
            clp$only_validate_name (attachment_p^.error_exit_procedure_name^.entry_point,
                  attachment_value_is_good);
            IF attachment_p^.error_exit_procedure_name^.object_library <> osc$null_name THEN
              clp$convert_string_to_file_ref (attachment_p^.error_exit_procedure_name^.object_library,
                    ignore_file, status);
              attachment_value_is_good := status.normal;
            IFEND;
          IFEND;
        IFEND;
      = fsc$error_limit =
        attachment_value_is_good := (attachment_p^.error_limit >= LOWERVALUE (amt$error_limit)) AND
              (attachment_p^.error_limit <= UPPERVALUE (amt$error_limit));
      = fsc$explicit_detach_allowed =
        ;
      = fsc$free_behind =
        ;
      = fsc$hide_attachment =
        ;
      = fsc$label_exit_procedure =
        ;
      = fsc$label_exit_procedure_name =
        IF attachment_p^.label_exit_procedure_name <> NIL THEN
          IF attachment_p^.label_exit_procedure_name^.entry_point <> osc$null_name THEN
            clp$only_validate_name (attachment_p^.label_exit_procedure_name^.entry_point,
                  attachment_value_is_good);
            IF attachment_p^.label_exit_procedure_name^.object_library <> osc$null_name THEN
              clp$convert_string_to_file_ref (attachment_p^.label_exit_procedure_name^.object_library,
                    ignore_file, status);
              attachment_value_is_good := status.normal;
            IFEND;
          IFEND;
        IFEND;
      = fsc$message_control =
        attachment_value_is_good := (attachment_p^.message_control <= amv$message_control);
      = fsc$null_attachment_option =
        ;
      = fsc$open_position =
        attachment_value_is_good := (attachment_p^.open_position >= LOWERVALUE (amt$open_position)) AND
              (attachment_p^.open_position <= UPPERVALUE (amt$open_position));
      = fsc$open_share_modes =
        attachment_value_is_good := (attachment_p^.open_share_modes <= fsv$file_access_options);
      = fsc$password =
        IF attachment_p^.password <> osc$null_name THEN
          clp$only_validate_name (attachment_p^.password, attachment_value_is_good);
        IFEND;
      = fsc$private_read =
        ;
      = fsc$scope =
        ;
      = fsc$sequential_access =
        ;
      = fsc$tape_error_options =
        IF (attachment_p^.tape_error_options.error_action < LOWERVALUE (amt$tape_error_action)) OR
              (attachment_p^.tape_error_options.error_action > UPPERVALUE (amt$tape_error_action)) THEN
          attachment_value_is_good := FALSE;
        ELSE
          attachment_value_is_good := (attachment_p^.tape_error_options.perform_failure_recovery >=
                LOWERVALUE (boolean)) AND (attachment_p^.tape_error_options.
                perform_failure_recovery <= UPPERVALUE (boolean))
        IFEND;
      = fsc$transfer_size =
        attachment_value_is_good := (attachment_p^.transfer_size >= LOWERVALUE (fst$transfer_size)) AND
              (attachment_p^.transfer_size <= UPPERVALUE (fst$transfer_size));
      = fsc$validation_ring =
        attachment_value_is_good := (attachment_p^.validation_ring >= LOWERVALUE (ost$ring)) AND
              (attachment_p^.validation_ring <= UPPERVALUE (ost$ring));
      = fsc$wait_for_attachment =
        IF (attachment_p^.wait_for_attachment.wait < LOWERVALUE (ost$wait)) OR
              (attachment_p^.wait_for_attachment.wait > UPPERVALUE (ost$wait)) THEN
          attachment_value_is_good := FALSE;
        ELSE
          IF attachment_p^.wait_for_attachment.wait = osc$wait THEN
            attachment_value_is_good := (attachment_p^.wait_for_attachment.wait_time >= 0) AND
                  (attachment_p^.wait_for_attachment.wait_time <= fsc$longest_wait_time);
          IFEND;
        IFEND;

      ELSE
        attachment_key_is_good := FALSE;
      CASEND;

      IF NOT attachment_key_is_good THEN
        IF status.normal OR (status.condition <> ame$improper_file_attrib_key) THEN
          status_reporting_procedure_ptr^ (ame$improper_file_attrib_key, 'FILE_ATTACHMENT', status);
          osp$append_status_integer (osc$status_parameter_delimiter, i, 10, FALSE, status);
        ELSE
          osp$append_status_integer (',', i, 10, FALSE, status);
        IFEND;
      ELSEIF NOT attachment_value_is_good THEN
        IF status.normal THEN
          status_reporting_procedure_ptr^ (ame$improper_file_attrib_value, 'FILE_ATTACHMENT', status);
          osp$append_status_parameter (osc$status_parameter_delimiter,
                fsv$attachment_names^ [attachment_p^.selector], status);
        ELSEIF status.condition = ame$improper_file_attrib_value THEN
          osp$append_status_parameter (',', fsv$attachment_names^ [attachment_p^.selector], status);
        IFEND;
      IFEND;
    FOREND;

  PROCEND fsp$validate_attachments;
?? TITLE := '[inline] fsp$validate_tape_attachment', EJECT ??
*if false

  PROCEDURE [INLINE] fsp$validate_tape_attachment
    (    tape_attachment: fst$tape_attachment;
     VAR attachment_key_is_good: boolean);

    CASE tape_attachment.selector OF
    = fsc$tape_block_type, fsc$tape_buffer_offset, fsc$tape_character_conversion, fsc$tape_character_set,
          fsc$tape_creation_date, fsc$tape_expiration_date, fsc$tape_file_accessibility,
          fsc$tape_file_identifier, fsc$tape_file_sequence_number, fsc$tape_file_set_identifier,
          fsc$tape_file_set_position, fsc$tape_generation_number, fsc$tape_generation_version_num,
          fsc$tape_implementation_id, fsc$tape_label_standard_version, fsc$tape_max_block_length,
          fsc$tape_max_record_length, fsc$tape_owner_identification, fsc$tape_padding_character,
          fsc$tape_record_type, fsc$tape_removable_media_group, fsc$tape_rewrite_labels,
          fsc$tape_volume_accessibility, fsc$tape_header_labels, fsc$tape_trailer_labels,
          fsc$tape_file_section_number, fsc$tape_block_count, fsc$tape_volume_initialization,
          fsc$tape_null_attachment_option =
      attachment_key_is_good := TRUE;

    ELSE
      attachment_key_is_good := FALSE;
    CASEND;

  PROCEND fsp$validate_tape_attachment;
*else

  FUNCTION [INLINE] f$valid_tape_attachment
    (    tape_attachment: fst$tape_attachment): boolean;

    CONST
      fsc$min_tape_attachment_choice = fsc$tape_block_type,
      fsc$max_tape_attachment_choice = fsc$tape_volume_initialization;

    f$valid_tape_attachment := (tape_attachment.selector >= fsc$min_tape_attachment_choice) AND
          (tape_attachment.selector <= fsc$max_tape_attachment_choice);

  FUNCEND f$valid_tape_attachment;
*ifend
?? OLDTITLE ??
MODEND fsm$validate_attachments;

