Subject: Re: print postscript file under HP 5L
To: None <c5666305@b1.hkstar.com>
From: John Kohl <jtk@kolvir.arlington.ma.us>
List: current-users
Date: 10/30/1998 07:44:02
I've attached a small shar file with my home-grown printcap hacks and
filters for my HP DeskJet 500. They should be adaptable to the HP 5L.
==John Kohl <jtk@kolvir.arlington.ma.us>, <john_kohl@alum.mit.edu>
# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# README
# Makefile
# djdvipf.sh
# djpspf.sh
# djlpf.c
# sample.printcap
# quiet.ps
#
echo x - README
sed 's/^X//' >README << 'END-of-README'
XThis is the set of print filters I use on my HP DeskJet 500 on my
Xi386 machine at home. I've used the filters for over a year without
Xproblems.
X
X'lpr -d' prints TeX DVI output
X'lpr -c' prints PostScript output
X'lpr' prints out text output
X
XTo install: type "make", then "make install"
X
XPut quiet.ps into your GhostScript inputs directory.
X(perhaps /usr/local/share/ghostscript/5.01). Get Ghostscript from the
XNetBSD packages collection.
X
XEdit your printcap appropriately (see sample.printcap)
X
XEnjoy!
X
X==John Kohl <jtk@kolvir.arlington.ma.us>
END-of-README
echo x - Makefile
sed 's/^X//' >Makefile << 'END-of-Makefile'
X# $Source: /u1/local/packages/djlpf/RCS/Makefile,v $
X# $Author: jtk $
X# $Id: Makefile,v 1.5 1998/10/08 03:20:01 jtk Exp $
X#
X
XPROG= djlpf
XLINKS= $(BINDIR)/djlpf $(BINDIR)/djlqpf
XNOMAN= noman
XBINDIR= /usr/libexec/lpr
X
XSCRIPTS= djdvipf.sh djpspf.sh
X
X.include <bsd.prog.mk>
END-of-Makefile
echo x - djdvipf.sh
sed 's/^X//' >djdvipf.sh << 'END-of-djdvipf.sh'
X#!/bin/sh
X# $Source: /u4/u1/local/packages/djlpf/RCS/djdvipf.sh,v $
X# $Author: jtk $
X# $Id: djdvipf.sh,v 1.7 1998/10/08 03:15:57 jtk Exp $
X#
X/usr/pkg/bin/dvips -r -q -f | /usr/pkg/bin/gs -sDEVICE=djet500 -q -dNOPAUSE -sOUTPUTFILE=/dev/stdout quiet.ps -
END-of-djdvipf.sh
echo x - djpspf.sh
sed 's/^X//' >djpspf.sh << 'END-of-djpspf.sh'
X#!/bin/sh
X# $Source: /u4/u1/local/packages/djlpf/RCS/djpspf.sh,v $
X# $Author: jtk $
X# $Id: djpspf.sh,v 1.6 1998/10/08 03:16:10 jtk Exp $
X#
X/usr/pkg/bin/gs -sDEVICE=djet500 -q -dNOPAUSE -sOUTPUTFILE=/dev/stdout quiet.ps -
END-of-djpspf.sh
echo x - djlpf.c
sed 's/^X//' >djlpf.c << 'END-of-djlpf.c'
X/*
X * $Source: /u4/u1/local/packages/djlpf/RCS/djlpf.c,v $
X * $Author: jtk $
X * $Id: djlpf.c,v 1.10 1998/10/08 03:17:49 jtk Exp $
X */
X
X#ifndef lint
Xstatic
X#ifdef __STDC__
Xconst
X#endif
Xchar rcsid_djlpf_c[] = "$Id: djlpf.c,v 1.10 1998/10/08 03:17:49 jtk Exp $";
X#endif /* lint */
X
X/*
X * Copyright (c) 1983 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X * notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X * notice, this list of conditions and the following disclaimer in the
X * documentation and/or other materials provided with the distribution.
X * 3. All advertising materials mentioning features or use of this software
X * must display the following acknowledgement:
X * This product includes software developed by the University of
X * California, Berkeley and its contributors.
X * 4. Neither the name of the University nor the names of its contributors
X * may be used to endorse or promote products derived from this software
X * without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X */
X
X#ifndef lint
Xchar copyright[] =
X"@(#) Copyright (c) 1983 Regents of the University of California.\n\
X All rights reserved.\n";
X#endif /* not lint */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)lpf.c 5.4 (Berkeley) 6/1/90";
X#endif /* not lint */
X
X/*
X * filter which reads the output of nroff and converts lines
X * with ^H's to overwritten lines. Thus this works like 'ul'
X * but is much better: it can handle more than 2 overwrites
X * and it is written with some style.
X * modified by kls to use register references instead of arrays
X * to try to gain a little speed.
X */
X/*
X * Hacked to pieces by John Kohl <jtk@kolvir.blrc.ma.us> to
X * convert into fancy filter for Hewlett-Packard DeskJet 500
X * (should also work for other HP PCL printers, except perhaps
X * for the 'text scale' thing below (see portrait code below)
X
X(much of the text width/length stuff inspired by printcap hackery from
X blknowle@frodo.jdssc.dca.mil (Brad L. Knowles)
X */
X
X#include <stdio.h>
X#include <stdlib.h>
X#include <string.h>
X#include <signal.h>
X#include <unistd.h>
X
X#ifndef MIN
X#define MIN(a,b) ((a) < (b) ? (a) : (b))
X#endif
X
X#define MAXWIDTH 210
X#define MAXREP 10
X
Xchar buf[MAXREP][MAXWIDTH];
Xint maxcol[MAXREP] = {-1};
Xint lineno;
Xint width = 132; /* default line length */
Xint length = 66; /* page length */
Xint indent; /* indentation length */
Xint npages = 0;
Xint literal; /* print control characters */
Xchar *name; /* user's login name */
Xchar *host; /* user's machine name */
Xchar *acctfile; /* accounting information file */
X
Xmain(argc, argv)
X int argc;
X char *argv[];
X{
X register FILE *p = stdin, *o = stdout;
X register int i, col;
X register char *cp;
X int opt;
X int done, linedone, maxrep;
X char ch, *limit;
X int lq;
X
X#define NAME argv[0]
X
X /* look at NAME to select anything weird */
X if (cp = strrchr(NAME, '/'))
X cp++;
X else
X cp = NAME;
X if (!strcmp(cp, "djlqpf")) /* LQ == letter quality */
X lq = 1;
X else
X lq = 0;
X
X while ((opt = getopt(argc, argv, "n:h:w:l:i:c")) != EOF)
X switch(opt) {
X case 'n':
X name = optarg;
X break;
X case 'h':
X host = optarg;
X break;
X case 'w':
X i = atoi(optarg);
X if (i > 0) {
X i = MIN(i, MAXWIDTH);
X width = i;
X }
X break;
X case 'l':
X length = atoi(optarg);
X break;
X case 'i':
X indent = atoi(optarg);
X break;
X case 'c': /* Print control chars */
X literal++;
X break;
X }
X argc -= optind;
X argv += optind;
X if (argc)
X acctfile = argv[0];
X
X for (cp = buf[0], limit = buf[MAXREP]; cp < limit; *cp++ = ' ');
X done = 0;
X
X /* preamble: send init string to printer to put into
X our preferred font mode.
X ESC E reset
X */
X
X fputs("\033E", o);
X if (literal) {
X /* if we're being literal, just send the output along */
X char line[BUFSIZ];
X int cc;
X npages++; /* give up on counting... */
X while ((cc = fread(line, sizeof(*line), sizeof(line)/sizeof(*line), p)) > 0) {
X fwrite(line, sizeof(*line), cc, o);
X }
X } else {
X
X
X if (length == 48) {
X /* ESC &l1O landscape */
X /* ESC &l6D 6 li/in */
X /* ESC &l48P 48 li/pg */
X /* ESC &l0L perf skip off */
X fputs("\033&l1o6d48p0L",o);
X if (width <= 51)
X fputs("\033(s5H",o); /* 5 CPI=52 cols */
X else if (width > 51 && width <= 103)
X /* nothing; printer default is 10 CPI */;
X else if (width > 103 && width <= 172)
X fputs("\033(s16.67H",o); /* 16.67 CPI = 172 cols */
X else
X fputs("\033(s20H",o); /* 20 CPI = 210 cols */
X } else {
X /* ESC &l0O portrait */
X /* ESC &l6D 6 li/in */
X /* ESC &l66P 66 li/pg */
X /* ESC &l0L perf skip off */
X /* ESC &k6W text scaling mode to squeeze 66
X lines onto page */
X fputs("\033&l0o7D",o);
X if (length > 48 && length < 66)
X /* can't fit more than 66 in portrait mode */
X fprintf(o, "\033&l%dP", length);
X else
X fputs("\033&l66P", o);
X fputs("\033&l0L", o);
X if (length > 63)
X fputs("\033&k6W",o); /* text scaling mode */
X
X if (width <= 40)
X fputs("\033(s5H",o); /* 5 CPI=40 cols */
X else if (width > 40 && width <= 80)
X /* nothing; printer default is 10 CPI */;
X else if (width > 80 && width <= 96)
X fputs("\033(s12h6T",o); /* 12 CPI = 96 cols;
X use Letter Gothic */
X else if (width > 96 && width <= 132)
X fputs("\033(s16.67H",o); /* 16.67 CPI = 132 cols */
X else
X fputs("\033(s20H",o); /* 20 CPI = 160 cols */
X }
X /* ESC &k2G carriage control (lf=crlf, cr=cr, ff=crff) */
X fputs("\033&k2G", o);
X
X if (lq)
X fputs("\033(s2Q",o); /* ESC (s2Q letter quality mode */
X else {
X /* ESC (s1Q draft quality mode */
X /* ESC &k1W bidirectional (draft only) */
X fputs("\033(s1Q\033&k1W",o);
X }
X
X while (!done) {
X col = indent;
X maxrep = -1;
X linedone = 0;
X while (!linedone) {
X switch (ch = getc(p)) {
X case EOF:
X linedone = done = 1;
X ch = '\n';
X break;
X
X case '\f':
X lineno = length;
X case '\n':
X if (maxrep < 0)
X maxrep = 0;
X linedone = 1;
X break;
X
X case '\b':
X if (--col < indent)
X col = indent;
X break;
X
X case '\r':
X col = indent;
X break;
X
X case '\t':
X col = ((col - indent) | 07) + indent + 1;
X break;
X
X default:
X if (col >= width || !literal && ch < ' ') {
X col++;
X break;
X }
X cp = &buf[0][col];
X for (i = 0; i < MAXREP; i++) {
X if (i > maxrep)
X maxrep = i;
X if (*cp == ' ') {
X *cp = ch;
X if (col > maxcol[i])
X maxcol[i] = col;
X break;
X }
X cp += MAXWIDTH;
X }
X col++;
X break;
X }
X }
X
X /* print out lines */
X for (i = 0; i <= maxrep; i++) {
X for (cp = buf[i], limit = cp+maxcol[i]; cp <= limit;) {
X putc(*cp, o);
X *cp++ = ' ';
X }
X if (i < maxrep)
X putc('\r', o);
X else
X putc(ch, o);
X if (++lineno >= length) {
X fflush(o);
X npages++;
X lineno = 0;
X }
X maxcol[i] = -1;
X }
X }
X if (lineno && !literal) {
X /* be sure to end on a page boundary */
X putchar('\f');
X npages++;
X }
X }
X if (name && acctfile && access(acctfile, 02) >= 0 &&
X freopen(acctfile, "a", stdout) != NULL) {
X printf("%7.2f\t%s:%s\n", (float)npages, host, name);
X }
X exit(0);
X}
END-of-djlpf.c
echo x - sample.printcap
sed 's/^X//' >sample.printcap << 'END-of-sample.printcap'
X# $Source: /u1/NetBSD-1.0/src/local/etc/RCS/printcap,v $
X# $Author: jtk $
X# $Id: printcap,v 1.16 1994/08/12 03:06:30 jtk Exp $
X#
X
X# Inspired by: Brad Knowles <blknowle@frodo.jdssc.dca.mil>
X
X##------ HP DeskJet Plus attached to this machine on Parallel port 0
X
Xgeneric_dphp|Draft Hewlett-Packard DeskJet 500 on Parallel Port 0:\
X :lp=/dev/lpa0np:\
X :sd=/var/spool/lpd:lf=/var/log/lpd-errs:sh:\
X :df=/usr/libexec/lpr/djdvipf:\
X :cf=/usr/libexec/lpr/djpspf:\
X :af=/var/account/lp.printacct:\
X :if=/usr/libexec/lpr/djlpf:
X
Xgeneric_php|Hewlett-Packard DeskJet on Parallel Port 0:\
X :lp=/dev/lpa0np:\
X :sd=/var/spool/lpd:lf=/var/log/lpd-errs:sh:\
X :df=/usr/libexec/lpr/djdvipf:\
X :cf=/usr/libexec/lpr/djpspf:\
X :af=/var/account/lp.printacct:\
X :if=/usr/libexec/lpr/djlqpf:
X#
X# recursive tc= would make this all work better...
X#
Xlq|hp|dj|Hewlett-Packard DeskJet (Portrait, 80 Columns):\
X :pw#80:\
X :pl#63:\
X :tc=generic_php:
X#
Xlqg|hpg|djg|Hewlett-Packard DeskJet (Portrait, 96 Columns/Letter Gothic):\
X :pw#96:\
X :pl#63:\
X :tc=generic_php:
X#
Xlqw|hpw|djw|Hewlett-Packard DeskJet (Portrait, 132 Columns):\
X :pw#132:\
X :pl#63:\
X :tc=generic_php:
X#
Xlqew|hpew|djew|Hewlett-Packard DeskJet (Portrait, 160 Columns):\
X :pw#160:\
X :pl#63:\
X :tc=generic_php:
X#
Xlqn|hpn|djn|Hewlett-Packard DeskJet (Portrait, 40 Columns):\
X :pw#40:\
X :pl#63:\
X :tc=generic_php:
X#
Xllq|lhp|ldj|Hewlett-Packard DeskJet (Landscape, 103 columns):\
X :pw#103:\
X :pl#48:\
X :tc=generic_php:
X#
Xllqw|lhpw|ldjw|Hewlett-Packard DeskJet (Landscape, 172 Columns):\
X :pw#172:\
X :pl#48:\
X :tc=generic_php:
X#
Xllqew|lhpew|ldjew|Hewlett-Packard DeskJet (Landscape, 210 Columns):\
X :pw#210:\
X :pl#48:\
X :tc=generic_php:
X#
Xllqn|lhpn|ldjn|Hewlett-Packard DeskJet (Landscape, 51 Columns):\
X :pw#51:\
X :pl#48:\
X :tc=generic_php:
X#
X#portrait:\
X# :pl#66:\
X# :tc=generic_php:
X#landscape:\
X# :pl#48:\
X# :tc=generic_php:
X
X#### >>> this is the the default printer:
Xlp|dhp|ddj|Draft Hewlett-Packard DeskJet (Portrait, 80 Columns):\
X :pw#80:\
X :pl#63:\
X :tc=generic_dphp:
X#
Xlpg|dhpg|ddjg|Hewlett-Packard DeskJet (Portrait, 96 Columns/Letter Gothic):\
X :pw#96:\
X :pl#63:\
X :tc=generic_dphp:
X#
Xlpw|dhpw|ddjw|Draft Hewlett-Packard DeskJet (Portrait, 132 Columns):\
X :pw#132:\
X :pl#63:\
X :tc=generic_dphp:
X#
Xlpew|dhpew|ddjew|Draft Hewlett-Packard DeskJet (Portrait, 160 Columns):\
X :pw#160:\
X :pl#63:\
X :tc=generic_dphp:
X#
Xlpn|dhpn|ddjn|Draft Hewlett-Packard DeskJet (Portrait, 40 Columns):\
X :pw#40:\
X :pl#63:\
X :tc=generic_dphp:
X#
Xllp|dlhp|dldj|Draft Hewlett-Packard DeskJet (Landscape, 103 columns):\
X :pw#103:\
X :pl#48:\
X :tc=generic_dphp:
X#
Xllpw|dlhpw|dldjw|Draft Hewlett-Packard DeskJet (Landscape, 172 Columns):\
X :pw#172:\
X :pl#48:\
X :tc=generic_dphp:
X#
Xllpew|dlhpew|dldjew|Draft Hewlett-Packard DeskJet (Landscape, 210 Columns):\
X :pw#210:\
X :pl#48:\
X :tc=generic_dphp:
X#
X# printer doesn't have this size font in stock...
X#llpn|dlhpn|dldjn|Draft Hewlett-Packard DeskJet (Landscape, 51 Columns):\
X# :pw#51:\
X# :pl#48:\
X# :tc=generic_dphp:
X#
X#dportrait:\
X# :pl#63:\
X# :tc=generic_dphp:
X#
X#dlandscape:\
X# :pl#48:\
X# :tc=generic_dphp:
X#
END-of-sample.printcap
echo x - quiet.ps
sed 's/^X//' >quiet.ps << 'END-of-quiet.ps'
X/=print /pop load def
X/print /pop load def
X/handleerror /quit load def
END-of-quiet.ps
exit