PROCEDURE  add_device_interface, adddi (
  type, t: key mdi, mti, ndi, tdi, ica_ii, keyend = $required
  procedure_name, pn: name = $required
  di_procedure_file, dpf: file
  ethernet_network_id, eni: string = $optional
  ve_interface_network_id, vini: string = $optional
  status)


*IF $variable(wev$proc_doc,declared)<>'UNKNOWN'

"     The purpose of this request is to create a CDCNET device
"configuration procedure using a template contained in
"$SYSTEM.CDCNET.SITE_CONTROLLED.CONFIGURATION.  This is to
"help the first time installer bring up a CDCNET device.
"
*IFEND


  WHEN any_fault DO
    detach_file $fname(configuration_file) status=ignore_status
    detach_file $value(di_procedure_file) status=ignore_status
    EXIT_PROC WITH osv$status
  WHENEND


    create_variable ignore_status k=status
    create_variable local_status k=status
    create_variable configuration_file k=string v='$system.cdcnet.site_controlled.configuration'
    create_variable configuration_proc k=string v='$local.'//$unique
    create_variable procedure_name k=string v=$string($value(procedure_name))

  "Pull out the skeleton procedure"

  $system.osf$command_library.create_object_library
    add_module l=$fname(configuration_file) m=$name($value(type)) status=local_status
    IF local_status.normal THEN
      generate_library l=$fname(configuration_proc) f=scl_proc
    ELSE
      put_line ' --ERROR-- Unable to access CDCNET device configuration procedures.' o=$response
    IFEND
  quit

  EXIT_PROC WITH local_status WHEN NOT local_status.normal

  "Edit in the proper procedure name"

  old_proc = 'PROC ' // $translate(ltu, $string($value(type)))
  new_proc = 'PROC ' // procedure_name
  old_procend = 'PROCEND ' // $translate(ltu, $string($value(type)))
  new_procend = 'PROCEND ' // procedure_name

 $system.edit_file $fname(configuration_proc) o=$null
    replace_text old_proc new_proc uc=yes
    IF ($specified(di_procedure_file)) THEN
      locate_text t='define_line'
      read_file f=$value(di_procedure_file) p=b
    IFEND
    IF $specified(ethernet_network_id) AND (type = mdi) THEN
      old_network_id = 'network_id = 1000(10)'
      new_network_id = 'network_id = '//ethernet_network_id
      replace_text old_network_id  new_network_id
    ELSEIF $specified(ethernet_network_id) AND (type = ica_ii) THEN
      old_network_id = 'network_id = 2000(10)'
      new_network_id = 'network_id = '//ethernet_network_id
      replace_text old_network_id  new_network_id
    IFEND
    replace_text old_procend new_procend uc=yes
    IF $specified(ve_interface_network_id) THEN
      insert_line new_text='define_ve_interface network_id='//ve_interface_network_id//'' p=before il=last
    IFEND
  end

  "Write the updated configuration library"

  IF local_status.normal THEN
    $system.osf$command_library.create_object_library
      add_module l=$fname(configuration_file)
      combine_module l=$fname(configuration_proc) status=local_status
      IF local_status.normal THEN
        generate_library l=$fname(configuration_file//'.$next')
      ELSE
        put_line ' --ERROR--  Unable to add new CDCNET device configuration procedure to library.' o=$response
      IFEND
    quit

    "Clean up even if creol fails"
    detach_file ($fname(configuration_proc)) status=ignore_status
    detach_file $fname(configuration_file) status=ignore_status
    detach_file $value(di_procedure_file) status=ignore_status

    EXIT_PROC WITH local_status WHEN NOT local_status.normal

  ELSE
    put_line ' --ERROR--  Unable to access CDCNET device configuration procedures.' o=$response
    EXIT_PROC WITH local_status
  IFEND

  put_line ('  ', ' CDCNET configuration procedure '//procedure_name//' installed', '  ') o=$response

PROCEND add_device_interface
