| 1 | #!/bin/sh |
| 2 | # dvipdft, completely rewritten by Thomas Esser for teTeX after an |
| 3 | # original script by Mark A. Wicks |
| 4 | # |
| 5 | # Thomas Esser. Public Domain. |
| 6 | # |
| 7 | # Modified by Matthias Franz for dvipdfmx (when running as dvipdfm) and |
| 8 | # TeX Live. |
| 9 | |
| 10 | # This script makes a first (fast) run with dvipdfm, then calls gs on |
| 11 | # the resulting pdf file to get the thumbnails and finally calls dvipdfm. |
| 12 | |
| 13 | progname=dvipdft |
| 14 | version=20090604.0046 |
| 15 | |
| 16 | # set trap for error |
| 17 | trap ' |
| 18 | echo "$progname: fatal error." >&2 |
| 19 | exit 1 |
| 20 | ' 1 |
| 21 | |
| 22 | test -f /bin/sh5 && test -z "$RUNNING_SH5" \ |
| 23 | && { UNAMES=`uname -s`; test "x$UNAMES" = xULTRIX; } 2>/dev/null \ |
| 24 | && { RUNNING_SH5=true; export RUNNING_SH5; exec /bin/sh5 $0 ${1+"$@"}; } |
| 25 | unset RUNNING_SH5 |
| 26 | |
| 27 | test -f /bin/bsh && test -z "$RUNNING_BSH" \ |
| 28 | && { UNAMES=`uname -s`; test "x$UNAMES" = xAIX; } 2>/dev/null \ |
| 29 | && { RUNNING_BSH=true; export RUNNING_BSH; exec /bin/bsh $0 ${1+"$@"}; } |
| 30 | unset RUNNING_BSH |
| 31 | |
| 32 | # hack around a bug in zsh: |
| 33 | test -n "${ZSH_VERSION+set}" && alias -g '${1+"$@"}'='"$@"' |
| 34 | |
| 35 | help="Usage: $progname [options] dvifile |
| 36 | $progname --help |
| 37 | $progname --version" |
| 38 | |
| 39 | quoteit() |
| 40 | { |
| 41 | echo "x$1" | sed "s@.@@; s@'@'\\\\''@; s@^@'@; s@\$@'@" |
| 42 | } |
| 43 | |
| 44 | # process args 1 to (n-1) and scan for a -o argument keep a properly |
| 45 | # quoted backup of the options, so that they can be restored later |
| 46 | unset s outfile |
| 47 | while test $# -gt 1; do |
| 48 | case $1 in |
| 49 | -o) outfile=$2;; |
| 50 | esac |
| 51 | s="$s${s+ }"`quoteit "$1"` |
| 52 | shift |
| 53 | done |
| 54 | |
| 55 | # check for last argument |
| 56 | case $1 in |
| 57 | --help) |
| 58 | echo "$help" |
| 59 | exit 0 |
| 60 | ;; |
| 61 | --version) |
| 62 | echo "$progname version $version by Thomas Esser and others" |
| 63 | exit 0 |
| 64 | ;; |
| 65 | "") |
| 66 | echo "$help" |
| 67 | exit 1 |
| 68 | ;; |
| 69 | esac |
| 70 | |
| 71 | # args 1 to (n-1) are gone, last one must be the dvifile |
| 72 | dvifile="$1" |
| 73 | |
| 74 | # outfile comes from -o argument, else it is derived from the input file |
| 75 | test -n "$outfile" \ |
| 76 | || outfile=`echo "$dvifile" | sed 's@.*/@@; s@\.dvi$@@; s@[email protected]@'` |
| 77 | |
| 78 | # outBase is part of the thumbname files just as dvipdfm expects them: |
| 79 | outBase=`echo "$outfile" | sed 's@\.pdf$@@'` |
| 80 | |
| 81 | ls "$outBase".[1-9]* >/dev/null 2>&1 && { |
| 82 | echo "$progname: Please move the following files out of the way:" >&2 |
| 83 | ls "$outBase".[1-9]* >&2 |
| 84 | exit 1 |
| 85 | } |
| 86 | |
| 87 | # restore args 1 to (n-1): |
| 88 | eval set x "$s"; shift |
| 89 | |
| 90 | # set trap for cleanup |
| 91 | trap ' |
| 92 | rm -f "$outBase".[1-9]* |
| 93 | ' 0 |
| 94 | |
| 95 | # Run dvipdfm with the fastest options for the first pass |
| 96 | echo "$progname: running dvipdfm $@ -z0 $dvifile" >&2 |
| 97 | dvipdfm ${1+"$@"} -z0 "$dvifile" |
| 98 | |
| 99 | # run gs |
| 100 | echo "$progname: running gs" >&2 |
| 101 | gs -r10 -dNOPAUSE -dBATCH -sDEVICE=png256 -sOutputFile="$outBase.%d" "$outfile" |
| 102 | |
| 103 | # run dvipdfm with the users specified options for the last pass |
| 104 | echo "$progname: running dvipdfm -t $@ $dvifile" >&2 |
| 105 | dvipdfm ${1+"$@"} -t "$dvifile" |