1: #!/bin/ksh 2: # 3: # Wrapper script for postprint on Solaris 4: # 5: # Pass files through the Solaris postprint utility, 6: # but only if they are not already postscript. 7: # Output is then piped directly to lp or lpr 8: # 9: # We do not process any files unless a default printer 10: # has been selected. The search list is $LPDEST, 11: # $PRINTER, the _default line in $HOME/.printers 12: # A printer may also be specified by option "-P printer" 13: # 14: # Any other options are passed on to postprint. 15: # This script knows about the postprint # options so 16: # it can skip over them and get to the filenames 17: # 18: # PROBLEMS 19: # - cat multiple postscript files into lpr is NOT 20: # the same as passing multiple filenames to postprint 21: # and piping the output to lpr. Postprint only generates 22: # one header, then multiple sets of data. 23: # This is why we need to insert each named file into 24: # the print queue directly. 25: # 26: # 2003/10/24 RB 27: 28: # Gather up the program options. 29: ppopts= 30: printer= 31: while getopts :c:f:l:m:n:o:p:r:s:t:x:y:P: opt 32: do 33: case $opt in 34: P) 35: printer=$OPTARG ;; 36: @(c|f|l|m|n|o|p|r|s|t|x|y)) 37: ppopts="${ppopts} -${opt}$OPTARG" ;; 38: :) 39: print -u2 "$0: option \"-$OPTARG\" requires a value" 40: exit 2 ;; 41: \?) 42: print -u2 "$0: no such option \"-$OPTARG\"" 43: exit 2 ;; 44: esac 45: done 46: shift OPTIND-1 47: 48: # Make sure we have a preferred printer set 49: # - don't rely on a system default. 50: printer=${printer:-$LPDEST} 51: printer=${printer:-$PRINTER} 52: printer=${printer:-$(grep '^_default' $HOME/.printers 2>/dev/null|awk '{print $2}')} 53: if [[ -z "$printer" ]]; then 54: print -u2 "$0: no preferred printer detected in LPDEST, PRINTER or .printers file" 55: exit 3 56: fi 57: 58: # Command to put stdin into the print queue. 59: # Use lpr rather than lp because it is less chatty 60: # printcmd="/usr/bin/lp -d$printer" 61: printcmd="/usr/ucb/lpr -P$printer" 62: 63: # Command to convert plain text to postscript. 64: # Use full path, since postprint, isn't in the path 65: ppcmd="/usr/lib/lp/postscript/postprint $ppopts" 66: 67: if [[ $# -gt 0 ]]; then 68: # we have one or more filenames on the command line 69: print -u2 -n "$0: sending to $printer: " 70: for file in "$@"; do 71: if [[ -f $file && -r $file ]]; then 72: # we have a real file 73: print -u2 -n "$file " 74: read line < $file 75: case $line in 76: %!*) cat $file | $printcmd ;; 77: *) $ppcmd $file | $printcmd ;; 78: esac 79: elif [[ $file = "-" ]]; then 80: # process stdin 81: print -u2 -n "(stdin) " 82: read line 83: case $line in 84: %!*) ( print -R $line; cat; ) | $printcmd ;; 85: *) ( print -R $line; cat; ) | $ppcmd | $printcmd ;; 86: esac 87: else 88: # invalid filename specified - non-fatal error; process remaining files 89: print -u2 "\n$0: invalid filename \"$file\" -- skipping" 90: continue 91: fi 92: done 93: print -u2 94: else 95: # no filenames specified -- process stdin 96: read line 97: case $line in 98: %!*) ( print -R $line; cat; ) | $printcmd ;; 99: *) ( print -R $line; cat; ) | $ppcmd | $printcmd ;; 100: esac 101: fi 102: 103: exit 0
last modified 22/03/2012 | Introduction | Table of Contents (frame/no frame) |
Printable (single file) |
© Dartmouth College |