| 1 | #!/bin/sh |
| 2 | # $Id: dvihp,v 1.3 1996/12/03 19:53:56 karl Exp karl $ |
| 3 | # Run dvicopy, then dvilj[k]. Originally written by Karl Berry. |
| 4 | # Public domain. |
| 5 | # Try to accept arguments a la dvips, from Thomas Esser. |
| 6 | |
| 7 | : ${DVILJ=dvilj4} # the dvilj variant to run |
| 8 | : ${SPOOL=lpr} # used to print an LJ file |
| 9 | |
| 10 | tmpdir=`mktemp -d` \ |
| 11 | || { echo "cannot create directory \`$tmpdir'."; exit 1; } |
| 12 | |
| 13 | trap ' |
| 14 | test -d "$tmpdir" && { rm -f "$tmpdir"/*; rmdir "$tmpdir"; } |
| 15 | exit 0 |
| 16 | ' 0 1 2 3 6 7 13 15 |
| 17 | |
| 18 | rcs_revision='$Revision: 1.3 $' |
| 19 | version=`set - $rcs_revision; echo $2` |
| 20 | |
| 21 | usage="Usage: `basename $0` [OPTIONS] [DVIFILE[.dvi]]. |
| 22 | Translate the given DVIFILE to Hewlett-Packard PCL by calling dvicopy |
| 23 | and then \$DVILJ (dvilj4 by default). |
| 24 | In the absence of other options, pipe the PCL to \$SPOOL (lpr by default). |
| 25 | |
| 26 | Options are recognized from dvips where possible: |
| 27 | -A print odd pages |
| 28 | -B print even pages |
| 29 | -d # set debug bits to # (see documentation) |
| 30 | -D # set resolution to # |
| 31 | -f run as filter |
| 32 | -l # don't print pages after # |
| 33 | -m manual feed |
| 34 | -n # print # pages |
| 35 | -O #,# set/change paper offset to #,# mm |
| 36 | -o s output to s instead of spooling |
| 37 | -p # don't print pages before # |
| 38 | -Ps pass directly to lpr |
| 39 | -v verbose operation |
| 40 | -x # set magnification to # |
| 41 | |
| 42 | Other options are passed to the dvilj program. |
| 43 | |
| 44 | Email bug reports to [email protected]." |
| 45 | |
| 46 | |
| 47 | if test $# -eq 0; then |
| 48 | echo "`basename $0`: Missing argument(s)." >&2 |
| 49 | echo "Try \``basename $0` --help' for more information." >&2 |
| 50 | exit 0 |
| 51 | fi |
| 52 | |
| 53 | unset infile opt output |
| 54 | output_opt=-e |
| 55 | verbose=false |
| 56 | |
| 57 | while test $# -gt 0; do |
| 58 | case "$1" in |
| 59 | -help|--help) echo "$usage"; exit 0;; |
| 60 | -version|--version) |
| 61 | echo "`basename $0` (Dviljk 2.6) $version" |
| 62 | echo "There is NO warranty. This script is public domain." |
| 63 | exit 0;; |
| 64 | -A) opt="$opt -D1";; # -A => -D1 (odd pages) |
| 65 | -B) opt="$opt -D2";; # -B -> -D2 (even pages) |
| 66 | -d) shift; opt="$opt --D$1";; # -d => --D (debug) |
| 67 | -d*) opt="$opt `echo $1 | sed s/d/-D/`";; |
| 68 | -D) shift; opt="$opt -R$1";; # -D => -R (resolution) |
| 69 | -f) infile=; output=-;; # -f (run as filter) |
| 70 | -l) shift; opt="$opt -t$1";; # -l => -t (ending page) |
| 71 | -l*) opt="$opt `echo $1 | sed s/l/t/`";; |
| 72 | -m) opt="$opt -A";; # -m => -A (manual feed) |
| 73 | -n) shift; opt="$opt -p$1";; # -n => -p (page count) |
| 74 | -n*) opt="$opt `echo $1 | sed s/^-n/-p/`";; |
| 75 | -o) if test $# -eq 1; then # -o (output file) |
| 76 | # No remaining args, output to foo.lj. |
| 77 | output=`basename $infile .dvi`.lj |
| 78 | else shift; output="$1"; fi;; |
| 79 | -o*) output="`echo $1 | sed 's/^-o//'`";; |
| 80 | -O) shift; x=`echo $1 | sed 's/,.*//'` # -O => -x, -y (page offsets) |
| 81 | y=`echo $1 | sed 's/.*,//'`; opt="$opt -x$x -y$y";; |
| 82 | -O*) temp="`echo $1 | sed 's/^-O//'`" |
| 83 | x=`echo $temp | sed 's/,.*//'` |
| 84 | y=`echo $temp | sed 's/.*,//'`; |
| 85 | opt="$opt -x$x -y$y";; |
| 86 | -p) shift; opt="$opt -f$1";; # -p => -f (starting page) |
| 87 | -p*) opt="$opt `echo $1 | sed s/p/f/`";; |
| 88 | -P) shift; output=; spool_opt="-P$1";; # -Pprinter |
| 89 | -P*) output=; spool_opt="$1";; |
| 90 | -v) verbose=true; opt="$opt -v";; |
| 91 | -x) shift; opt="$opt -m$1";; # -x => -m (magnification) |
| 92 | -x*) opt="$opt `echo $1 | sed s/x/m/`";; |
| 93 | --) shift; infile="$1"; break;; # -- => end of options |
| 94 | -*) opt="$opt $1";; # pass other options through |
| 95 | *) infile="$1";; |
| 96 | esac |
| 97 | shift |
| 98 | done |
| 99 | |
| 100 | # Make sure the filenames are unique on MS-DOS |
| 101 | vfless_dvi="$tmpdir"/dvi$$.vf |
| 102 | |
| 103 | # Expand VF references. |
| 104 | # If $infile is null, this will read standard input. |
| 105 | # dvilj can't read from a pipe, so always write to a file. |
| 106 | $verbose && echo "Running dvicopy $infile >$vfless_dvi" >&2 |
| 107 | if dvicopy $infile >"$vfless_dvi"; then :; else |
| 108 | echo "$0: dvicopy $infile failed." >&2 |
| 109 | exit 1 |
| 110 | fi |
| 111 | $verbose && ls -l "$vfless_dvi" >&2 |
| 112 | |
| 113 | if test -z "$output"; then |
| 114 | output=- # output to stdout |
| 115 | # Doing this pipe means the true exit status might get lost, but it |
| 116 | # seems worth it to avoid the temporary file. (Bad enough to have one.) |
| 117 | maybe_spool_cmd="| $SPOOL $spool_opt" |
| 118 | else |
| 119 | maybe_spool_cmd= |
| 120 | fi |
| 121 | |
| 122 | # Translate DVI to LJ. |
| 123 | cmd="$DVILJ $opt $output_opt$output \"$vfless_dvi\" $maybe_spool_cmd" |
| 124 | $verbose && echo "Running $cmd" >&2 |
| 125 | if eval $cmd; then :; else |
| 126 | echo "$0: $DVILJ failed." >&2 |
| 127 | exit 2 |
| 128 | fi |