aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtoc/toc38
-rw-r--r--toc/toc.tmac2
2 files changed, 21 insertions, 19 deletions
diff --git a/toc/toc b/toc/toc
index 2b21790..9544934 100755
--- a/toc/toc
+++ b/toc/toc
@@ -3,29 +3,31 @@
# toc -- run troff in three passes
: ${TROFF:=troff}
+SED='sed -n /^(toc)/{s///;p}'
+RM=rm
+
+trap '$RM; RM=; exit 130' INT
+trap '$RM' EXIT
+
+tmp() {
+ x=`mktemp` || exit $?
+ RM=$RM\ $x
+ eval $1=\$x
+}
if [ ! -t 0 ]; then
- f=`mktemp`
+ tmp f
cat > $f
set -- "$@" $f
fi
-if [ -z "$PIPE" ]; then
- g=`mktemp`
- h=`mktemp`
-
- 2>$g >/dev/null $TROFF -rte=1 -rto=0 -E "$@"
- <$g 2>$h >/dev/null $TROFF -rte=1 -rto=1 -E "$@"
- <$h $TROFF -rte=0 -rto=1 "$@"
- s=$?
-
- rm $h $g
-else
- $TROFF -rte=1 -rto=0 -zE "$@" 2>&1 |
- $TROFF -rte=1 -rto=1 -zE "$@" 2>&1 |
- $TROFF -rte=0 -rto=1 "$@"
- s=$?
-fi
+tmp g
+tmp h
+
+$TROFF -rte=1 -rto=0 "$@" 2>&1 1>/dev/null | $SED >$g
+$TROFF -rte=1 -rto=1 "$@" <$g 2>&1 1>/dev/null | $SED >$h
+$TROFF -rte=0 -rto=1 "$@" <$h
+
+s=$?
-[ ! -t 0 ] && rm $f
exit $s
diff --git a/toc/toc.tmac b/toc/toc.tmac
index 143994e..8431e06 100644
--- a/toc/toc.tmac
+++ b/toc/toc.tmac
@@ -15,7 +15,7 @@
.
.\" te -- collect line
.de te
-. if \n(te=1 .tm \$*
+. if \n(te=1 .tm (toc)\$*
..
.
.ec