PROCEDURE (hidden) rap$move_packing_list (
  temp_packing_list_path, tplp: file = $required
  packing_list_name, pln: (VAR) string 0..16 = $required
  status)


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

" PURPOSE:
"   This procedure moves the packing list from the temporary location where
"   it was loaded, to the permanent location indicated by the packing list
"   name passed in.
"
"   Before this can be done the destination must be tested that a packing
"   list does'nt already reside there.  If one does, it is compared to the
"   packing list loaded into the temporary location.  The comparison is done
"   by checksuming the respective files.  When the checksums compare, the
"   packing list already in the destination is kept and the packing list in
"   the temporary location is deleted.  Otherwise, the user is prompted to
"   provide a new name for the packing list and the testing is repeated
"   using the new name.
"
"   When the destination is clear (that is, no packing list resides there),
"   the packing list from the temporary location is moved there.
"
"   If the packing list name was changed, the new name is returned to
"   the caller.
"
*IFEND



  "$FORMAT=OFF
  VAR
    ignore_status: status
    local_status: status
    packing_list_already_present: boolean
    packing_list_name_already_used: boolean
    packing_list_checksum: integer
    packing_list_path: file
    rav$software_maintenance: (xref) file
    temp_packing_list_checksum: integer
    utility_status: status
    value_response: string
  VAREND
  "$FORMAT=ON"


  move_block: ..
    BLOCK

      packing_list_path = rav$software_maintenance.installation_database//$name(packing_list_name)
      packing_list_name_already_used = $file(packing_list_path, permanent)
      packing_list_already_present = FALSE

      WHILE packing_list_name_already_used AND (NOT packing_list_already_present) DO

        " Compare the checksums

        "$ PACKAGE_SOFTWARE
        $system.execute_task sp=rap$package_software l=$local.raf$library status=utility_status
        EXIT move_block WHEN NOT utility_status.normal

          checksum_file f=packing_list_path c=packing_list_checksum status=local_status
          IF local_status.normal THEN
            checksum_file f=temp_packing_list_path c=temp_packing_list_checksum status=local_status
          IFEND
        QUIT
        EXIT move_block WHEN NOT local_status.normal

        IF packing_list_checksum = temp_packing_list_checksum THEN

          "Use packing list already installed.
          packing_list_already_present = TRUE
          $system.delete_file f=temp_packing_list_path status=ignore_status

        ELSE "checksums do not match"
          "The packing lists are not the same,
          "prompt user for new packing list name to resolve conflict.
          value_response = ''

          rap$display_message mm=initiation_messages mn=packing_list_name_already_used ..
                mp=(packing_list_name) t=$response status=ignore_status

          "User must acknowledge
          rap$press_next

          rap$prompt_for_value pm=install_tape_menu pn=packing_list_prompt vd=('name 1..16') ..
                vr=value_response

          packing_list_name = $translate(lower_to_upper, $trim($substr(value_response, 1, 16)))
          packing_list_path = rav$software_maintenance.installation_database//$name(packing_list_name)
          packing_list_name_already_used = $file(packing_list_path, permanent)

        IFEND
      WHILEND

      IF NOT packing_list_already_present THEN

        change_catalog_entry f=temp_packing_list_path nfn=$name(packing_list_name) status=local_status

      IFEND

    BLOCKEND move_block

  EXIT procedure WITH local_status WHEN NOT local_status.normal
  EXIT procedure WITH utility_status WHEN NOT utility_status.normal

PROCEND rap$move_packing_list
