! sqrsh (sqr shell)
! Copyright (C) 1997 Ray Ontko & Company
!
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation; either version 2 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program; if not, write to the Free Software
! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
!
!++
!
! Name
!
!   sqrsh.sqh
!
! Description
!
!   This is a library of shared routines used by various sqrsh
!   modules.
!
!--
!
! Modification History
!
! Name            Date       Comment
! --------------- ---------- ---------------------------------------- 
! Lori Donnelly   1999/07/06 Added fixup_files
! Ray Ontko       1999/08/06 Cleanup fixup_files
!

!-------------------------------------------------------------- fixup_files
begin-procedure fixup_files ( $tname, $oname, $bname )
!
!++
!
! Procedure
!
!   fixup_files( $tname , $oname , $bname )
!
! Description
!
!   This procedure takes the temporary file that was created in the
!   previous procedure and renames it to the output file name that 
!   the user has selected.  This routine is needed so that a user
!   can now successfully have the output file name the same as the
!   input file name.  This removes a step for the user.  This procedure
!   checks to see if the output file name exists if it does it deletes
!   it and then renames the temporary file to the name the user requested.
!   If the user requests a different output file name it will just rename
!   the temporary file and not try to do a delete.  There are error messages
!   that let you know if there was any trouble deleting or renaming the
!   files.  The messages are just 'show' statements.  Processing is not
!   stopped.  If either of these messages occur you will need to verify
!   your output.
!
!--
!

! if the backup file exists, delete it
if exists($bname) = 0
   let #bdstatus = delete($bname)
   ! we don't care if it fails
end-if

! if the output file exists, rename it to the bck file
if exists($oname) = 0 
   if rename($oname, $bname) != 0
      show 'unable to rename "' $oname '" to "' $bname '"'
   end-if
end-if

! rename the tmp file to the output file
if rename($tname, $oname) != 0
   show 'unable to rename "' $tname '" to "' $oname '"'
end-if

end-procedure !fixup_files

