# makesect: make the reference manual
#
# Usage: makesect <size>
#
# If the file 'lastpage' exists, it will be read to get the initial page number
#
# This differs from makesection by not making a table of contents, and also
# in where it puts the files.
#
# $Id: makesect,v 2.3 1999/04/26 04:44:42 grog Exp grog $
#
# $Log: makesect,v $
# Revision 2.3  1999/04/26 04:44:42  grog
# Checkin 9 May
#
# Revision 2.2  1997/12/30 08:08:39  grog
# Minor mods
#
# Revision 2.1  1997/12/07 08:34:53  grog
# Base second edition
#
# Revision 1.2  1997/08/30 04:56:52  grog
# Checkpoint 30 August 1997
#
# Revision 1.1  1996/11/12 11:15:44  grog
# Initial revision
#
#
sect=$1
if [ -f lastpage ]; then
  read page < lastpage
  page=`expr $page + 1`
else
  page=1
fi
TEMPFILE=/tmp/filelist.$$ export TEMPFILE
MANTEMP=../Chapter/${sect}/mantemp
if [ -f preferences/$1 ]; then
  cat preferences/$1 > $TEMPFILE
fi
TOOLS=`pwd`/../tools
GROFF_TMAC_PATH=$TOOLS:/usr/share/tmac export GROFF_TMAC_PATH
PATH=$TOOLS:$PATH
cd man$sect
rm -rf ../Chapter/$sect/manpages ../$sect/Toc/toc.man
mkdir -p ../Chapter/$sect
echo --- eliminating duplicates
# We do this by sorting by size (4th column of the ls -l listing)
# and comparing adjacent files.  They're gzipped, which means they're
# not exactly the same size, but they're close enough.
ls -lL *.gz | sort +4 | sed 's:^.* ::; s:^\./::; s:\.gz$::' >> $TEMPFILE
files=`xargs <$TEMPFILE elimdup | sort -f`
printf "%-28s\t%s\t%s\t%s\n\n" "Man page" First Last Pages
for i in ${files}; do
  printf "%-30s\t%d\t" $i $page
#  echo "zcat $i | cleanup $i | soelim | ${TBL} | groff -rD1 -rP$page -r%$page -r$$ -rLL=${HEIGHT} -rIN=${WIDTH} -rN2 -mpic ${MACROFILE} -    >../Chapter/$sect/man/$i"
  cleanup < $i $i | soelim | ${TBL} | \
  groff -rD1 -rP$page -r%$page -r$$ -rLL=${HEIGHT} -rIN=${WIDTH} -rN2 -mpic ${MACROFILE} - \
   >${MANTEMP} 2>>../$sect/Toc/toc.man
#   echo   lastpage=\`awk \< ../Chapter/$sect/man/$i '/%%Page:/ {page=$2 }; END {print page}'\`
   lastpage=`awk < ${MANTEMP} '/%%Page:/ {page=$2 }; END {print page}'`
   if [ $lastpage -ge $page ]; then
     pages=`expr $lastpage - $page + 1`
     page=$lastpage
   else
     echo '***' $i has incorrect page numbering: $lastpage
     pages=1
   fi
   cat ${MANTEMP} >> ../Chapter/$sect/manpages
   rm ${MANTEMP}
   printf "%d\t%d\n" $page $pages
   page=`expr $page + 1`
done
echo $page > ../appendix-start
rm manpages~
rm $TEMPFILE
