#!/bin/csh -f

if ( $1 != "3" && $1 != "1") then
  echo "ERROR: you must specify either a 1 or a 3 as the argument "
  echo " to this program"
  echo ""
  echo "USAGE:"
  echo "    bldmanman [1|3]"
  echo ""
  exit 1
endif
echo "generating man$1 pages for the manual"

pushd $KHOROS_HOME/man >& /dev/null
set flist = `ls man$1/*.$1`
popd >& /dev/null

if ( -e man$1pg.man ) then
  /bin/rm -f man$1pg.man
endif

touch man$1pg.man
cat $KHOROS_HOME/manual/utils/man$1.header >> man$1pg.man
foreach file ( $flist )
   set front = `basename $file .$1`
   echo .so KHOROS_HOME/man/$file >> man$1pg.man
   echo .XS >> man$1pg.man
   echo $front >> man$1pg.man
   echo .XE >> man$1pg.man
end
cat $KHOROS_HOME/manual/utils/man$1.footer >> man$1pg.man
