PROCEDURE qcp$combine_drivers (
  nosve_non_boot_drivers_file, nnbdf: file = $required
  site_non_boot_drivers_catalog, snbdc: file = $required
  non_boot_drivers_file, nbdf: file = $required
  status)

"
"   The purpose of this request is to combine PP routines
"supplied by the site with the released version of the
"non_boot_drivers (specified by the first parameter).
"A catalog may optionally exist containing site-supplied PP
"routines.  If so, they are combined with the release version and
"placed on the non_boot_drivers_file.  If the site_non_boot_drivers
"catalog does not exist, this routine returns with a normal status.
"



  VAR
    command_file: file = $local//$name($unique)
    format_status: status
    formatted_count: integer = 0
    formatted_pp: file = $local//$name($unique)
    ignore_status: status
    local_status: status
    pp_add_status: status
    pp_count: integer = 0
    pp_status: status
    scratch_file: file = $local//$name($unique)
    site_pp: string
  VAREND


build_block: ..
  BLOCK

    list_catalog c=site_non_boot_drivers_catalog fl=scratch_file ..
          d=1 fc=pp_count status=pp_status

    IF (NOT pp_status.normal) OR (pp_status.normal AND (pp_count = 0)) THEN
      EXIT build_block
    IFEND

    $system.put_line ' Builing new non_boot_drivers file ...' o=$response

    VAR
      pp_files: array 1 .. pp_count of string
    VAREND

    $system.accept_line v=pp_files i=scratch_file status=local_status
    $system.detach_file scratch_file status=ignore_status
    EXIT build_block WHEN NOT local_status.normal

COLLECT_TEXT o=command_file until='END FORMAT COLLECT' sm='?' status=local_status
    manage_deadstart_files
      create_binary_formatted_file
        add_record i=nosve_non_boot_drivers_file f=NVE_FILE
        FOR i = 1 TO pp_count DO
          site_pp = $path($fname(pp_files(i)), last)
          $system.include_line 'format_binary_record i=$fname(pp_files(i)) o=formatted_pp f=CIP_PERIPHERAL_PROCESSOR' ..
             status=format_status
          IF format_status.normal THEN
            formatted_count = formatted_count + 1
            $system.include_line 'add_record i=formatted_pp f=NVE_FILE' status=pp_add_status
            IF NOT pp_add_status.normal THEN
              $system.put_line $strrep($status(FALSE, 'RA', rae$unable_to_add_formatted_pp, pp_files(i)) o=$response
            IFEND
            $system.delete_file f=formatted_pp status=ignore_status
          ELSE
            $system.put_line $strrep($status(FALSE, 'RA', rae$unable_to_format_pp, site_pp)) o=$response
          IFEND
        FOREND
        generate_file o=non_boot_drivers_file ff=NVE_FILE
      quit
    quit
END FORMAT COLLECT


    $system.include_file f=command_file status=local_status
    $system.delete_file f=command_file status=ignore_status
    EXIT build_block WHEN NOT local_status.normal

    IF NOT (pp_count = formatted_count) THEN
      text = 'PP catalog ' // $string(site_non_boot_drivers_catalog)
      local_status = $status(false, 'RA', rae$not_all_files_processed, text)
    IFEND
    EXIT build_block WHEN NOT local_status.normal

  BLOCKEND build_block

  EXIT procedure WITH local_status WHEN NOT local_status.normal

PROCEND qcp$combine_drivers
