*copyc OSD$DEFAULT_PRAGMATS
MODULE iim$get_term_conn_attributes;

{ PURPOSE: This module provides the ring 2 interface which gets
{          the default connection attributes for a particular file.
{          The returned values are the values which will be in
{          effect for subsequent instances-of-open of the file.

{  DESIGN: The values for the requested attributes are obtained from
{          the Local Name Table (LNT) entry for the named file.  The
{          attributes in this entry may have been set by the commands
{          REQT, CHATCA, or CHATCD or by their program interfaces
{          IFP$CHANGE_TERM_CONN_ATTRIBUTES, RMP$REQUEST_TERMINAL, or
{          IFP$CHANGE_TERM_CONN_DEFAULTS.  If a requested attribute
{          has not been set by either of these interfaces then the
{          value returned for it is the value it defaults to at login.
{
{          Authored by V.L. Richardson on 2/18/86.

?? TITLE := 'MODULE iim$get_term_conn_attributes' ??

?? PUSH (LISTEXT := ON) ??
*copyc FMP$GET_TERMINAL_ATTRIBUTES
*copyc CLP$GET_ULTIMATE_CONNECTION
*copyc CLP$VALIDATE_NAME
*copyc CLV$STANDARD_FILES
*copyc IFE$ERROR_CODES
*copyc IIK$KEYPOINTS
*copyc IIV$CONNECTION_DESC_PTR
*copyc IIV$INTERACTIVE_TERMINATED
*copyc OSP$APPEND_STATUS_INTEGER
*copyc OSP$APPEND_STATUS_PARAMETER
*copyc OSP$SET_STATUS_ABNORMAL
*copyc PMP$GET_JOB_MODE
*copyc RMP$GET_DEVICE_CLASS
?? POP ??

?? NEWTITLE := 'PROCEDURE iip$get_term_conn_attributes', EJECT ??

  PROCEDURE [XDCL, #GATE] iip$get_term_conn_attributes (local_file_name:
    amt$local_file_name;
    VAR connection_attributes: ift$get_connection_attributes;
    VAR status: ost$status);

    VAR
      converted_name: ost$name,
      default_term_attributes_ptr: ^ift$get_connection_attributes,
      device_assigned: boolean,
      device_class: rmt$device_class,
      i: integer,
      job_mode: jmt$job_mode,
      k: integer,
      local_status: ost$status,
      set_of_term_conn_attr_keys: iit$set_of_term_conn_attr_keys,
      ultimate_name: ost$name,
      valid_name: boolean;

    status.normal := TRUE;

  { Convert and validate the file name.

    clp$validate_name (local_file_name, converted_name, valid_name);
    IF NOT valid_name THEN
      osp$set_status_abnormal (ifc$interactive_facility_id,
            ife$file_name_ill_formed, local_file_name, status);
      osp$append_status_parameter (osc$status_parameter_delimiter,
        'IFP$GET_TERM_CONN_ATTRIBUTES', status);
      RETURN;
    IFEND;

  { Verify that the file is assigned to a terminal device.

    rmp$get_device_class (converted_name, device_assigned, device_class,
          local_status);
    IF NOT local_status.normal THEN
      status := local_status;
      RETURN;
    ELSE
      IF (device_class <> rmc$terminal_device) AND (device_class <> rmc$network_device) THEN
        clp$get_ultimate_connection (local_file_name, ultimate_name, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;

        pmp$get_job_mode (job_mode, local_status);
        IF NOT local_status.normal THEN
          status := local_status;
          RETURN;
        ELSEIF (NOT (job_mode IN $iit$job_modes [jmc$interactive_connected,
               jmc$interactive_cmnd_disconnect, jmc$interactive_line_disconnect,
               jmc$interactive_sys_disconnect]) AND
               (((ultimate_name = clv$standard_files [clc$sf_job_input_file].path_handle_name) OR
               (ultimate_name = clv$standard_files [clc$sf_job_output_file].path_handle_name)) OR
               (ultimate_name = clv$standard_files [clc$sf_command_file].path_handle_name))) THEN
          osp$set_status_abnormal (ifc$interactive_facility_id,
               ife$current_job_not_interactive, 'IFP$GET_TERM_CONN_ATTRIBUTES',
               status);
          RETURN;
        ELSE
          osp$set_status_abnormal (ifc$interactive_facility_id,
                ife$file_name_not_terminal, converted_name, status);
          osp$append_status_parameter (osc$status_parameter_delimiter,
            'IFP$GET_TERM_CONN_ATTRIBUTES', status);
          RETURN;
        IFEND;
      IFEND;
    IFEND;

  { Validate the attribute keys.

    set_of_term_conn_attr_keys := - $iit$set_of_term_conn_attr_keys [];
    FOR i := LOWERBOUND (connection_attributes) TO UPPERBOUND
          (connection_attributes) DO
      IF NOT (connection_attributes [i].key IN set_of_term_conn_attr_keys)
            THEN
        osp$set_status_abnormal (ifc$interactive_facility_id,
              ife$unknown_attribute_key, '', status);
        k := ORD (connection_attributes [i].key);
        osp$append_status_integer (osc$status_parameter_delimiter, k, 10,
              FALSE, status);
        osp$append_status_parameter (osc$status_parameter_delimiter,
          'IFP$GET_TERM_CONN_ATTRIBUTES', status);
        RETURN;
      IFEND;
    FOREND;

  { Get the requested attribute values from BAM's LNT.

    fmp$get_terminal_attributes (converted_name, connection_attributes, local_status);

  { Return the requested attribute values from the LNT if found there,
  { or from the set of login defaults, if not.

    FOR i := 1 TO UPPERBOUND (connection_attributes) DO
      IF connection_attributes [i].source = ifc$undefined_attribute THEN
        CASE iiv$network_identifier OF
        = iic$cdcnet_network =  { STANDALONE }
          CASE connection_attributes [i].key OF
          = ifc$attention_character_action =
            connection_attributes [i].attention_character_action :=
                  iiv$deflt_connection_attributes.attention_character_action.value;
          = ifc$break_key_action =
            connection_attributes [i].break_key_action :=
                  iiv$deflt_connection_attributes.break_key_action.value;
          = ifc$end_of_information =
            connection_attributes [i].end_of_information :=
                  iiv$deflt_connection_attributes.end_of_information.value;
          = ifc$input_block_size =
            connection_attributes [i].input_block_size :=
                  iiv$deflt_connection_attributes.input_block_size.value;
          = ifc$input_editing_mode =
            connection_attributes [i].input_editing_mode :=
                  iiv$deflt_connection_attributes.input_editing_mode.value;
          = ifc$input_output_mode =
            connection_attributes [i].input_output_mode :=
                  iiv$deflt_connection_attributes.input_output_mode.value;
          = ifc$input_timeout =
            connection_attributes [i].input_timeout :=
                  iiv$deflt_connection_attributes.input_timeout.value;
          = ifc$input_timeout_length =
            connection_attributes [i].input_timeout_length :=
                  iiv$deflt_connection_attributes.input_timeout_length.value;
          = ifc$input_timeout_purge =
            connection_attributes [i].input_timeout_purge :=
                  iiv$deflt_connection_attributes.input_timeout_purge.value;
          = ifc$partial_char_forwarding =
            connection_attributes [i].partial_character_forwarding :=
                  iiv$deflt_connection_attributes.partial_char_forwarding.value;
          = ifc$prompt_file =
            connection_attributes [i].prompt_file :=
                  iiv$deflt_connection_attributes.prompt_file.value;
          = ifc$prompt_file_identifier =
            connection_attributes [i].prompt_file_identifier :=
                  iiv$deflt_connection_attributes.prompt_file_identifier.value;
          = ifc$prompt_string =
            connection_attributes [i].prompt_string :=
                  iiv$deflt_connection_attributes.prompt_string.value;
          = ifc$store_backspace_character =
            connection_attributes [i].store_backspace_character :=
                  iiv$deflt_connection_attributes.store_backspace_character.value;
          = ifc$store_nuls_dels =
            connection_attributes [i].store_nuls_dels :=
                  iiv$deflt_connection_attributes.store_nuls_dels.value;
          = ifc$trans_character_mode =
            connection_attributes [i].trans_character_mode :=
                  iiv$deflt_connection_attributes.trans_character_mode.value;
          = ifc$trans_forward_character =
            connection_attributes [i].trans_forward_character :=
                  iiv$deflt_connection_attributes.trans_forward_character.value;
          = ifc$trans_length_mode =
            connection_attributes [i].trans_length_mode :=
                  iiv$deflt_connection_attributes.trans_length_mode.value;
          = ifc$trans_timeout_mode =
            connection_attributes [i].trans_timeout_mode :=
                  iiv$deflt_connection_attributes.trans_timeout_mode.value;
          = ifc$trans_message_length =
            connection_attributes [i].trans_message_length :=
                  iiv$deflt_connection_attributes.trans_message_length.value;
          = ifc$trans_terminate_character =
            connection_attributes [i].trans_terminate_character :=
                  iiv$deflt_connection_attributes.trans_terminate_character.value;
          = ifc$trans_protocol_mode =
            connection_attributes [i].trans_protocol_mode :=
                  iiv$deflt_connection_attributes.trans_protocol_mode.value;
          ELSE
          CASEND;

        = iic$dsiaf_network =  { DUAL STATE }

          CASE connection_attributes [i].key OF
          = ifc$attention_character_action =
            connection_attributes [i].attention_character_action := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.attention_character_action.value;
          = ifc$break_key_action =
            connection_attributes [i].break_key_action := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.break_key_action.value;
          = ifc$end_of_information =
            connection_attributes [i].end_of_information := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.end_of_information.value;
          = ifc$input_block_size =
            connection_attributes [i].input_block_size := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.input_block_size.value;
          = ifc$input_editing_mode =
            connection_attributes [i].input_editing_mode := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.input_editing_mode.value;
          = ifc$input_output_mode =
            connection_attributes [i].input_output_mode := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.input_output_mode.value;
          = ifc$input_timeout =
            connection_attributes [i].input_timeout := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.input_timeout.value;
          = ifc$input_timeout_length =
            connection_attributes [i].input_timeout_length := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.input_timeout_length.value;
          = ifc$input_timeout_purge =
            connection_attributes [i].input_timeout_purge := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.input_timeout_purge.value;
          = ifc$partial_char_forwarding =
            connection_attributes [i].partial_character_forwarding := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.partial_char_forwarding.value;
          = ifc$prompt_file =
            connection_attributes [i].prompt_file := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.prompt_file.value;
          = ifc$prompt_file_identifier =
            connection_attributes [i].prompt_file_identifier := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.prompt_file_identifier.value;
          = ifc$prompt_string =
            connection_attributes [i].prompt_string := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.prompt_string.value;
          = ifc$store_backspace_character =
            connection_attributes [i].store_backspace_character := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.store_backspace_character.value;
          = ifc$store_nuls_dels =
            connection_attributes [i].store_nuls_dels := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.store_nuls_dels.value;
          = ifc$trans_character_mode =
            connection_attributes [i].trans_character_mode := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.trans_character_mode.value;
          = ifc$trans_forward_character =
            connection_attributes [i].trans_forward_character := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.trans_forward_character.value;
          = ifc$trans_length_mode =
            connection_attributes [i].trans_length_mode := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.trans_length_mode.value;
          = ifc$trans_timeout_mode =
            connection_attributes [i].trans_timeout_mode := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.trans_timeout_mode.value;
          = ifc$trans_message_length =
            connection_attributes [i].trans_message_length := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.trans_message_length.value;
          = ifc$trans_terminate_character =
            connection_attributes [i].trans_terminate_character := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.trans_terminate_character.value;
          = ifc$trans_protocol_mode =
            connection_attributes [i].trans_protocol_mode := iiv$connection_desc_ptr^.
                  nam_os_default_attributes.trans_protocol_mode.value;
          ELSE
          CASEND;

        CASEND;
      IFEND;
    FOREND;


  PROCEND iip$get_term_conn_attributes;
MODEND iim$get_term_conn_attributes;
