aboutsummaryrefslogtreecommitdiff
path: root/toc/toc
diff options
context:
space:
mode:
Diffstat (limited to 'toc/toc')
-rwxr-xr-xtoc/toc30
1 files changed, 13 insertions, 17 deletions
diff --git a/toc/toc b/toc/toc
index 4e1f298..f6c2501 100755
--- a/toc/toc
+++ b/toc/toc
@@ -2,15 +2,9 @@
# toc -- run troff in three passes
-RM=rm
-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)"
+ echo "usage: $0 [cmd ... \|] <troff> [arg ...]" 1>&2
+ echo "(input should be given on stdin)" 1>&2
exit 1
}
@@ -25,27 +19,29 @@ end() {
exit $s
}
+RM=rm
+AWK='
+ /^\(toc\)/ { print substr($0, 6); next }
+ { print > "/dev/stderr" }
+'
+
[ $# -eq 0 ] && usage
trap '$RM; RM=; exit 130' INT
trap '$RM' EXIT
-
-tmp f
->$f cat
-
-tmp g
-tmp h
-tmp i
-tmp j
+for t in f g h i j; do tmp $t; done
echo $0: first pass 1>&2
-{ eval "$@" -rte=1 -dtf=; s=$?; } <$f 2>&1 1>$i | awk "$AWK" >$g
+
+tee $f | { eval "$@" -rte=1 -dtf=; s=$?; } 2>&1 1>$i | awk "$AWK" >$g
[ -s $g ] || end $i
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
echo $0: third pass 1>&2
+
{ eval "$@" -rte=0 -dtf=$h; s=$?; } <$f | grep -v '^(toc)'
exit $s