#! /bin/ksh usage1="Usage: ${0##*/} [-h] [-D dateformat] [-P printer] [-N copies] [-J job] file ..." usage2=' Options: -h no header lines -P printer ) -N copies ) same as in lpr command (N -> #) -J job ) -D date format date format for header line (see man date) -v print command (not yet implemented) -n do not execute command (not yet implemented) ' # Defaults: tmpfile=${TMPDIR-/tmp}/prt$$ job="${J-H.Richter}" printer="${P-og2_dx}" dateformat="${D-%Y-%m-%d}" while getopts hP:#:J: option do case "$option" in [hvn]) flags="$flags$option";; [?]) echo "$usage1" 1>&2 exit 2;; *) eval "$option='$OPTARG'";; esac done shift $(($OPTIND-1)) if [[ $# -eq 0 ]] then cat >$tmpfile.txt firstline=`head -1 $tmpfile.txt` case "$firstline" in %!PS-Adobe*) mv $tmpfile.txt $tmpfile.ps set $tmpfile.ps;; *) set $tmpfile.txt;; esac fi for file do filen=${file##*/} printed=0 case $filen in *.?*) case ${filen##*.} in ps) lpr -P"$printer" -#"${N-1}" -J"$job" "$file" printed=1;; dvi) dvips -o $tmpfile "$file" lpr -P"$printer" -#"${N-1}" -J"$job" $tmpfile printed=1;; esac esac if [[ $printed -eq 0 ]] then if grep -Fq ' ' $file then expand <"$file" >$tmpfile data=$tmpfile else data="$file" fi if grep -Evq '^.{0,80}$' "$data" then if grep -Evq '^.{0,88}$' "$data" then if grep -Evq '^.{0,99}$' "$data" then format=" -r" else format=" -s 8" fi else format=" -s 9" fi else format=" -s 10" fi case "$flags" in *h*) format=" -h$format" esac i2ps$format -b "$file `date +$dateformat`" "$data" | lpr -P"$printer" -#"${N-1}" -J"$job" fi if [[ -f $tmpfile ]] then rm $tmpfile fi done if [[ -f $tmpfile.txt ]] then rm $tmpfile.txt fi if [[ -f $tmpfile.ps ]] then rm $tmpfile.ps fi