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

?? PUSH (LISTEXT := ON) ??
*copyc OSS$JOB_PAGED_LITERAL
*copyc IIT$CONNECTION_DESCRIPTION
*copyc iip$clear_lock
*copyc iip$connection_to_vt_attributes
*copyc iip$set_lock
*copyc IIP$ST_ALLOCATE_QUEUE_ENTRY
*copyc iip$vt_initialize_connection
*copyc IIV$CONNECTION_DESC_PTR
*copyc IIV$INTERACTIVE_TERMINATED
*copyc IIV$INT_TASK_OPEN_FILE_COUNT
*copyc jmv$connection_acquired
*copyc nap$get_attributes
*copyc jmp$is_xterm_job
*copyc jmp$system_job
*copyc nat$data_fragments
*copyc OSS$TASK_SHARED
*copyc OSP$INITIALIZE_SIG_LOCK
*copyc OSV$TASK_SHARED_HEAP
*copyc PMP$GET_EXECUTING_TASK_GTID
?? POP ??

?? NEWTITLE := '  convert_and_download', EJECT ??

    PROCEDURE convert_and_download (attributes: iit$connection_attributes;
          connection_desc_ptr: ^iit$connection_description;
      VAR status: ost$status);

      VAR
        converted_loc: ^ift$connection_attributes,
        i: ift$connection_attribute_keys,
        j: integer,
        scratch_seq: ^SEQ ( * );

      PUSH scratch_seq: [[REP (ORD (ifc$max_connection_key) - ORD (ifc$min_connection_key) + 1)
            * #SIZE (ift$connection_attribute) OF CELL]];
      RESET scratch_seq;
      NEXT converted_loc: [1 .. (ORD (ifc$max_connection_key) - ORD (ifc$min_connection_key) + 1)]
            IN scratch_seq;
      j := 0;
      FOR i := ifc$min_connection_key TO ifc$max_connection_key DO
        j := j + 1;
        converted_loc^ [j].key := i;
        CASE i OF
        = ifc$attention_character_action =
          converted_loc^ [j].attention_character_action := attributes.attention_character_action.value;

        = ifc$break_key_action =
          converted_loc^ [j].break_key_action := attributes.break_key_action.value;

        = ifc$end_of_information =
          converted_loc^ [j].end_of_information := attributes.end_of_information.value;

        = ifc$input_block_size =
          converted_loc^ [j].input_block_size := attributes.input_block_size.value;

        = ifc$input_editing_mode =
          converted_loc^ [j].input_editing_mode := attributes.input_editing_mode.value;

        = ifc$input_output_mode =
          converted_loc^ [j].input_output_mode := attributes.input_output_mode.value;

        = ifc$input_timeout =
          converted_loc^ [j].input_timeout := attributes.input_timeout.value;

        = ifc$input_timeout_length =
          converted_loc^ [j].input_timeout_length := attributes.input_timeout_length.value;

        = ifc$input_timeout_purge =
          converted_loc^ [j].input_timeout_purge := attributes.input_timeout_purge.value;

        = ifc$null_connection_attribute =
          j := j - 1;

        = ifc$partial_char_forwarding =
          converted_loc^ [j].partial_character_forwarding := attributes.partial_char_forwarding.value;

        = ifc$prompt_file =
          converted_loc^ [j].prompt_file := attributes.prompt_file.value;

        = ifc$prompt_file_identifier =
          converted_loc^ [j].prompt_file_identifier := attributes.prompt_file_identifier.value;

        = ifc$prompt_string =
          converted_loc^ [j].prompt_string := attributes.prompt_string.value;

        = ifc$store_backspace_character =
          converted_loc^ [j].store_backspace_character := attributes.store_backspace_character.value;

        = ifc$store_nuls_dels =
          converted_loc^ [j].store_nuls_dels := attributes.store_nuls_dels.value;

        = ifc$trans_character_mode =
          converted_loc^ [j].trans_character_mode := attributes.trans_character_mode.value;

        = ifc$trans_forward_character =
          converted_loc^ [j].trans_forward_character := attributes.trans_forward_character.value;

        = ifc$trans_length_mode =
          converted_loc^ [j].trans_length_mode := attributes.trans_length_mode.value;

        = ifc$trans_message_length =
          converted_loc^ [j].trans_message_length := attributes.trans_message_length.value;

        = ifc$trans_terminate_character =
          converted_loc^ [j].trans_terminate_character := attributes.trans_terminate_character.value;

        = ifc$trans_timeout_mode =
          converted_loc^ [j].trans_timeout_mode := attributes.trans_timeout_mode.value;

        ELSE
          j := j - 1;
        CASEND;
      FOREND;

      IF j > 0 THEN
        RESET scratch_seq;
        NEXT converted_loc: [1 .. j] IN scratch_seq;
        iip$connection_to_vt_attributes (connection_desc_ptr, converted_loc^,
              status);
      IFEND;

    PROCEND convert_and_download;
?? OLDTITLE ??
?? NEWTITLE := 'PROCEDURE iip$st_initialize_connection', EJECT ??

  PROCEDURE [XDCL, #GATE] iip$st_initialize_connection (terminal_file_name: amt$local_file_name;
    VAR status: ost$status);

    VAR
      connection_desc_ptr: ^iit$connection_description,
      conn_desc_entry_descriptor: iit$st_queue_entry_descriptor,
      temp_string: ^string (*),
      get_attributes: array [1 ..1] of nat$get_attribute,
      local_status: ost$status,
      vtp_connection_id: iit$vtp_connection_id;

    iiv$network_identifier := iic$cdcnet_network;

    iip$set_lock (iiv$connection_desc_lock, osc$wait, status);

    iip$st_allocate_queue_entry (iic$connection_description, conn_desc_entry_descriptor, status);

    IF iiv$connection_desc_ptr = NIL THEN
      iiv$connection_desc_ptr := conn_desc_entry_descriptor.connection_description_ptr;
      connection_desc_ptr := iiv$connection_desc_ptr;
      osp$initialize_sig_lock (iiv$interactive_task_count_lock);
      osp$initialize_sig_lock (iiv$downline_queue_lock);
      osp$initialize_sig_lock (connection_desc_ptr^.st_get_lock);
    ELSE
      connection_desc_ptr := iiv$connection_desc_ptr;
      WHILE connection_desc_ptr^.next_connection_desc_ptr <> NIL DO
        connection_desc_ptr := connection_desc_ptr^.next_connection_desc_ptr;
      WHILEND;
      connection_desc_ptr^.next_connection_desc_ptr := conn_desc_entry_descriptor.connection_description_ptr;
      connection_desc_ptr := connection_desc_ptr^.next_connection_desc_ptr;
      osp$initialize_sig_lock (connection_desc_ptr^.st_get_lock);
    IFEND;

    connection_desc_ptr^.actual_connection_attributes := iiv$deflt_connection_attributes;
    connection_desc_ptr^.default_connection_attributes := iiv$deflt_connection_attributes;
    connection_desc_ptr^.downline_queue_count := 0;
    connection_desc_ptr^.get_info := iiv$get_info;
    connection_desc_ptr^.job_input_count := 0;
    connection_desc_ptr^.job_output_count := 0;
    connection_desc_ptr^.next_connection_desc_ptr := NIL;
    connection_desc_ptr^.open_local_file_count := 0;
    connection_desc_ptr^.output_buffer_entry_loc := NIL;
    connection_desc_ptr^.output_buffer_exit_loc := NIL;
    connection_desc_ptr^.page_length := 30;
    connection_desc_ptr^.page_width := 80;
    connection_desc_ptr^.session_layer_file_name := terminal_file_name;
    connection_desc_ptr^.solicitation_pending := FALSE;
    connection_desc_ptr^.terminal_model.size := 6;
    connection_desc_ptr^.terminal_model.value := 'CDC721';

{ Set the Terminal_Name terminal attribute in the connection description.

    IF jmp$is_xterm_job () THEN

{ An xterm job cannot get accounting information
{ through network access accounting information from peer.

      iiv$connection_desc_ptr^.terminal_name := osc$null_name;
    ELSE
      get_attributes [1].kind := nac$peer_accounting_information;
      PUSH get_attributes [1].peer_accounting_information: [[REP 256 OF char]];
      nap$get_attributes (terminal_file_name, get_attributes, status);
      IF NOT status.normal THEN
        get_attributes [1].peer_accounting_info_length := 0;
        status.normal := TRUE;
      IFEND;

      RESET get_attributes [1].peer_accounting_information;
      IF get_attributes [1].peer_accounting_info_length <> 0 THEN
        NEXT temp_string: [get_attributes [1].peer_accounting_info_length]
              IN get_attributes [1].peer_accounting_information;
        iiv$connection_desc_ptr^.terminal_name := temp_string^ (79, 31);
      ELSE
        iiv$connection_desc_ptr^.terminal_name := osc$null_name;
      IFEND;
    IFEND;

    iip$vt_initialize_connection (connection_desc_ptr^.vtp_connection_id, status);

    osp$initialize_sig_lock (connection_desc_ptr^.connection_attributes_lock);
    osp$initialize_sig_lock (connection_desc_ptr^.terminal_attributes_lock);

    pmp$get_executing_task_gtid (iiv$job_monitor_task_id);
    iiv$task_handling_break := iiv$job_monitor_task_id;

    iiv$connection_desc_count := SUCC (iiv$connection_desc_count);

    iip$clear_lock (iiv$connection_desc_lock, status);

    IF (NOT jmp$system_job ()) AND (jmv$connection_acquired) THEN
      IF NOT jmp$is_xterm_job () THEN

{ Connection attributes are already initialized for an xterm job.

        convert_and_download (connection_desc_ptr^.actual_connection_attributes,
              connection_desc_ptr, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
      IFEND;
    IFEND;

  PROCEND iip$st_initialize_connection;

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

  PROCEDURE [XDCL, #GATE] iip$st_clone_connection
    (VAR status: ost$status);

    pmp$get_executing_task_gtid (iiv$job_monitor_task_id);
    iiv$task_handling_break := iiv$job_monitor_task_id;
    status.normal := TRUE;
    convert_and_download (iiv$deflt_connection_attributes,
        iiv$connection_desc_ptr, status);

  PROCEND iip$st_clone_connection;
MODEND
