*BSD News Article 45305


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!msunews!agate!howland.reston.ans.net!xlink.net!zib-berlin.de!news.tu-chemnitz.de!irz401!narcisa.sax.de!not-for-mail
From: j@narcisa.sax.de (J Wunsch)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: Can't get printer to work correctly
Date: 12 Jun 1995 12:03:27 +0200
Organization: Private U**x site, Dresden.
Lines: 208
Message-ID: <3rh3df$lsm@bonnie.tcd-dresden.de>
References: <3plcn3$e68@agate.berkeley.edu> <3qfedi$e4g@bonnie.tcd-dresden.de> <3r8trg$lts@agate.berkeley.edu>
Reply-To: joerg_wunsch@uriah.heep.sax.de
NNTP-Posting-Host: 192.109.108.139
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit

Geordan Rosario <geordan@OCF.Berkeley.EDU> wrote:

>>RTFM printcap(5) for an explanation on how the various lpd filters
>>work.
>>
>I did go through printcap's man page quite a few times, and I still don't have
>filters straight.

Well, i didn't say it's the best explanation i could imagine of. :-)
It required me to perform a few trial-and-error steps as well...  (and
finally, after wondering why it didn't work, and looking up the
source, i found that there has been a bug in the old lpd sources :-).

>Could you give me an example on using pr as the filter?

`pr' is the easiest, since it's a built-in filter (from the `-p'
option to lpr).  Anyway, here are parts of my configuration:

lp|lp12|Standard line printer 12 cpi:\
	:if=/root/lpr/textfilter:lf=/var/log/lpd-errs:\
	:tf=/root/lpr/psfilter:\
	:df=/root/lpr/dvifilter:\
	:vf=/root/lpr/dummyfilter:\
	:sh:lp=/dev/lpt0:pl#96:pw#96:px#1440:py#2100:
lq|Letter quality printer:\
	:if=/root/lpr/textfilter:lf=/var/log/lpd-errs:\
	:tf=/root/lpr/psfilter:\
	:df=/root/lpr/dvifilter:\
	:vf=/root/lpr/dummyfilter:\
	:sh:lp=/dev/lpt0:pl#72:pw#80:px#2880:py#4200:
...

...quite a bunch more printers, which are all different in their
resolution values (but refer to the same physical printer).

The `dummyfilter' is a plain `cat', just needed to make `lpr -v' the
same as `lpr -l' (some FTP software client missed the `-l' flag).

The most complicated is the `textfilter':

#!/bin/sh
#
# Textfilter (`if' printcap entry) for lpd service
#
PATH=/bin:/usr/bin

USAGE="usage: textfilter [-c] -w width -l length -i indent -n login -h host [acc
tfile]"
COPT=0
WIDTH=-1
LENGTH=-1
INDENT=-1
LOGIN=""
HOST=""
ACCTFILE=""
phase="opts"
remjob="false"

###echo "$*" 1>&2

set -- `getopt cw:l:i:n:h: $*`

if [ $? != 0 ] ; then
        echo $USAGE 1>&2
        exit 2
fi


for i in $*
do
        case $i in
        -c)
                COPT=1
                shift
                ;;

        -w)
                WIDTH=$2
                shift 2
                ;;

        -l)
                LENGTH=$2
                shift 2
                ;;

        -i)
                INDENT=$2
                shift 2
                ;;

        -n)
                LOGIN="$2"
                shift 2
                ;;

        -h)
                HOST="$2"
                shift 2
                ;;

        --)
                phase="posargs"
                shift
                ;;

        esac
done

if [ -z "$LOGIN" -o -z "$HOST" -o $phase != posargs -o $# -gt 1 ] ; then
        echo $USAGE 1>&2
        exit 2
fi

if [ $# -eq 1 ] ; then
        ACCTFILE=$*
fi

#if [ `hostname` != "$HOST" ] ; then
#       remjob="true"
#       echo "\n\n\n\n"
#       echo "*** Remote lpd job @ `hostname` on `date`  ***\n\n\n\n"
#       banner $LOGIN; echo "\n\n\n\n\n"
#       banner "   @"; echo "\n\n\n\n\n"
#       banner $HOST; echo
#       echo -n "\f"
#fi

###     echo "COPT=$COPT, WIDTH=$WIDTH, LENGTH=$LENGTH, INDENT=$INDENT, \
###LOGIN=$LOGIN, HOST=$HOST, ACCTFILE=$ACCTFILE" 1>&2
###exit 0

if [ $COPT -eq 1 ] ; then
        # simply shortcut it
        cat
else
        echo -n "^[@"
        if [ -n "$INDENT" -a $INDENT -ne 0 ] ; then
                awk 'BEGIN {printf "\033l%c", '$INDENT'; exit}'
        fi

        if [ -n "$LENGTH" ] ; then
                if [ $LENGTH -le 72 ] ; then
                        echo -n "^[2"
                        # assume user wants to pretty-print
                        echo -n "^[P^[k0^[x1"
                else
                        echo -n "^[x0"
                        if [ $LENGTH -le 96 ] ; then
                                echo -n "^[0"
                        fi
                fi
        else
                # default: 8 lpi
                echo -n "^[0"
        fi
        if [ -n "$WIDTH" ] ; then
                if [ $WIDTH -le 80 ] ; then
                        # 10 cpi
                        echo -n "^[P"
                elif [ $WIDTH -le 96 ] ; then
                        # 12 cpi
                        echo -n "^[M"
                elif [ $WIDTH -le 120 ] ; then
                        # 15 cpi
                        echo -n "^[g"
                else
                        # 20 cpi
                        echo -n "^[M^O"
                fi
        else
                # default: 12 cpi
                echo -n "^[M"
        fi

        # iso8859 ==> ibm437
        #iso2ibm
        tr '\344\366\374\304\326\334\337\361\321\341\351\355\363\372\277\241' \
           '\204\224\201\216\231\232\341\244\245\240\202\241\242\243\250\255'
fi


The escape sequences (with ESC transliterated to ^[ for Usenet's sake)
are used to initialize an Epson SQ-870 printer to the desired
resolution.  The final `tr' translates some of the ISO-8859-1 codes
into IBM codepage 437.

The bypass via $COPT is the `-l' flag.

Here are finally the bottom few lines from the `psfilter' (which is
invoked via `lpr -t', normally reserved for troff -- i agree that
something like `apsfilter' is a better solution at all):

if [ $WIDTH -gt 1440 ]  # 1440 pixels is 8" * 180 dpi,
then                    # 2880 pixels is 8" * 360 dpi
        gs -sOUTPUTFILE=- -sDEVICE=escp2 -dQUIET -dNOPAUSE -dSAFER - quit.ps
else
        gs -sOUTPUTFILE=- -sDEVICE=epson -dQUIET -dNOPAUSE -dSAFER - quit.ps
fi

(Well, i realize that my scripts are using getopt(1).  This is not
provided as a standard utility, and new implementations should use
getopts(1) instead, which is a shell builtin.)
-- 
cheers, J"org                      private:   joerg_wunsch@uriah.heep.sax.de
                                   http://www.sax.de/~joerg/

Never trust an operating system you don't have sources for. ;-)