#!/bin/csh -f
# Swaps the contents of the two files given as arguments if they
# both exist.  Flags an error if the number of arguments is not two
# or the files don't both exist.

if ($#argv != 2) then
  echo swap: '' Usage: swap file1 file2
  exit(1)
endif

set temp1 = /tmp/$1:t.swap.$$

if (-f $1 && -f $2) then
  rm -f $temp1
  mv $1 $temp1
  if ($status) exit(2)
  mv $2 $1
  if ($status) exit(3)
  mv $temp1 $2
else
  echo swap: '' file not found
  exit(4)
endif
