Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Oct 1997 11:43:49 -0400
From:      "Doug Kite" <dkite@co.lenoir.nc.us>
To:        freebsd-questions@freebsd.org
Subject:   input filter for lp
Message-ID:  <199710061124.LAA06264@ns.co.lenoir.nc.us>

next in thread | raw e-mail | index | archive | help
How do I get a script I have written to act as an input filter for 
lpd? I have written a script in awk that checks the width of the file 
on standard input and sends the proper initialization sequence for 
the printer.  

The script is working fine, and I can type:
ls -l | lpfilter         or        cat foo | lpfilter 
and the codes are inserted properly, but...

Even though I put an entry in my printcap file that lists my script as
the input filter, it does not execute when I print a file. I know the
script works, and does what I want, but I can't get it to execute
automatically when something is printed.

Any thoughts would be appreciated.

Doug

Here's the /etc/printcap entry:
lp|hp|hp4v|HP Laserjet 4V|\
 :sd=/var/spool/lpd/hp:\
 :rm=192.168.0.15:\
 :rp=text:\
 :lp=:\
 :if=/usr/bin/lpfilter:\
 :lf=/var/log/lpd-errs:\
 :sh:

And here is the lpfilter script:
#!/usr/bin/awk -f
 # Add printer setup codes to first long line
 # \x1B - ESC (ASCII 027, HEX 1B)
 # &l1o5.369C - orientation landscape, vertical motion index
 # (s12.5H - pitch 12.5
 # first part of P sets font to courier, pitch 10, symbol set PC-8
 # &l0o7.183C - orientation portrait, vertical motion index
 # %s - the string (the original line, $0)
 # \n - newline
BEGIN { W = 0
 I = "\x1B&l1o5.369C\x1B(s12.5H"
 P = "\x1B(10U\x1B(s0p10h0s0b4099T\x1B&l0o7.183C"
 }
{ if (W == 0 && length > 85) {
 if (index($0,"\x0C") != 0) {
  split($0,p,"\x0C")
  printf("%s\x0C%s%s\n",p[1],I,p[2])
 }
 else { printf("%s%s\n",I,$0) }
 W = 1
 }
else {
 { if (NR == 1) {
  printf("%s%s\n",P,$0)
  }
 else { print $0 }
 }
 }
 }
__________________________________________________
Doug Kite            email: dkite@co.lenoir.nc.us
Network Administrator         phone: 919-559-6442
Lenoir County MIS               fax: 919-523-0371



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199710061124.LAA06264>