#! /bin/csh -f

# @(#) $Header: genupd,v 1.1 91/04/16 11:41:05 deyke Exp $

set newdir=/users/funk/dk5sg/tcp
set olddir=/users/funk/dk5sg/tcp.$1

cd $newdir
sort /usr/local/lib/users > users.$$
mv users.$$ users
set files=()
foreach i ( \
	Makefile \
	convers/*.[ch] \
	convers/Makefile \
	hosts \
	net.rc.$1 \
	src/*.[ch] \
	src/Makefile \
	users \
	util/*.[ch] \
	util/Makefile \
	util/genupd \
	)
  if ( ! { cmp -s $i $olddir/$i } ) then
    set files=($files $i)
  endif
end

cd $olddir
set remove=()
foreach i (`find * -print`)
  if ( ! -e $newdir/$i ) then
    set remove=($remove $i)
    if ($i:e == c) then
      set remove=($remove $i:r.o)
    endif
  endif
end

echo 'check() {'
echo '  touch $1'
echo '  if test "`vitals - < $1`" != "$2" ; then'
echo '    echo ERROR: vitals shows wrong numbers for $1 $3 updating.'
echo '    echo Update aborted.'
echo '    exit 1'
echo '  fi'
echo '}'

cd $olddir
foreach i ($files)
  touch $i
  echo check $i \'"`vitals - < $i`"\' before
end

foreach i ($files)
  echo echo Updating $i
  echo ex - $i "<<'@EOF'"
  diff -e $i $newdir/$i
  echo x
  echo @EOF
  echo check $i \'"`vitals - < $newdir/$i`"\' after
end

foreach i ($remove)
  echo echo Removing $i
  echo rm -rf $i
end

echo echo Update complete, no errors.
echo exit 0
