*copyc OSD$DEFAULT_PRAGMATS
MODULE iim$fetch_terminal;
?? TITLE := 'MODULE iim$fetch_terminal' ??

?? PUSH (LISTEXT := ON) ??
*copyc IFE$ERROR_CODES
*copyc ift$get_connection_attributes
*copyc IIT$CONNECTION_DESCRIPTION
*copyc IIV$INTERACTIVE_TERMINATED
*copyc IIP$UPDATE_OPEN_DESC_ATTRIBUTES
*copyc OST$STATUS
*copyc OSP$APPEND_STATUS_INTEGER
*copyc OSP$APPEND_STATUS_PARAMETER
*copyc OSP$SET_STATUS_ABNORMAL
*copyc PMP$GET_JOB_MODE
*copyc jmp$system_job
?? POP ??

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

  PROCEDURE [XDCL, #GATE] iip$fetch_terminal (file_id: amt$file_identifier;
    open_file_desc_pointer: ^iit$open_file_description;
    terminal_attributes: ^ift$get_connection_attributes;
    VAR status: ost$status);

    VAR
      get_all_attributes: iit$connection_attributes,
      set_of_terminal_attribute_keys: iit$set_of_term_conn_attr_keys,
      i: integer,
      j: ift$connection_attribute_keys,
      k: integer,
      job_mode: jmt$job_mode,
      local_status: ost$status;

    status.normal := TRUE;

{ Verify that this is an interactive job.

    pmp$get_job_mode (job_mode, local_status);
    IF NOT local_status.normal THEN
      status := local_status;
      RETURN;
    ELSEIF NOT jmp$system_job () THEN
      IF NOT (job_mode IN $iit$job_modes [jmc$interactive_connected,
            jmc$interactive_cmnd_disconnect, jmc$interactive_line_disconnect,
            jmc$interactive_sys_disconnect]) THEN
        osp$set_status_abnormal (ifc$interactive_facility_id,
              ife$current_job_not_interactive, 'IFP$FETCH_TERMINAL', status);
        RETURN;
      IFEND;
    IFEND;

{ Validate the terminal attribute keys.

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

{ Update the terminal attributes for the file id if they might have changed.

    IF open_file_desc_pointer^.attributes_cycle <> open_file_desc_pointer^.
      connection_desc_pointer^.attributes_cycle THEN
      iip$update_open_desc_attributes (file_id, open_file_desc_pointer,
            ifc$fetch_terminal_req, local_status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;
    IFEND;

    IF NOT iiv$cdcnet_connection THEN
    { For those attributes which are ignored in dual state 255x connections,
    { replace their keys in terminal_attributes with ifc$null_connection_attribute.

      FOR i := 1 TO UPPERBOUND (terminal_attributes^) DO
        CASE terminal_attributes^ [i].key OF
        = ifc$trans_protocol_mode =
          terminal_attributes^ [i].key := ifc$null_connection_attribute;

        ELSE
        { All other attributes will have their values returned.
        CASEND;

      FOREND;
    IFEND;

{ Get the terminal attributes for the file id.

    FOR i := 1 TO UPPERBOUND (terminal_attributes^) DO
      CASE terminal_attributes^ [i].key OF
      = ifc$attention_character_action =
        terminal_attributes^ [i].attention_character_action := open_file_desc_pointer^.
              attributes.attention_character_action.value;
      = ifc$break_key_action =
        terminal_attributes^ [i].break_key_action := open_file_desc_pointer^.
              attributes.break_key_action.value;
      = ifc$end_of_information =
        terminal_attributes^ [i].end_of_information := open_file_desc_pointer^.
              attributes.end_of_information.value;
      = ifc$input_block_size =
        terminal_attributes^ [i].input_block_size := open_file_desc_pointer^.
              attributes.input_block_size.value;
      = ifc$input_editing_mode =
        terminal_attributes^ [i].input_editing_mode := open_file_desc_pointer^.
              attributes.input_editing_mode.value;
      = ifc$input_output_mode =
        terminal_attributes^ [i].input_output_mode := open_file_desc_pointer^.
              attributes.input_output_mode.value;
      = ifc$input_timeout =
        terminal_attributes^ [i].input_timeout := open_file_desc_pointer^.
              attributes.input_timeout.value;
      = ifc$input_timeout_length =
        terminal_attributes^ [i].input_timeout_length := open_file_desc_pointer^.
              attributes.input_timeout_length.value;
      = ifc$input_timeout_purge =
        terminal_attributes^ [i].input_timeout_purge := open_file_desc_pointer^.
              attributes.input_timeout_purge.value;
      = ifc$partial_char_forwarding =
        terminal_attributes^ [i].partial_character_forwarding := open_file_desc_pointer^.
              attributes.partial_char_forwarding.value;
      = ifc$prompt_file =
        terminal_attributes^ [i].prompt_file := open_file_desc_pointer^.
              attributes.prompt_file.value;
      = ifc$prompt_file_identifier =
        terminal_attributes^ [i].prompt_file_identifier := open_file_desc_pointer^.
              attributes.prompt_file_identifier.value;
      = ifc$prompt_string =
        terminal_attributes^ [i].prompt_string := open_file_desc_pointer^.
              attributes.prompt_string.value;
      = ifc$store_backspace_character =
        terminal_attributes^ [i].store_backspace_character := open_file_desc_pointer^.
              attributes.store_backspace_character.value;
      = ifc$store_nuls_dels =
        terminal_attributes^ [i].store_nuls_dels := open_file_desc_pointer^.
              attributes.store_nuls_dels.value;
      = ifc$trans_character_mode =
        terminal_attributes^ [i].trans_character_mode := open_file_desc_pointer^.
              attributes.trans_character_mode.value;
      = ifc$trans_forward_character =
        terminal_attributes^ [i].trans_forward_character := open_file_desc_pointer^.
              attributes.trans_forward_character.value;
      = ifc$trans_length_mode =
        terminal_attributes^ [i].trans_length_mode := open_file_desc_pointer^.
              attributes.trans_length_mode.value;
      = ifc$trans_timeout_mode =
        terminal_attributes^ [i].trans_timeout_mode := open_file_desc_pointer^.
              attributes.trans_timeout_mode.value;
      = ifc$trans_message_length =
        terminal_attributes^ [i].trans_message_length := open_file_desc_pointer^.
              attributes.trans_message_length.value;
      = ifc$trans_terminate_character =
        terminal_attributes^ [i].trans_terminate_character := open_file_desc_pointer^.
              attributes.trans_terminate_character.value;

      = ifc$trans_protocol_mode =
        terminal_attributes^ [i].trans_protocol_mode := open_file_desc_pointer^.
              attributes.trans_protocol_mode.value;
      ELSE
      CASEND;
    FOREND;

  PROCEND iip$fetch_terminal;

MODEND iim$fetch_terminal;
