PROC prompt_for_channel_network (
  di_information : string = $optional
  host_network_id: string = $optional
  pcu_entries    : integer -281474976710655..281474976710655 = $optional
  relays         : var of string = $optional
  network        : var of string = $optional
  lcu_entries    : var of integer = $optional
  status         : var of status = $optional
  )

" Set parameters to local variables

  di_data = $value(di_information)
  relays_restricted = $value(relays)
  network_identifier = $value(network)

" Initialize working variables. "

  create_variable choice k=string
  create_variable configuration_file k=string v='$local.'//$unique
  create_variable cr_requested k=string
  create_variable hex_network_value k=string
  create_variable (local_status ignore) k=status
  create_variable network_string k=string v=' '

" Set default values.

  IF (relays_restricted = ' ') THEN
    relays_restricted = 'NO'
  IFEND
  title = ' ' // $trim($substr(di_data, 5, 36)) // ', ' // $substr(di_data, 43, 4) // ', S/N ' //..
        $strrep($integer($substr(di_data, 50, 6)))

main_loop: ..
  LOOP

  IF network_identifier = ' ' THEN
    network_string = ' '
  ELSE
    hex_network_value = $strrep($integer(network_identifier),16)//'(16)'
    network_string = network_identifier//' or '//hex_network_value
  IFEND

"$ format=off
    put_line (..
     '1Define Channel Network for:'..
     title..
     '01. Network Identifier ................. '//network_string ..
     ' 2. Relays restricted .................. '//relays_restricted ..
     '0Enter a menu selection, QUIT, GO, or ?:'..
     )
"$ format=on
    choice = ' '
    accept_line choice input p=''

    IF choice = '1' THEN

      prompt_for_network_id network_identifier help=channel_network

    ELSEIF choice = '2' THEN " relays restricted. "

      prompt_for_relays_restricted relays_restricted

    ELSEIF ($translate(lower_to_upper, choice) = 'QUIT') OR ($translate(lower_to_upper, choice) = 'QUI') THEN

      EXIT main_loop

    ELSEIF (choice = '?') OR ($translate(lower_to_upper, choice) = 'HELP') THEN

"$ format=off
      put_line (..
        '0With this menu you define a channel network between your mainframe and'..
        ' the CDCNET DI indicated in the menu title. ' ..
        '0You must specify the network identifier for the channel network.  No ' ..
        ' default value is provided.'..
        '0The default value for Relays restricted is NO.  If you set this value '..
        ' to YES, NOS/VE will only relay messages between this network and other '..
        ' networks if no other path is available.'..
        '0Enter a menu selection to supply a parameter.'..
        ' Enter GO or press NEXT to accept the parameters and return to the'..
        '   previous menu.'..
        ' Enter QUIT to return to the previous menu without changing the parameters.'..
        '  ')
"$ format=on
      accept_line cr_requested input p='Press NEXT:'

    ELSEIF (choice = ' ') OR ($translate(lower_to_upper, choice) = 'GO') THEN

      IF network_identifier = ' ' THEN
        accept_line cr_requested input p='Network identifier needed, press NEXT: '
      ELSE
        detach_file $fname(configuration_file) status=ignore
        generate_defhn host_network_id $fname(configuration_file//'.$eoi')
        generate_defcn network_identifier relays_restricted di_data $fname(configuration_file//'.$eoi')
        execute_task sp=logical_configuration_utility
          verify_network_configuration i=$fname(configuration_file) status=local_status
        quit
        detach_file $fname(configuration_file) status=ignore
        IF local_status.normal THEN
          IF $value(network) = ' ' THEN
            $value(lcu_entries) = $value(lcu_entries) + 1
          IFEND
          $value(relays) = relays_restricted
          $value(network) = network_identifier
          put_line ('0Parameters verified.' '  ')
          accept_line cr_requested input p='Press NEXT: '
          EXIT main_loop
        ELSE
          display_value local_status
          accept_line cr_requested input p='Press NEXT: '
        IFEND
      IFEND

    ELSE

      accept_line cr_requested input p='Invalid selection, press NEXT: '

    IFEND

  LOOPEND main_loop
  detach_file $fname(hex_output_file) status=ignore

PROCEND prompt_for_channel_network
