aboutsummaryrefslogtreecommitdiff
path: root/toc
diff options
context:
space:
mode:
Diffstat (limited to 'toc')
-rw-r--r--toc/Makefile8
-rwxr-xr-xtoc/gtoc4
-rwxr-xr-xtoc/toc46
3 files changed, 36 insertions, 22 deletions
diff --git a/toc/Makefile b/toc/Makefile
index 6b6468f..d6d2a6e 100644
--- a/toc/Makefile
+++ b/toc/Makefile
@@ -1,5 +1,5 @@
-README.pdf: README.t toc.tmac toc gtoc
- ./gtoc -Tps README.t | ps2pdf - > README.pdf
+README.pdf: README.t toc.tmac toc
+ <README.t ./toc groff -Tps | ps2pdf - > README.pdf
-example.pdf: example.t toc.tmac toc gtoc
- ./gtoc -Tps example.t | ps2pdf - > example.pdf
+example.pdf: example.t toc.tmac toc
+ <example.t ./toc groff -Tps | ps2pdf - > example.pdf
diff --git a/toc/gtoc b/toc/gtoc
deleted file mode 100755
index f64ddbe..0000000
--- a/toc/gtoc
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-export TROFF=groff
-exec=${0%gtoc}toc
-exec "$exec" "$@"
diff --git a/toc/toc b/toc/toc
index d3de1a5..4e1f298 100755
--- a/toc/toc
+++ b/toc/toc
@@ -2,12 +2,17 @@
# 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
+AWK='
+ /^\(toc\)/ { print substr($0, 6); next }
+ { print > "/dev/stderr" }
+'
+
+usage() {
+1>&2 echo "usage: $0 [cmd ... \|] <troff> [arg ...]"
+1>&2 echo "(input should be given on stdin)"
+ exit 1
+}
tmp() {
x=`mktemp` || exit $?
@@ -15,19 +20,32 @@ tmp() {
eval $1=\$x
}
-if [ ! -t 0 ]; then
- tmp f
- cat > $f
- set -- "$@" $f
-fi
+end() {
+ cat $1
+ exit $s
+}
+
+[ $# -eq 0 ] && usage
+trap '$RM; RM=; exit 130' INT
+trap '$RM' EXIT
+
+tmp f
+>$f cat
tmp g
tmp h
+tmp i
+tmp j
+
+echo $0: first pass 1>&2
+{ eval "$@" -rte=1 -dtf=; s=$?; } <$f 2>&1 1>$i | awk "$AWK" >$g
+[ -s $g ] || end $i
-$TROFF -rte=1 -dtf= "$@" 2>&1 1>/dev/null | $SED >$g
-$TROFF -rte=1 -dtf=$g "$@" 2>&1 1>/dev/null | $SED >$h
-$TROFF -rte=0 -dtf=$h "$@"
+echo $0: second pass 1>&2
+{ eval "$@" -rte=1 -dtf=$g; s=$?; } <$f 2>&1 1>$j | awk "$AWK" >$h
+diff -q $g $h >/dev/null && end $j
-s=$?
+echo $0: third pass 1>&2
+{ eval "$@" -rte=0 -dtf=$h; s=$?; } <$f | grep -v '^(toc)'
exit $s