#!/bin/csh -f
#
# check in unchanged (for when ci complains)
#
set progname = `basename $0`
set temploc  = /tmp/$progname.$$
set tempfile = $temploc/rcsdiff.stdout+err.res
onintr tidyup

#
#	argument checking
#
if !($#argv) then
  echo "usage: $progname <file>1+" | errcat
  exit 1
endif

set files = ($*)

rm -rf $temploc
mkdir $temploc
if $status then
  echo "${progname}: fatal error: funny business in /tmp" | errcat
  exit 1
endif
chmod go-rwx $temploc	#privacy in /tmp


foreach file ($files)
  echo -n "${file}: " | errcat
   #we follow RCS's tradition of using standard error...
  rcsdiff $file >& $tempfile
  set rcsdiff_status = $status
  if ($rcsdiff_status == 0) then #no differences; safe to check in
    co -u -f -q $file
    if ($status) then
      (\
      echo "$progname had problems: aborting. PLEASE don't take RCS's advice on checking in;" ;\
      echo " it is STRONGLY recommended you leave this file alone." ;\
      ) | errcat
      # but don't exit!
    else
      echo "done." | errcat
    endif
  else if ($rcsdiff_status == 1) then #differences found; alert user!
    echo "differences found: $progname aborted." | errcat
    # but don't exit!
  else #errors in rcsdiff; alert user!
    (\
    echo "rcsdiff gives error(s), as follows:" ;\
    sed 's/^/	/' $tempfile ;\
    echo "$progname aborted." ;\
    ) | errcat
    # but don't exit!
  endif
end #foreach file

rm -rf $temploc
exit 0


tidyup:
rm -rf $temploc
echo "$progname interrupted, aborting." | errcat
exit 1
