#!/bin/sh
# Make a short table of contents file from the source file
# for inclusion by the main file.
# Greg Lehey, 1 January 2003
# $Id: mkctoc,v 1.9 2003/01/07 03:06:02 grog Exp grog $
#
# Usage: mkctoc filename
#
SRCFILE=$1
STOCFILE=ctoc/$SRCFILE
cat > ${STOCFILE} <<EOF
.nh
.nr header*end \n[nl]
.\" Defined in Chapter and Appendix macros
.nr header*height \n[header*end]-\n[header*start]
.\" \n[header*height]
.sp -\n[header*height]u
.nr ctoc*old*indent \n[.i]
.nr ctoc*old*ll \n[.l]
.\" Define the layout of the box
.nr stoc*indent .08i
.nr stoc*ll 1.5i
.nr stoc*box*outdent 0-\n[stoc*indent]
.nr stoc*box*width \n[stoc*ll]u+(2*\n[stoc*indent])
.in \n[stoc*indent]u
.ll \n[stoc*ll]u
.fam H
.na
.ft I
.vs 10p
.ps 9
.mk stoc*box*top*left
.sp 1v
.nr text*start \n[nl]
In this chapter:
.Ls B
EOF
grep ^.H2 ${SRCFILE} | sed 's/.H2 "/.sp -.6v \
.LI \
/; s/"$//' >> ${STOCFILE}
cat >> ${STOCFILE} <<EOF
.LE
.\" Grr.  If I don't extend the line length, the box drops a line.
.ll +2i
.\" Fill 20% grey
\D'f 200'
.nr stoc*box*ht \n[nl]-\n[stoc*box*top*left]
.\" Fill box
\D'P \n[stoc*box*outdent]u 0u 0 -\n[stoc*box*ht]u \n[stoc*box*width]u 0 0 \n[stoc*box*ht]u'
.ll -2i
.sp -\n[stoc*box*ht]u
In this chapter:
.Ls B
EOF
grep ^.H2 ${SRCFILE} | sed 's/.H2 "/.sp -.6v \
.LI \
/; s/"$//' >> ${STOCFILE}
cat >> ${STOCFILE} <<EOF
.LE
.sp 1v
.ps
.vs
.ft R
.ad
.fam
.ll \n[ctoc*old*ll]u
.in \n[ctoc*old*indent]u
.\" Now see whether we're above or below the title.  If we're
.\" above, move down.
.nr ctoc*bottom \n[nl]
.\" Header end \n[header*end], ctoc bottom \n[ctoc*bottom],
.nr ctoc*undershoot \n[header*end]-\n[ctoc*bottom]
.ie \n[ctoc*undershoot]>0 .sp \n[ctoc*undershoot]u
.el .sp 1v
.hy
.ig
stoc*indent \n[stoc*indent]
stoc*ll \n[stoc*ll]
stoc*box*outdent \n[stoc*box*outdent]
stoc*box*width \n[stoc*box*width]
.P
..
EOF
