?? RIGHT := 110 ??
?? NEWTITLE := 'INSTALL_SOFTWARE Utility: RAP$CHECKSUM_FILE Interface.' ??
MODULE ram$checksum_file;

{ PURPOSE:
{   This module contains the interface to checksum a file.
{
{ DESIGN:
{   The compiled module resides in RAF$LIBRARY.
{   The file is opened, checksummed, and closed.  The checksum is returned
{   to the caller.
{
{ NOTES:
{
{

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
?? POP ??
*copyc amp$get_segment_pointer
*copyc fsp$close_file
*copyc ocp$checksum
*copyc osp$disestablish_cond_handler
*copyc osp$establish_block_exit_hndlr
*copyc rap$open_file
?? OLDTITLE, NEWTITLE := 'Global Declarations Declared by This Module', EJECT ??
?? OLDTITLE, NEWTITLE := '[XDCL] rap$checksum_file', EJECT ??

{ PURPOSE:
{   This procedure returns a checksum for the specified file.
{
{ DESIGN:
{   The file is opened, checksummed, and closed.  The checksum is returned
{   to the caller.
{
{ NOTES:
{
{

  PROCEDURE [XDCL] rap$checksum_file
    (    file: fst$file_reference;
     VAR checksum: integer;
     VAR status: ost$status);

    VAR
      file_contents_p: ^SEQ ( * ),
      file_fid: amt$file_identifier,
      file_open: boolean,
      file_segment_pointer: amt$segment_pointer,
      local_status: ost$status;

?? NEWTITLE := 'abort_handler', EJECT ??

{ PURPOSE:
{   This procedure cleans up when an abort situation occurs within the block
{   structure.
{
{ DESIGN:
{   If the file has been opened, it will be closed before the the procedure
{   returns.
{
{ NOTES:
{
{

    PROCEDURE abort_handler
      (    condition: pmt$condition;
           condition_information: ^pmt$condition_information;
           save_area: ^ost$stack_frame_save_area;
       VAR handler_status: ost$status);

      VAR
        ignore_status: ost$status;

      IF file_open THEN
        fsp$close_file (file_fid, ignore_status);
      IFEND;

    PROCEND abort_handler;

?? OLDTITLE, EJECT ??


    status.normal := TRUE;

    file_open := FALSE;
    osp$establish_block_exit_hndlr (^abort_handler);

  /main/
    BEGIN

      rap$open_file (^file, amc$segment, fsc$read, FALSE, NIL, file_fid, file_open, status);
      IF NOT status.normal THEN
        EXIT /main/;
      IFEND;

      amp$get_segment_pointer (file_fid, amc$sequence_pointer, file_segment_pointer, status);
      IF NOT status.normal THEN
        EXIT /main/;
      IFEND;
      file_contents_p := file_segment_pointer.sequence_pointer;

      RESET file_contents_p;

      checksum := ocp$checksum( file_contents_p );

    END /main/;

    IF file_open THEN
      fsp$close_file (file_fid, local_status);
      IF status.normal AND (NOT local_status.normal) THEN
        status := local_status;
      IFEND;
    IFEND;

    osp$disestablish_cond_handler;

  PROCEND rap$checksum_file;
MODEND ram$checksum_file;
