*copyc OSD$DEFAULT_PRAGMATS
MODULE ifm$change_terminal_attributes;

{ PURPOSE:  This Ring 3 module calls a Ring 2 interface to change
{           the terminal attributes for a connection.
{
{  DESIGN:  For dual state connections IIM$CHANGE_TERMINAL_ATTRIBUTES
{           is called to change the connection's attributes;  for
{           standalone connections, IIM$ST_CHNG_TERMINAL_ATTRIBUTES.
{
?? TITLE := 'MODULE ifm$change_terminal_attributes' ??

?? PUSH (LISTEXT := ON) ??
*copyc fst$file_reference
*copyc ife$error_codes
*copyc ifk$keypoints
*copyc ift$terminal_attributes
*copyc iip$st_chng_terminal_attributes
*copyc iip$change_terminal_attributes
*copyc iiv$connection_desc_ptr
*copyc iiv$interactive_terminated
*copyc oss$job_paged_literal
?? POP ??

*copyc clp$get_ultimate_connection
*copyc clp$validate_name
*copyc clv$standard_files
*copyc iip$xlate_local_file_to_session
*copyc osp$append_status_parameter
*copyc osp$generate_log_message
*copyc osp$set_status_abnormal
*copyc pmp$get_job_mode
*copyc rmp$get_device_class

?? NEWTITLE := 'PROCEDURE ifp$change_terminal_attributes', EJECT ??
*copyc ifh$change_terminal_attributes

  PROCEDURE [XDCL, #GATE {TS_gate} ] ifp$change_terminal_attributes (terminal_file_name:
    fst$file_reference;
    terminal_attributes: ift$terminal_attributes;
    VAR status: ost$status);

    VAR
      converted_name: ost$name,
      device_assigned: boolean,
      device_class: rmt$device_class,
      i: integer,
      job_mode: jmt$job_mode,
      local_status: ost$status,
      log: [STATIC, READ, oss$job_paged_literal] pmt$ascii_logset := [pmc$job_log],
      message_status: ost$status,
      ultimate_name: amt$local_file_name,
      valid_name: boolean;

    status.normal := TRUE;
    #KEYPOINT (osk$entry, 0, ifk$change_terminal_attributes);

  /change_terminal_attributes/
    BEGIN
      IF STRLENGTH (terminal_file_name) > osc$max_name_size THEN
        osp$set_status_abnormal (ifc$interactive_facility_id,
              ife$file_name_ill_formed, terminal_file_name, status);
        osp$append_status_parameter (osc$status_parameter_delimiter,
          'IFP$CHANGE_TERMINAL_ATTRIBUTES', status);
        EXIT /change_terminal_attributes/;
      IFEND;

      clp$validate_name (terminal_file_name, converted_name, valid_name);
      IF NOT valid_name THEN
        osp$set_status_abnormal (ifc$interactive_facility_id,
              ife$file_name_ill_formed, terminal_file_name, status);
        osp$append_status_parameter (osc$status_parameter_delimiter,
          'IFP$CHANGE_TERMINAL_ATTRIBUTES', status);
        EXIT /change_terminal_attributes/;
      IFEND;

    { Get the name of the file which the terminal file is connected to.

      clp$get_ultimate_connection (converted_name, ultimate_name, status);
      IF NOT status.normal THEN
        EXIT /change_terminal_attributes/;
      IFEND;

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

      rmp$get_device_class (ultimate_name, device_assigned, device_class,
            status);
      IF NOT status.normal THEN
        EXIT /change_terminal_attributes/;
      ELSE
        IF (device_class <> rmc$terminal_device) AND (device_class <> rmc$network_device) THEN
          pmp$get_job_mode (job_mode, local_status);
          IF NOT local_status.normal THEN
            status := local_status;
            EXIT /change_terminal_attributes/;
          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$CHANGE_TERMINAL_ATTRIBUTES',
                 status);
            EXIT /change_terminal_attributes/;
          ELSE
            osp$set_status_abnormal (ifc$interactive_facility_id,
                  ife$file_name_not_terminal, ultimate_name, status);
            osp$append_status_parameter (osc$status_parameter_delimiter,
                  'IFP$CHANGE_TERMINAL_ATTRIBUTES', status);
            EXIT /change_terminal_attributes/;
          IFEND;
        IFEND;
      IFEND;

      CASE iiv$network_identifier OF
      = iic$cdcnet_network =
      { STANDALONE }

{ Check for attributes which have no meaning on this type of terminal connection.

        FOR i := 1 TO UPPERBOUND (terminal_attributes) DO
          CASE terminal_attributes [i].key OF
          = ifc$pause_break_character, ifc$terminate_break_character, ifc$terminal_class =
            osp$set_status_abnormal (ifc$interactive_facility_id,
                  ife$illegal_nam_ve_change, 'IFP$CHANGE_TERMINAL_ATTRIBUTES', status);
            message_status := status;
            osp$generate_log_message (log, message_status, status);
          ELSE
          CASEND;
        FOREND;

        iip$st_chng_terminal_attributes (ultimate_name, terminal_attributes,
               status);

      = iic$dsiaf_network =
      { DUAL STATE }

{ Check for attributes which have no meaning on this type of terminal connection.

        IF NOT iiv$cdcnet_connection THEN
          FOR i := 1 TO UPPERBOUND (terminal_attributes) DO
            CASE terminal_attributes [i].key OF
            = ifc$begin_line_character, ifc$carriage_return_sequence,
              ifc$code_set, ifc$end_page_action, ifc$form_feed_delay, ifc$form_feed_sequence,
              ifc$hold_page_over, ifc$line_feed_sequence, ifc$end_output_sequence,
              ifc$control_code_replacement , ifc$function_key_class =
              osp$set_status_abnormal (ifc$interactive_facility_id,
                    ife$illegal_nam_ccp_change, 'IFP$CHANGE_TERMINAL_ATTRIBUTES', status);
              message_status := status;
              osp$generate_log_message (log, message_status, status);
            ELSE
            CASEND;
          FOREND;
        ELSE
          FOR i := 1 TO UPPERBOUND (terminal_attributes) DO
            CASE terminal_attributes [i].key OF
            = ifc$pause_break_character, ifc$terminate_break_character,
              ifc$control_code_replacement =
              osp$set_status_abnormal (ifc$interactive_facility_id,
                    ife$illegal_nam_cdcnet_change, 'IFP$CHANGE_TERMINAL_ATTRIBUTES', status);
              message_status := status;
              osp$generate_log_message (log, message_status, status);
            ELSE
            CASEND;
          FOREND;
        IFEND;

        iip$change_terminal_attributes (terminal_attributes, status);

      ELSE
      CASEND;

    END /change_terminal_attributes/;
    #KEYPOINT (osk$exit, 0, ifk$change_terminal_attributes);

  PROCEND ifp$change_terminal_attributes;
MODEND ifm$change_terminal_attributes;
