PROCEDURE create_cdcnet_config_procs (
)

" This procedure allows the user to create the initial configuration
" for a CDCNET device.

  "$FORMAT=OFF
  VAR
    choice: string
    cr_requested: string
    local_status: status
  VAREND
  "$FORMAT=ON"

" Menu data variables. "

  "$FORMAT=OFF
  VAR
    device_type: string = ''
    di_procedure_file: string = '$local.'//$unique
    ethernet_id: string = ''
    system_id: string = ''
    ve_interface_network_id: string = ''
  VAREND
  "$FORMAT=ON

main_loop: ..
  LOOP

"$ format=off
    put_line (..
     '1Create Configuration Procedures for CDCNET Devices (MDI, MTI, TDI, ' ..
     '    and ICA-II)'..
     '01. Type of CDCNET device ............... '//device_type..
     ' 2. CDCNET device System Identifier ..... '//system_id)
    IF (device_type = 'MDI') OR (device_type = 'ICA_II') THEN
      put_line (..
        ' 3. Ethernet Network Identifier ......... '//ethernet_id..
        ' 4. VE Interface Network Identifier ..... '//ve_interface_network_id)
    ELSEIF (device_type = 'MTI') THEN
      put_line (..
        ' 3. Define an Async Terminal '..
        ' 4. Define an Async Printer   '..
        ' 5. VE Interface Network Identifier ..... '//ve_interface_network_id)
    ELSEIF (device_type = 'TDI') THEN
      put_line (..
        ' 3. Define an Async Terminal '..
        ' 4. Define an Async Printer   ')
    IFEND
    put_line (..
     '0Enter a menu selection, QUIT, GO, or ?:'..
    )
"$ format=on
    choice=''
    accept_line choice input p=''

    IF choice = '1' THEN

      prompt_for_device_type device_type

    ELSEIF choice = '2' THEN

      IF device_type <> '' THEN
        IF device_type = 'ICA_II' THEN
          prompt_for_system_id ica2 system_id
        ELSE
          prompt_for_system_id di system_id
        IFEND
      ELSE
        accept_line cr_requested input p='CDCNET device type selection needed, press NEXT: '
      IFEND
    ELSEIF choice = '3' THEN
      IF (device_type = 'MTI') OR (device_type = 'TDI') THEN
        configure_lines dpf=di_procedure_file lt=async_terminal
      ELSEIF (device_type = 'MDI') OR (device_type = 'ICA_II') THEN
        prompt_for_network_id ethernet ethernet_id
      ELSE
        put_line '  '
        accept_line cr_requested input p='Invalid selection, press NEXT: '
      IFEND

    ELSEIF choice = '4' THEN

      IF (device_type = 'MTI') OR (device_type = 'TDI') THEN
        configure_lines dpf=di_procedure_file lt=async_printer
      ELSEIF (device_type = 'MDI') OR (device_type = 'ICA_II') THEN
        prompt_for_network_id ve ve_interface_network_id
      ELSE
        put_line '  '
        accept_line cr_requested input p='Invalid selection, press NEXT: '
      IFEND

    ELSEIF choice = '5' THEN

      IF (device_type = 'MTI') THEN
        prompt_for_network_id ve ve_interface_network_id
      ELSE
        put_line '  '
        accept_line cr_requested input p='Invalid selection, press NEXT: '
      IFEND

    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 create the initial configuration for a CDCNET'..
        ' Mainframe Device Interface (MDI), Mainframe Terminal Interface (MTI),'..
        ' Terminal Device Interface (TDI), or Integrated Communications' ..
        ' Adapter (ICA-II).  You must select the type of CDCNET device' ..
        ' and supply its system identifier. '..
        ' Each device type is described more completely in the help '..
        ' for menu selection 1.'..
        )
      IF (device_type = 'MTI') OR (device_type = 'TDI') THEN
        put_line (..
          '0Select number 3 if you would like to define another ASYNC terminal' ..
          ' on a TDI or MTI.  LIM 0 PORT 0 is already defined in the default' ..
          ' configuration.  The selection of a TUP is optional.' ..
          '0Select number 4 if you would like to define an ASYNC printer on a' ..
          ' TDI or MTI.' ..
          )
        IF device_type = 'MTI' THEN
          put_line (..
          '0Select number 5 to specify the network identifier of the VE interface' ..
          ' used to route messages to the host through this MTI.  The selection' ..
          ' of a VE interface network identifier is required if more than one device' ..
          ' (i.e., MDI, MTI, or EXPRESSLink) was defined during network configuration.'..
          )
        IFEND
      ELSEIF device_type = 'ICA_II' THEN
        put_line (..
          '0Select number 3 to specify the network identifier of the ethernet' ..
          ' to which the ICA-II is connected.' ..
          '0Select number 4 to specify the network identifier of the VE interface' ..
          ' used to route messages to the host through this ICA-II.  The selection' ..
          ' of a VE interface network identifier is required if more than one device' ..
          ' (i.e., ICA_II or EXPRESSLink) was defined during network configuration.'..
          )
      ELSEIF device_type = 'MDI' THEN
        put_line (..
          '0Select number 3 to specify the network identifier of the ethernet' ..
          ' to which the MDI is connected.' ..
          '0Select number 4 to specify the network identifier of the VE interface' ..
          ' used to route messages to the host through this MDI.  The selection' ..
          ' of a VE interface network identifier is required if more than one device' ..
          ' (i.e., MDI, MTI, or EXPRESSLink) was defined during network configuration.'..
          )
      IFEND
      put_line (..
        '0Enter a menu selection to set the device type or system identifier.'..
        ' Enter GO or press NEXT to create the configuration procedure.'..
        ' Enter QUIT to return to the main menu.'..
        '  ')
"$ format=on
      accept_line cr_requested input p='Press NEXT: '

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

      IF device_type = '' THEN
        put_line '  '
        accept_line cr_requested input p='CDCNET device type needed, press NEXT: '
      ELSE
        IF system_id = '' THEN
          put_line '   '
          accept_line cr_requested input p='CDCNET device System Identifier needed, press NEXT: '
        ELSE
          IF (device_type = 'MDI') OR (device_type = 'ICA_II') THEN
            IF (ethernet_id <> '') AND (ve_interface_network_id <> '') THEN
              include_line ..
                    'add_device_interface t='//device_type//' pn=SYSTEM_'//system_id//' eni=ethernet_id ..
                    vini=ve_interface_network_id status=local_status'
            ELSEIF ethernet_id <> '' THEN
              include_line ..
                    'add_device_interface t='//device_type//' pn=SYSTEM_'//system_id//' eni=ethernet_id ..
                    status=local_status'
            ELSEIF ve_interface_network_id <> '' THEN
              include_line ..
                    'add_device_interface t='//device_type//' pn=SYSTEM_'//system_id//'..
                    vini=ve_interface_network_id status=local_status'
            ELSE
              include_line ..
                    'add_device_interface t='//device_type//' pn=SYSTEM_'//system_id//' status=local_status'
            IFEND
          ELSEIF (device_type = 'MTI') THEN
            IF $file($fname(di_procedure_file), opened) THEN
              IF ve_interface_network_id <> '' THEN
                include_line ..
                      'add_device_interface t='//device_type//' pn=SYSTEM_'//system_id//'..
                      dpf='//di_procedure_file//' vini=ve_interface_network_id status=local_status'
              ELSE
                include_line 'add_device_interface t='//device_type//' pn=SYSTEM_'//system_id//'..
                     dpf='//di_procedure_file//' status=local_status'
              IFEND
            ELSE
              IF ve_interface_network_id <> '' THEN
                include_line ..
                      'add_device_interface t='//device_type//' pn=SYSTEM_'//system_id//' ..
                      vini=ve_interface_network_id status=local_status'
              ELSE
                include_line ..
                      'add_device_interface t='//device_type//' pn=SYSTEM_'//system_id//' status=local_status'
              IFEND
            IFEND
          ELSE"IF (device_type = 'TDI') THEN
            IF $file($fname(di_procedure_file), opened) THEN
              include_line 'add_device_interface t='//device_type//' pn=SYSTEM_'//system_id//'..
                   dpf='//di_procedure_file//' status=local_status'
            ELSE
              include_line ..
                    'add_device_interface t='//device_type//' pn=SYSTEM_'//system_id//' status=local_status'
            IFEND
          IFEND

          IF local_status.normal THEN
            accept_line cr_requested input p='Press NEXT: '
            EXIT main_loop
          ELSE
            display_value local_status
            put_line '  '
            accept_line cr_requested input p='Press NEXT: '
          IFEND
        IFEND
      IFEND
    ELSE

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

    IFEND
  LOOPEND main_loop

PROCEND create_cdcnet_config_procs
