PROCEDURE qcm$generate_qcu_ds_tape, generate_qcu_ds_tape, genqdt (
  external_vsn, evsn: string 1..6 = $required
  recorded_vsn, rvsn: string 1..6 = $optional
  type, t: any of
      key
        mt9$1600
        mt9$6250
        mt18$38000
      keyend
    anyend = mt9$6250
  delete_tape_files, dtf: boolean = TRUE
  product_files, pf: list of file = $optional
  build_level, bl: name = $optional
  feature_catalog, fc: any of
      key
        none
      keyend
      file
    anyend = none
  feature_build_level, fbl: name = object
  working_catalog, wc: any of
      key
        none
      keyend
      file
    anyend = none
  working_build_level, wbl: name = object
  status)

IF NOT $variable(wev$default_file_server defined) THEN
  VAR
    wev$default_file_server : (ENVIRONMENT) string
  VAREND
  check_default_file_server
IFEND
IF NOT $variable(wev$default_dev_base_family defined) THEN
  VAR
    wev$default_dev_base_family : (ENVIRONMENT) string
  VAREND
  set_environment_defaults
IFEND
VAR
  development_base : file = wev$development_base, $fname(wev$default_dev_base_family//'.INTVE')
  wev$development_base : (ENVIRONMENT) string = $string(development_base)
  server_development_base : file = wev$server_development_base, $fname($string(wev$default_file_server)//..
$trim($substr(wev$development_base, $scan_string('.', wev$development_base), $strlen(wev$development_base))))
  wev$server_development_base : (ENVIRONMENT) string = $string(server_development_base)
VAREND
IF $specified(build_level) THEN
  create_variable wev$build_level kind=string scope=xdcl ..
    value=$string($value(build_level))
ELSEIF $variable(wev$build_level,declared) = 'NONLOCAL' THEN
  create_variable wev$build_level kind=string scope=xref
ELSE
  create_variable wev$build_level kind=string scope=xdcl value='NONE'
IFEND

IF $specified(feature_catalog) THEN
  create_variable wev$feature_catalog kind=string scope=xdcl ..
    value=$string($value(feature_catalog))
ELSEIF $variable(wev$feature_catalog,declared) = 'NONLOCAL' THEN
  create_variable wev$feature_catalog kind=string scope=xref
ELSE
  create_variable wev$feature_catalog kind=string scope=xdcl ..
    value=$string($value(feature_catalog))
IFEND

IF $specified(feature_build_level) THEN
  create_variable wev$feature_build_level kind=string scope=xdcl ..
    value=$string($value(feature_build_level))
ELSEIF $variable(wev$feature_build_level,declared) = 'NONLOCAL' THEN
  create_variable wev$feature_build_level kind=string scope=xref
ELSE
  create_variable wev$feature_build_level kind=string scope=xdcl ..
    value=$string($value(feature_build_level))
IFEND


IF $specified(working_catalog) THEN
  create_variable wev$working_catalog kind=string scope=xdcl value=$string($value(working_catalog))
ELSEIF $variable(wev$working_catalog, declared) = 'NONLOCAL' THEN
  create_variable wev$working_catalog kind=string scope=xref
ELSE
  create_variable wev$working_catalog kind=string value='NONE'
IFEND
IF wev$working_catalog = 'NONE' THEN
  EXIT_PROC WITH $status(false, 'WE', wee$unspecified_working_cat)
IFEND

IF ($variable(wev$ignore_status, declared) = 'LOCAL') OR ($variable(wev$local_status, declared) = 'LOCAL') ..
      THEN
  EXIT_PROC WITH $status(false, 'WE', wee$declared_status_variables)
IFEND

create_variable (wev$ignore_status, wev$local_status) k=status

attach_file $fname(wev$working_catalog//'.source_library') status=wev$local_status
detach_file $fname(wev$working_catalog//'.source_library') status=wev$ignore_status
IF (wev$local_status.normal = false) AND (..
      ($condition(wev$local_status.condition) = 'PFE$UNKNOWN_LAST_SUBCATALOG') OR ..
      ($condition(wev$local_status.condition) = 'PFE$UNKNOWN_NTH_SUBCATALOG')) THEN
  delete_variable (wev$ignore_status, wev$local_status)
  EXIT_PROC WITH $status(false, 'WE', wee$undefined_working_catalog)
IFEND

delete_variable (wev$ignore_status, wev$local_status)
IF $specified(working_build_level) THEN
  create_variable wev$working_build_level kind=string scope=xdcl ..
    value=$string($value(working_build_level))
ELSEIF $variable(wev$working_build_level,declared) = 'NONLOCAL' THEN
  create_variable wev$working_build_level kind=string scope=xref
ELSE
  create_variable wev$working_build_level kind=string scope=xdcl ..
    value=$string($value(working_build_level))
IFEND


  "$FORMAT=OFF"
  TYPE
    files_record: RECORD
    name: string 0 .. $max_name
    file_id: string 1 .. 17
    RECEND
  TYPEND
  "$FORMAT=ON"

  "$FORMAT=OFF"
  VAR
    bl_path: string
    block_type: name
    boot_image_exists : boolean
    build_level_path: string
    cip_path: string
    deadstart_files_defined: boolean = FALSE
    deadstart_lists: string 0 .. $max_name = $unique
    deadstart_tape: string 0 .. $max_name = $unique
    fbl_path: string
    fbl_pp_path: string
    file_count: integer
    file_id: string 0 .. $max_name
    file_name: file
    ignore_status: status
    index: integer
    local_status: status
    maintenance_path: string
    message : string
    pps_exists : boolean
    record_type: name
    wbl_path: string
    wbl_pp_path: string
    temp_product_list: list 0 .. $max_list of file
    total_deadstart_file_count: integer
  VAREND
  "$FORMAT=ON"

gendt_block: ..
  BLOCK

    IF wev$build_level = 'NONE' THEN
      local_status=$status(false, 'WE', wee$unspecified_build_level_var)
      EXIT gendt_block
    IFEND

    cip_path='('
    build_level_path='('
    maintenance_path='('


    wbl_path=wev$working_catalog//'.'//wev$working_build_level
    wbl_pp_path=wbl_path//'.maintenance.osf$pp'
    cip_path=cip_path//wbl_path//'.cip '
    build_level_path=build_level_path//wbl_path//' '
    maintenance_path=maintenance_path//wbl_path//'.maintenance '


    IF wev$feature_catalog <> 'NONE' THEN
      fbl_path=wev$feature_catalog//'.'//wev$feature_build_level
      fbl_pp_path=fbl_path//'.maintenance.osf$pp'
      cip_path=cip_path//fbl_path//'.cip '
      build_level_path=build_level_path//fbl_path//' '
      maintenance_path=maintenance_path//fbl_path//'.maintenance '
    IFEND


    bl_path=wev$server_development_base//'.OS.'//wev$build_level
    cip_path=cip_path//bl_path//'.cip)'
    build_level_path=build_level_path//bl_path//')'
    maintenance_path=maintenance_path//bl_path//'.maintenance)'


    boot_image_exists = $file($fname(wbl_path//'.boot_image'), permanent) OR ..
          $file($fname(fbl_path//'.boot_image'), permanent)

    pps_exists = ($file($fname(wbl_pp_path), catalog) AND ..
          NOT $nil($catalog_contents($fname(wbl_pp_path), include_files)))
    IF wev$feature_catalog <> 'NONE' THEN
      pps_exists = pps_exists OR ($file($fname(fbl_pp_path), catalog) AND ..
          NOT $nil($catalog_contents($fname(fbl_pp_path), include_files)))
    IFEND

    IF boot_image_exists OR pps_exists THEN
      putl ''
      put_line l=' Build CIP and NON_BOOT_DRIVERS files.' o=$response
      generate_cip_components status=local_status
      EXIT gendt_block WHEN NOT local_status.normal
    IFEND

    putl ''
    put_line l=' Generate QCU Deadstart tape ' o=$response

    get_source d=dst$deadstart_record_lists s=$fname(deadstart_lists) pn=os status=local_status
    EXIT gendt_block WHEN NOT local_status.normal
    include_file f=$fname(deadstart_lists) status=local_status
    EXIT gendt_block WHEN NOT local_status.normal

    IF $specified(product_files) THEN
      total_deadstart_file_count=deadstart_file_count + $size(product_files)
    ELSE
      total_deadstart_file_count=deadstart_file_count
    IFEND

    "$FORMAT=OFF"
    VAR
      deadstart_files: ARRAY 1 .. total_deadstart_file_count OF files_record
    VAREND
    "$FORMAT=ON"

    FOR index = 1 TO total_deadstart_file_count DO
      deadstart_files(index).name=$unique
    FOREND
    deadstart_files_defined=true

    putl ''
    put_line l=' Acquire files.' o=$response

    file_count=1
    FOR index = 1 TO deadstart_file_count DO
      IF index = deadstart_file_count THEN
        IF $specified(product_files) THEN
          temp_product_list=product_files
          WHILE NOT $nil(temp_product_list) DO
            file_name=$first(temp_product_list)
            temp_product_list=$rest(temp_product_list)
            attach_file f=file_name lfn=$name(deadstart_files(file_count).name) am=(read, execute) sm=(read,..
                   execute) status=local_status
            EXIT gendt_block WHEN NOT local_status.normal
            put_line l='   Attaching  '//file_name o=$response
            file_id=$strrep($first($reverse($path_elements(file_name))))
            IF $size(file_id)> 17 THEN
              deadstart_files(file_count).file_id=file_id(1, 17)
            ELSE
              deadstart_files(file_count).file_id=file_id
            IFEND
            file_count=file_count + 1
          WHILEND
        IFEND
      IFEND
      include_line sl='acqqf fn=$name(deadstart_file_list(index).disk_name) ..
            lfn=$name(deadstart_files(file_count).name) ..
            sc='//$vname(deadstart_file_list(index).integration_path) status=local_status
      EXIT gendt_block WHEN NOT local_status.normal
      deadstart_files(file_count).file_id=deadstart_file_list(index).tape_name
      file_count=file_count + 1
    FOREND


    put_line l=' Begin writing the deadstart tape.' o=$response
    IF $specified(recorded_vsn) THEN
      message = ' Pls blank label '//external_vsn//': internal vsn='//recorded_vsn//', density='//type
      request_operator_action message=message status=ignore_status
      request_magnetic_tape f=$fname(deadstart_tape) evsn=external_vsn rvsn=recorded_vsn t=type r=true ..
            status=local_status
    ELSE
      request_magnetic_tape f=$fname(deadstart_tape) evsn=external_vsn t=type r=true status=local_status
    IFEND
    EXIT gendt_block WHEN NOT local_status.normal
    set_file_attribute f=$fname(deadstart_tape) flt=labelled status=local_status
    EXIT gendt_block WHEN NOT local_status.normal

      IF type = 'MT18$38000' THEN
       maxbl = 32640
      ELSE
       maxbl = 4128
      IFEND;

    FOR index = 1 TO total_deadstart_file_count DO
      get_block_and_record_type i=$fname(deadstart_files(index).name) bt=block_type rt=record_type ..
            status=local_status
      EXIT gendt_block WHEN NOT local_status.normal
      change_tape_label_attributes f=$fname(deadstart_tape) fsp=next_file rl=true ..
            fi=deadstart_files(index).file_id bt=block_type rt=record_type status=local_status
      EXIT gendt_block WHEN NOT local_status.normal
"     put_line l=' Copying the file, '//deadstart_files(index).file_id//', to the deadstart tape.' o=$response
      copy_file i=$fname(deadstart_files(index).name) o=$fname(deadstart_tape) status=local_status
      EXIT gendt_block WHEN NOT local_status.normal
    FOREND

    putl ''
    put_line l=' Generate DS tape complete' o=$response


    IF delete_tape_files THEN
"     put_line l=' Deleting tape files.' o=$response
      delete_file f=$fname(wbl_path//'.boot_image') status=ignore_status
      delete_file f=$fname(wbl_path//'.monitor_image') status=ignore_status
      delete_file f=$fname(wbl_path//'.system_core_image') status=ignore_status
      delete_file f=$fname(wbl_path//'.dcfile') status=ignore_status
      delete_file f=$fname(wbl_path//'.non_boot_drivers') status=ignore_status
      delete_file f=$fname(wbl_path//'.job_image') status=ignore_status
      delete_file f=$fname(wbl_path//'.system_core_symbol_table') status=ignore_status
      delete_file f=$fname(wbl_path//'.builtin_library') status=ignore_status
      delete_file f=$fname(wbl_path//'.operator_library') status=ignore_status
      delete_catalog c=$fname(wbl_path//'.cip') do=catalog_and_contents status=ignore_status
      delete_file f=$fname(wbl_path//'.files_attributes') status=ignore_status
    IFEND

"   put_line l=' End generate_deadstart_tape.' o=$response
  BLOCKEND gendt_block

  detach_file f=$fname(deadstart_lists) status=ignore_status
  detach_file f=$fname(deadstart_tape) status=ignore_status
  IF deadstart_files_defined THEN
    FOR index = 1 TO total_deadstart_file_count DO
      detach_file f=$fname(deadstart_files(index).name) status=ignore_status
    FOREND
  IFEND

  EXIT procedure WITH local_status WHEN NOT local_status.normal

PROCEND qcm$generate_qcu_ds_tape

