diff options
author | John Ankarström <john@ankarstrom.se> | 2021-06-23 20:55:06 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-06-23 20:55:06 +0200 |
commit | bffbccd88aa57541bffca931c6a4c205773ad619 (patch) | |
tree | 113458e94b7f5439efa8b058e3a819827a42b342 /toc | |
parent | df9030831e294af0030d3c9df092a1ea910aa6df (diff) | |
download | mk-bffbccd88aa57541bffca931c6a4c205773ad619.tar.gz |
toc: Change toc script usage, skip unnecessary passes
Diffstat (limited to 'toc')
-rw-r--r-- | toc/Makefile | 8 | ||||
-rwxr-xr-x | toc/gtoc | 4 | ||||
-rwxr-xr-x | toc/toc | 46 |
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" "$@" @@ -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 |