PROCEDURE rap$collect_dump_materials (
  external_vsn, evsn, ev: any of
      string 1..6
      name 1..6
    anyend = $optional
  recorded_vsn, rvsn, rv: any of
      string 1..6
      name 1..6
    anyend = $optional
  type, t: key
      mt9$1600, mt9$6250, mt18$38000
    keyend = mt9$6250
  link_output_catalog, loc: file = $optional
  status)


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

"    The purpose of this request is to collect the linker output
"files (JOB_TEMPLATE_LINK_MAP, SYSTEM_CORE_LINK_MAP and
"SYSTEM_DEBUG_TABLE) that are required for debugging a system
"altered by a site.  The collected files are written to the tape
"specified by either the EVSN or RVSN (or both). The parameter
"can optionally be specified to locate the files to be dumped; if this
"parameter is not specified, it is computed by using the level value
"returned from the procedure GET_SYSTEM_LEVEL.
*IFEND

*copyc rav$maids_file_catalog_names

  "$FORMAT=OFF
  VAR
    backup_jt_link_map: string
    backup_sc_link_map: string
    backup_system_debug_table: string
    command_file: file = $local//$name($unique)
    evsn_string: string 0..14 = ''
    jt_link_map: file
    ignore_status: status
    local_status: status

    nosve_link_input_catalog: file
    nosve_version_file: file
    output_vsn: string 0..5 = ''
    rvsn_string: string 0..14 = ''
    sc_link_map: file
    system_debug_table: file
    system_level: name
    text: string
  VAREND
  "$FORMAT=ON"


  WHEN any_fault DO
    EXIT procedure WITH osv$status
  WHENEND

  main_block: ..
    BLOCK

*copyc rav$system_root_variable

  IF NOT $specified(link_output_catalog) THEN
    nosve_version_file = rav$system//name_nosve_maintenance_catalog//name_link_input_catalog//name_os_version_file
    rap$get_system_level ovf=nosve_version_file sl=system_level status=local_status
    EXIT main_block WHEN NOT local_status.normal
    link_output_catalog = rav$system//name_site_maintenance_catalog//system_level//name_link_output_catalog
  IFEND

  jt_link_map = link_output_catalog//name_jt_link_map
  sc_link_map = link_output_catalog//name_sc_link_map
  system_debug_table = link_output_catalog//name_system_debug_table

  backup_jt_link_map = 'backup_file ' // $string(jt_link_map)
  backup_sc_link_map = 'backup_file ' // $string(sc_link_map)
  backup_system_debug_table = 'backup_file ' // $string(system_debug_table)

  IF $specified(external_vsn) THEN
    evsn_string = 'evsn=' // $quote($string(external_vsn))
    output_vsn = $string(external_vsn)
  IFEND
  IF $specified(recorded_vsn) THEN
    rvsn_string = 'rvsn=' // $quote($string(recorded_vsn))
    output_vsn = $string(recorded_vsn)
  IFEND

  collect_block: ..
    BLOCK

  IF output_vsn = '' THEN
    local_status = $status(FALSE, 'RA', rae$vsn_param_required, ' ')
    EXIT collect_block WHEN NOT local_status.normal
  IFEND

  IF NOT $file(jt_link_map, assigned) OR ($file(jt_link_map, size) <= 0) THEN
    backup_jt_link_map = ''
    $system.put_line ' Missing dump material file: '//$string(jt_link_map) o=$response
  IFEND
  IF NOT $file(sc_link_map, assigned) OR ($file(sc_link_map, size) <= 0) THEN
    backup_sc_link_map = ''
    $system.put_line ' Missing dump material file: '//$string(sc_link_map) o=$response
  IFEND
  IF NOT $file(system_debug_table, assigned) OR ($file(system_debug_table, size) <= 0) THEN
    backup_system_debug_table = ''
    $system.put_line ' Missing dump material file: '//$string(system_debug_table) o=$response
  IFEND
  IF (backup_jt_link_map = '') AND (backup_sc_link_map = '') AND (backup_system_debug_table = '') THEN
    local_status = $status(FALSE, 'RA', rae$missing_required_file, 'needed for the dump materials')
    EXIT collect_block WHEN NOT local_status.normal
  IFEND

  $system.put_line ' Submitting batch job to write dump materials to tape '//output_vsn o=$response

COLLECT_TEXT o=command_file until='END_COLLECT' sm='?'
  JOB jn=coldm jc=system
    $system.request_magnetic_tape f=$local.tape t=?type? ..
      ?evsn_string?  ?rvsn_string?  ring=true
    $system.backup_permanent_files bf=$local.tape l=$null
      ?backup_jt_link_map?
      ?backup_sc_link_map?
      ?backup_system_debug_table?
    quit
    $system.detach_file f=$local.tape
  JOBEND
END_COLLECT

  $system.include_file f=command_file status=local_status
  $system.detach_file f=command_file status=ignore_status

  BLOCKEND collect_block

  BLOCKEND main_block

  EXIT procedure WITH local_status WHEN NOT local_status.normal

PROCEND rap$collect_dump_materials
