*BSD News Article 52084


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!simtel!news.kei.com!news.mathworks.com!tank.news.pipex.net!pipex!howland.reston.ans.net!Germany.EU.net!news.dfn.de!RRZ.Uni-Koeln.DE!se
From: se@MI.Uni-Koeln.DE (Stefan Esser)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: HP DeskJet 600 question
Date: 2 Oct 1995 20:37:31 GMT
Organization: Institute for Mathematics, University of Cologne, Germany
Lines: 156
Message-ID: <44piib$r0p@news.rrz.uni-koeln.de>
References: <87zqfkk5b2.fsf@osti.rmt.utk.edu>
NNTP-Posting-Host: sysiphos.mi.uni-koeln.de
To: wolpert@osti.rmt.utk.edu (Edward Wolpert)

In article <87zqfkk5b2.fsf@osti.rmt.utk.edu>, wolpert@osti.rmt.utk.edu (Edward Wolpert) writes:
|> 	I've recently got an HP deskjet 600.  I'm using gs to convert
|> postscript documents to pcl3, what the 600 understands.  I'm using the
|> output driver djet500.  Has anyone else used a HP deskjet 600?  What
|> are your configs? (Printcap, etc)  My printcap is
|> 
|>    lp:lp=/dev/lpt0:sh:sd=/var/spool/output/lpd:lf=/var/log/lpd-errs:
|> 
|> basically.  I'm working on some conversion filters, so sending print
|> jobs to lp will go through the gs->pcl3 filter, and make another queue
|> for text as well, that will go though a different filter.  Anyone else
|> do anything similar?

A long time ago I wrote a Perl script to distinguish
between PostScript, HP-GL and Text files sent to some
HP LaserJet (which supported HP-PCL and HP-GL only).

You don't need two queues, since all HP-PCL printers
can be set to use Unix carriage controls, and PostScript
can easily be recognized using a regular expression.

I'm not cutting out the HP-GL specific code, since I
don't want to risk breaking the code (and don't have
access to the system I wrote this for, anymore) ...

If you are interested, I could rip out the unnecessary
parts, and send it to you for testing ...


The first of the following files is the "if" filter 
assigned to this print queue using the following line
in /etc/printcap:

	:if=/usr/local/lib/lpdfilters/LaserJet-III:\

The second is a small wrapper to start GhostScript 
with suitable options.

No guarantees, but this worked just fine at a time ... :)

# -- 8< ---- cut here ---- 8< ---- cut here ---- 8< ---- cut here ---- 8< --
#!/usr/local/bin/perl
###############################################################################
#
# /usr/local/lib/lpdfilters/LaserJet-III
#
#	BSD line printer filter for HP-PCL 5 printer
#	  with independent init and uninit strings 
#	  for HP-PCL and HP-GL modes
#

#----------------------------------------------------------------------------
# init and uninit strings for HP-PCL and HP-GL modes
#
$text_inistr = "\033E\033&l26A\033&l1S\033&k2G"; # Text init string
$text_unistr = "\033E\033&l0S";			 # Text un_init string

$hpgl_inistr = "\033E\033&l26a1O\033&l0S\033%0B";# HP-GL init string
$hpgl_unistr = "\033E\033&l0S";			 # HP-GL un_init string
$stdpwcmd    = "PW 0.15;";		# default pen width in HP-GL mode

#----------------------------------------------------------------------------
# describe (a superset of) the HP-GL commands
#
$hpglcmd = '(SM.|DT.|LB[^\003]*\003|[A-Z][A-Z][-\d,.\s]*|[.,;]|\033\..([\d;\s]*:)?|\s|[\003])';

#----------------------------------------------------------------------------
# lprm sends SIGINT (is THIS signal handler necessary ???)
#
$SIG{'INT'}  = 'CLEANUP';

sub CLEANUP {
    print ($hpglfile ? $hpgl_unistr : $text_unistr);
    close(STDOUT);
    exit 2;
}

#----------------------------------------------------------------------------
# read enough (=4KByte) data to choose HP-GL or HP-PCL mode
#
$numread = read(STDIN,$buffer,4096);

#----------------------------------------------------------------------------
# abort if DVI-File ...
#
exit 1 if $buffer =~ /\367\002\001\203/;

#----------------------------------------------------------------------------
# eliminate <ESC>E at begin of file
#
$buffer =~ s/^((\033&.\d*([a-z]\d*)*[A-Z])*)\033E/\1/;

#----------------------------------------------------------------------------
# look for a sequence of HP-GL commands
#
if ($buffer =~ /^ ?%!/) {
    $psfile = 1;
} else {
    $b = $buffer;
    $b =~ s/^(\033&.\d*([a-z]\d*)*[A-Z])+//;
    $b =~ m/^$hpglcmd+/oi;

    $matchlen= length($&);
    $matchlen= 0 if $matchlen > $numread; # to work around perl-4.019 problem

    $escapes = $buffer  =~ tr/\033/\033/;
    $hpglfile= $matchlen > 10 && $matchlen / $numread > 0.95 && $escapes < 10;
}

#----------------------------------------------------------------------------
# put command to set pen width behind 'IN', if found in the first 20 bytes,
# else at start of file
#
if ($hpglfile) {
    $pwcmd  = ($buffer =~ m/(PW\s*\d+\.?\d*\s*;)/i)[0] || $stdpwcmd;
    if (substr($buffer,0,20) =~ m/IN/i) {
	$buffer =~ s/IN\s*;/IN;$pwcmd/i;
    } else {
	$buffer = $pwcmd . $buffer;
    }
}

#----------------------------------------------------------------------------
# print init string, all data, uninit string to STDOUT
#
print ($hpglfile ? $hpgl_inistr : $text_inistr);

if ($psfile) {
    open(FILTER,"| /usr/local/lib/lpdfilters/ps_to_ljet3");
    select(FILTER);
}

while ($numread > 0) {
    print $buffer;
    $numread=read(STDIN,$buffer,4096);
}

if ($psfile) {
    select(STDOUT);
    close(FILTER);
}

print ($hpglfile ? $hpgl_unistr : $text_unistr);

close(STDOUT) || exit (1);

exit (0);
# -- 8< ---- cut here ---- 8< ---- cut here ---- 8< ---- cut here ---- 8< --
#!/bin/sh
/usr/local/bin/gs -dNOPAUSE -sDEVICE=ljet3 -q -sOUTPUTFILE='|cat' -
# -- 8< ---- cut here ---- 8< ---- cut here ---- 8< ---- cut here ---- 8< --
-- 
 Stefan Esser, Zentrum fuer Paralleles Rechnen		Tel:	+49 221 4706021
 Universitaet zu Koeln, Weyertal 80, 50931 Koeln	FAX:	+49 221 4705160
 ==============================================================================
 http://www.zpr.uni-koeln.de/staff/esser/esser.html	  <se@ZPR.Uni-Koeln.DE>