Add (1) readme and (2) copy of GPLv2 for stow.
[utils/utils.git] / retex
... / ...
CommitLineData
1#!/bin/bash
2# Well-behaved repeating TeX builder -- Matt McCutchen
3# usage: retex <cmd> <input-file-minus-.tex>
4
5set -e
6
7cmd="$1"
8in="$2"
9shift 2
10
11function run {
12 echo "[$iter] Running $2..."
13 yes X | "$cmd" -file-line-error-style "$in"
14}
15
16function compare {
17 echo "Comparing files..."
18 for f in "$in"*; do
19 # ignore pdfs because they have a nonreproducible "ID" at the end
20 # and logs because they aren't read
21 if ! [ "$f" != "${f%.keep*}" ] && ! [ "$f" != "${f%.pdf}" ] \
22 && ! [ "$f" != "${f%.log}" ]; then
23 suf="${f#$in}"
24 cmp "$in$suf" "$in.keep$suf" || return $?
25 fi
26 done
27 echo "Reached a fixed point."
28}
29
30function keep {
31 echo "Keeping files..."
32 for f in "$in"*; do
33 if ! [ "$f" != "${f%.keep*}" ]; then
34 suf="${f#$in}"
35 \cp -p "$in$suf" "$in.keep$suf"
36 fi
37 done
38}
39
40function clean {
41 echo "Cleaning up kept files..."
42 rm -f "$in.keep"*
43}
44
45function fail {
46 echo "Compiler exited with code $1."
47 # Remove output files here, a la .DELETE_ON_ERROR?
48 exit $1
49}
50
51iter=0
52keep
53run || fail $?
54limit=10
55while ! compare; do
56 iter=$(($iter + 1))
57 if [ $iter -ge $limit ]; then
58 echo "Did not reach a fixed point in $limit tries."
59 exit 2
60 fi
61 keep
62 run || fail $?
63done
64clean
65echo "Successful."