PROCEDURE rap$replace_ds_tape_config (
  input_external_vsn, ievsn, iev: any of
         string 1..6
         name 1..6
       anyend = $optional
  input_recorded_vsn, irvsn, irv: any of
         string 1..6
         name 1..6
       anyend = $optional
  output_external_vsn, oevsn, oev: any of
         string 1..6
         name 1..6
       anyend = $optional
  output_recorded_vsn, orvsn, orv: any of
         string 1..6
         name 1..6
       anyend = $optional
  configuration_files_catalog, cfc: file = $system.site_os_maintenance.deadstart_commands
  input_type, it, type, t: key
      mt9$1600, mt9$6250, mt18$38000
    keyend = mt9$6250
  output_type, ot: key
      mt9$1600, mt9$6250, mt18$38000
    keyend = $optional
  input_removable_media_group, irmg: (BY_NAME, ADVANCED) any of
      key
        none
      keyend
      name
    anyend = osd$reqmt_removable_media_group, none
  output_removable_media_group, ormg: (BY_NAME, ADVANCED) any of
      key
        none
      keyend
      name
    anyend = osd$reqmt_removable_media_group, none
  unload_output_deadstart_tape, uodt: boolean = TRUE
  status)

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

"
"  The purpose of this procedure is write a new deadstart tape from an
"  existing deadstart tape, allowing changes to DCFILE, PROLOG_LIBRARY,
"  and PHYSICAL_CONFIG.
"
*IFEND


  "$FORMAT=OFF
  VAR
    command_file: file = $local//$name($unique)
    command_status: status
    ignore_status: status

"         string length choosen to accomodate string EVSN='xxxxxx' plus pad
    ievsn_string: string 0..14 = ''
    irvsn_string: string 0..14 = ''
    ivsn_specified: boolean = false

    local_status: status

    oevsn_string: string 0..14 = ''
    orvsn_string: string 0..14 = ''
    ovsn_specified: boolean = false

    temp_deadstart_catalog: file = $user//$name($unique)
    text: string
  VAREND
  "$FORMAT=ON"




*IF $variable(wev$proc_doc,declared)<>'UNKNOWN'
"  Either the external VSN or recorded VSN must be specified for both
"  the input and output VSN parameters.
*IFEND

  IF NOT $specified(output_type) THEN
    output_type = input_type
  IFEND

  IF $specified(input_external_vsn) THEN
    ivsn_specified = true
    ievsn_string = 'evsn=' // $quote($string(input_external_vsn))
  IFEND
  IF $specified(input_recorded_vsn) THEN
    ivsn_specified = true
    irvsn_string = 'rvsn=' // $quote($string(input_recorded_vsn))
  IFEND
  IF input_removable_media_group <> 'NONE' THEN
    ivsn_specified = true
  IFEND
  IF $specified(output_external_vsn) THEN
    ovsn_specified = true
    oevsn_string = 'evsn=' // $quote($string(output_external_vsn))
  IFEND
  IF $specified(output_recorded_vsn) THEN
    ovsn_specified = true
    orvsn_string = 'rvsn=' // $quote($string(output_recorded_vsn))
  IFEND
  IF output_removable_media_group <> 'NONE' THEN
    ovsn_specified = true
  IFEND
  IF NOT ivsn_specified THEN
    local_status = $status(false, 'RA', rae$vsn_param_required, ' ')
    EXIT procedure WITH local_status
  IFEND
  IF NOT ovsn_specified THEN
    local_status = $status(false, 'RA', rae$vsn_param_required, ' ')
    EXIT procedure WITH local_status
  IFEND


*IF $variable(wev$proc_doc,declared)<>'UNKNOWN'
"  If this job is being initiated from the operator console, submit the
"  job as a batch job to the system;  if this job is not being submitted
"  from the system console, continue the procedure interactively.
*IFEND

  $system.delete_file f=command_file status=ignore_status

  IF $job(system) THEN
    $system.put_line l=' Submitting job to write a new deadstart tape ...' o=output
COLLECT_TEXT command_file.$eoi until='**' sm='?'
      JOB job_name=repdtc job_class=system
        VAR
          local_status: status
          ignore_status: status
        VAREND
        SYSTEM_OPERATOR_UTILITY C=system_administration
        replace_block: BLOCK
        $system.osf$builtin_library.maintain_deadstart_software
**
  ELSE
COLLECT_TEXT command_file.$eoi until='**'
        replace_block: BLOCK
**
  IFEND


"  Call the procedure to create a deadstart catalog; the input deadstart
"  tape is read and a unqiue deadstart catalog is built in $USER

COLLECT_TEXT command_file.$eoi until='  COLLECT_END' sm='?'
    $system.create_catalog c=?temp_deadstart_catalog?  status=local_status
    EXIT replace_block WHEN NOT local_status.normal

    create_ve_deadstart_catalog dc=?temp_deadstart_catalog? ..
               ?ievsn_string? ?irvsn_string? type=?input_type? ..
               rmg=?input_removable_media_group? status=local_status
    EXIT replace_block WHEN NOT local_status.normal


"  Copy site-specified configuration files to the deadstart catalog, if any
"

    rap$copy_configuration_files cfc=?configuration_files_catalog? ..
      deadstart_catalog=?temp_deadstart_catalog? status=local_status
    EXIT replace_block WHEN NOT local_status.normal


"  Call procedure to write a new deadstart tape from the unique
"  deadstart catalog in $USER.

    create_ve_deadstart_tape ..
              deadstart_catalog=?temp_deadstart_catalog? ..
              ?oevsn_string? ?orvsn_string? ..
              type=?output_type? ..
              removable_media_group=?output_removable_media_group? ..
              unload_deadstart_tape=?unload_output_deadstart_tape? ..
              status=local_status

    EXIT replace_block WHEN NOT local_status.normal

    $system.delete_catalog c=?temp_deadstart_catalog? do=catalog_and_contents status=ignore_status

  COLLECT_END


  IF $job(system) THEN
COLLECT_TEXT command_file.$eoi until='**' sm='?'
      quit      " for maintain_software
      BLOCKEND replace_block
      QUIT "from SOU"
      IF NOT local_status.normal THEN
        $system.put_line l=(' '//$strrep($status(FALSE, 'RA', rae$executing_error, 'REPLACE_DS_TAPE_CONFIGURATIONS')) ..
        ' '//$strrep(local_status)) o=$job_log
        $system.send_operator_message 'REPLACE_DS_TAPE_CONFIGURATIONS aborted...See job log for details' ..
           operator_class=system_operator
      IFEND
    JOBEND
**
  ELSE
COLLECT_TEXT command_file.$eoi until='**' sm='?'
      BLOCKEND replace_block
**
  IFEND

  $system.include_file f=command_file status=command_status
  $system.delete_file f=command_file status=ignore_status

  $system.delete_catalog c=temp_deadstart_catalog do=catalog_and_contents status=ignore_status

*IF $variable(wev$proc_doc,declared)<>'UNKNOWN'
"  The variable command_status is the status returned from the include_file
"  command.  The variable local_status is the status of individual commands
"  within the include_file command.  If an individual command within returns
"  a bad status in local_status and the include file is running interactively,
"  command_status will be normal.  In this circumstance, local_status will
"  capture the bad status.  Using two status variables allows the capture
"  of bad status from all possible failures.  The intent is to always exit
"  this procedure with local_status when either local_status or command_status
"  is bad.
*IFEND

  IF NOT command_status.normal THEN
    local_status = command_status
  IFEND

  EXIT procedure WITH local_status WHEN NOT local_status.normal

PROCEND rap$replace_ds_tape_config
