#!/bin/ksh93 # $Id: dvihp,v 1.3 1996/12/03 19:53:56 karl Exp karl $ typeset -r rcs_revision='$Revision: 1.4 $' typeset -r version=${rcs_revision:11:${#rcs_revision}-13} typeset -r FPROG=${.sh.file} typeset -r PROG=${FPROG##*/} SDIR=${FPROG%/*} [[ -z ${DVILJ} ]] && DVILJ='dvilj4' # the dvilj variant to run [[ -z ${SPOOL} ]] && SPOOL='lp' # used to print an LJ file TDIR=${ mktemp -t --directory ${PROG}.XXXXXX ; } [[ -z ${TDIR} ]] && print -u2 'Unable to create temp dir - exiting.' && exit 1 trap "rm -rf ${TDIR}" EXIT function showUsage { [[ -n $1 ]] && X='-?' || X='--man' getopts -a ${PROG} "${ print ${USAGE} ; }" OPT $X } # Try to accept arguments a la dvips, from Thomas Esser. USAGE='[-?'"${version}"' ] [-author?Originally written by Karl Berry.] [-author?Jens Elkner (2015 ksh93 port).] [-license?Public domain] [+NAME?'"${PROG}"' - dvi to Hewlett-Packard PCL converter] [+DESCRIPTION?Translates the given \advifile\a to Hewlett-Packard PCL by calling \bdvicopy\b(1) and then \bdvilj4\b(1) or whatever the environment variable \bDVILJ\b is set to. In the absence of other options, pipes the PCL to \blp\b or whatever the environment variable \bSPOOL\b is set to.] [+NOTE that all operands after the \advifile\a are passed to the dvilj program as is.] [h:help?Print this help and exit.] [F:functions?Print a list of all functions available.] [T:trace]:[fnList?A comma separated list of functions of this script to trace (convinience for troubleshooting).] [+?] [A?Print odd pages.] [B?Print even pages.] [d]:[num?Set debug bits to \anum\a (see documentation).] [D]:[num?Set resolution to \anum\a.] [f?Run as filter.] [l]:[num?Do not print pages after \anum\a.] [m?Manual feed.] [n]:[num?Print \anum\a pages.] [O]:[num,num?Set/change paper offset to \anum\a,\anum\a mm.] [o]:[dst?Output to \adst\a instead of spooling.] [p]:[num?Do not print pages before \anum\a.] [P]:[printer?Pass directly to the given \aprinter\a.] [V:version?Print version info and exit.] [v?Verbose operation.] [x]:[num?Set magnification to \anum\a.] [+BUGS] [+?Email bug reports to tex-k@tug.org.] \n\n[\advifile\a[\b.dvi\b] [dvilj_option ...] ' unset infile opt output output_opt='-e' integer VERBOSE=0 X="${ print ${USAGE} ; }" while getopts "${X}" OPT ; do case "${OPT}" in h) showUsage ; exit 0 ;; V) print "${PROG} (Dviljk 2.6) ${version}" \ '\nThere is NO warranty. This script is public domain.' exit 0 ;; A) opt+=' -D1';; # -A => -D1 (odd pages) B) opt+=' -D2';; # -B -> -D2 (even pages) d) opt+=" --D${OPTARG}";; # -d => --D (debug) D) opt+=" -R${OPTARG}";; # -D => -R (resolution) f) infile=; output=-;; # -f (run as filter) l) opt+=" -t${OPTARG}";; # -l => -t (ending page) m) opt+=" -A";; # -m => -A (manual feed) n) opt+=" -p${OPTARG}";; # -n => -p (page count) o) output="${OPTARG}";; # -o (output file) O) A=( ${OPTARG//,/ } ) # -O => -x, -y (page offsets) opt+=" -x${A[0]} -y${A[1]}";; p) opt+=" -f${OPTARG}";; # -p => -f (starting page) P) output=; spool_opt="-P${OPTARG}";; # -Pprinter v) VERBOSE=1; opt+=" -v";; x) opt+=" -m${OPTARG}";; # -x => -m (magnification) esac done X=$((OPTIND-1)) shift $X && OPTIND=1 unset X [[ -z $1 ]] && showUsage 1 && exit 1 infile="$1" [[ -e ${infile} ]] || print -u2 "${file} does not exist - exiting." && exit 2 shift opt+=" $@" # Make sure the filenames are unique on MS-DOS vfless_dvi="${TDIR}/dvi$$.vf" # Expand VF references. # If $infile is null, this will read standard input. # dvilj can't read from a pipe, so always write to a file. (( VERBOSE )) && print -u2 "Running dvicopy ${infile} >${vfless_dvi}" if ! dvicopy ${infile} >"${vfless_dvi}"; then print -u2 "${PROG}: dvicopy ${infile} failed." exit 1 fi (( VERBOSE )) && ls -l "${vfless_dvi}" >&2 if [[ -z ${output} ]]; then output=- # output to stdout # Doing this pipe means the true exit status might get lost, but it # seems worth it to avoid the temporary file. (Bad enough to have one.) maybe_spool_cmd="| ${SPOOL} ${spool_opt}" else maybe_spool_cmd= fi # Translate DVI to LJ. CMD="${DVILJ} ${opt} ${output_opt} ${output} \"${vfless_dvi}\" ${maybe_spool_cmd}" (( VERBOSE )) && print -u2 "Running ${CMD}" ${CMD} || { print -u2 "${PROG}: ${DVILJ} failed." ; exit 2 ; }