summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorabs <abs@pkgsrc.org>2000-10-16 12:19:06 +0000
committerabs <abs@pkgsrc.org>2000-10-16 12:19:06 +0000
commitbec51713ab70a29fd2bd3dc09f08f0df921cb010 (patch)
treed68d233f01d4541b210e54f4aa51b0b0fb633526
parent6c6def5051ad42d6b46f839a57031a98eba5e067 (diff)
downloadpkgsrc-bec51713ab70a29fd2bd3dc09f08f0df921cb010.tar.gz
Add if-psprint 1.0
if-psprint is intended to print text, postscript, or native printer language to an arbitrary printer, either connected to a the local unix server, or remote machine via SMB (if samba is installed).
-rw-r--r--print/if-psprint/Makefile30
-rwxr-xr-xprint/if-psprint/files/if-psprint.pl164
-rw-r--r--print/if-psprint/pkg/COMMENT1
-rw-r--r--print/if-psprint/pkg/DESCR3
-rw-r--r--print/if-psprint/pkg/PLIST2
5 files changed, 200 insertions, 0 deletions
diff --git a/print/if-psprint/Makefile b/print/if-psprint/Makefile
new file mode 100644
index 00000000000..6a2eb91794e
--- /dev/null
+++ b/print/if-psprint/Makefile
@@ -0,0 +1,30 @@
+# $NetBSD: Makefile,v 1.1.1.1 2000/10/16 12:19:06 abs Exp $
+#
+
+DISTNAME= if-psprint-1.0
+CATEGORIES= print
+MASTER_SITES= # empty
+DISTFILES= # empty
+
+MAINTAINER= abs@netbsd.org
+
+DEPENDS+= ghostscript{,-nox11}-[6-9]*:../../print/ghostscript
+DEPENDS+= enscript-[0-9]*:../../print/enscript
+
+USE_PERL5= YES
+
+EXTRACT_ONLY= # empty
+NO_WRKSUBDIR= yes
+NO_CHECKSUM= yes
+NO_PATCH= yes
+NO_CONFIGURE= yes
+
+do-build:
+ ${SED} -e 's|@PREFIX@|${PREFIX}|g' \
+ < ${FILESDIR}/if-psprint.pl \
+ > ${WRKSRC}/if-psprint
+
+do-install:
+ ${INSTALL_SCRIPT} ${WRKSRC}/if-psprint ${PREFIX}/libexec/if-psprint
+
+.include "../../mk/bsd.pkg.mk"
diff --git a/print/if-psprint/files/if-psprint.pl b/print/if-psprint/files/if-psprint.pl
new file mode 100755
index 00000000000..7db5819d665
--- /dev/null
+++ b/print/if-psprint/files/if-psprint.pl
@@ -0,0 +1,164 @@
+#!@PREFIX@/bin/perl -w
+#
+# $NetBSD: if-psprint.pl,v 1.1.1.1 2000/10/16 12:19:07 abs Exp $
+#
+# Copyright (c) 2000 David Brownlee <abs@netbsd.org>. All rights
+# reserved. Provided as-is without express or implied warranties.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided the above copyright and this
+# notice is retained.
+#
+# Print text, postscript, or native printer language to arbitrary printer,
+# designed as a quick for for the random printers that get hooked up to
+# the NetBSD server and random Windows boxes around the office...
+#
+# Overview:
+# - Overloads 'af' entry to contain printer type, and optional location.
+# in the form 'type[.model][/smb/smb_dest]'. 'ps' for no gs filter.
+# - Reads first 1k and calls 'file' to determine filetype.
+# - Builds a spool command based on filetype:
+# - If text and not postscript, use enscript text->postscript
+# - If enscripted or postscript, use gs postscript->printer_format
+# - Otherwise assumed to be native printer language (its your rope)
+# - Open pipe to spool command, send first 1k, then rest of data
+# - requires ghostscript, enscript, and samba if printing to smb hosts
+#
+# Sample printcap entries: (Remember to create spool dir [sd])
+#
+# HP deskjet named 'leaves' connected to smb host 'tea'.
+# (using ghostscript 'hpdj' driver model 'unspec')
+#
+# leaves:\
+# :sh:mx=0:if=@PREFIX@/libexec/if-psprint:lf=/var/log/lpd-errs:\
+# :lp=/dev/null:sd=/var/spool/lpd/leaves:af=hpdj.unspec/smb/tea/leaves
+#
+# Canon bubblejet connected to /dev/lpa0 (using gs 'bjc800' driver)
+#
+# bubbly:\
+# :sh:mx=0:if=@PREFIX@/libexec/if-psprint:lf=/var/log/lpd-errs:\
+# :lp=/dev/lpa0:sd=/var/spool/lpd/bubbly:af=bjc800
+#
+
+$ENV{'PATH'}="@PREFIX@/bin:/usr/bin:/bin";
+
+use strict;
+use Getopt::Std;
+use IPC::Open3;
+
+my( $user,
+ $dest,
+ $spoolhost,
+ $device,
+ $model,
+ %opt,
+ );
+
+# Parse options (ignore most)
+#
+
+&getopt('w:l:i:n:h:', \%opt);
+$user = $opt{'n'};
+$user ||= $ENV{'USER'};
+$spoolhost = $opt{'h'};
+if (!$spoolhost)
+ { chomp($spoolhost = `hostname`); }
+
+if (@ARGV != 1 || $ARGV[0] !~ m#(\w+)(\.(\w+)|)(/smb/.*/.*|)#)
+ { &usage_and_exit; }
+$device = $1;
+$model = $3;
+$dest = $4;
+if ($dest)
+ { $dest =~ s#/smb/#smb:/#; }
+
+# Determine filetype
+#
+
+my($data, $filetype);
+if (!read(STDIN, $data, 1024)) # initial filetype check data
+ { &fail("No data to print"); }
+$filetype = &filetype($data);
+
+# Generate spool command
+#
+
+my($spool);
+$spool = '';
+if ($filetype =~ /^PostScript/ || $filetype =~ /text/)
+ {
+ if ($filetype !~ /^PostScript/)
+ { $spool .= '|'.filter_enscript(); }
+ if ($model || $device ne 'ps')
+ { $spool .= '|'.filter_gs($device, $model); }
+ }
+
+if ($dest)
+ { $spool .= "|smbspool smb://$dest 1 $user $spoolhost 1 -"; }
+
+if ($spool eq '')
+ { $spool = '>&STDOUT'; }
+
+# Spool output
+#
+if (!open(OUTPUT, $spool))
+ { &fail("Unable to run '$spool': $!"); }
+print OUTPUT $data; # print initial filetype check data
+while (read(STDIN, $data, 16*1024))
+ { print OUTPUT $data; }
+close(STDIN);
+close(OUTPUT);
+exit;
+
+sub fail
+ {
+ print STDERR "if-psprint: @_\n";
+ exit 1;
+ }
+
+sub filetype
+ {
+ my($data) = @_;
+ my($pid, $filetype);
+
+ unless ($pid = open3('WTRFH', 'RDRFH', 'ERRFH', 'file -b -'))
+ { &fail("Unable to run 'file': $!"); }
+ print WTRFH $data;
+ close(WTRFH);
+ close(ERRFH);
+ 0 && close(ERRFH); # Pacify perl's -w
+ chop($filetype = <RDRFH>);
+ close(RDRFH);
+ wait;
+ $filetype;
+ }
+
+sub filter_enscript
+ {
+ my($filter);
+
+ $filter = "enscript -q -B -p -";
+ }
+
+sub filter_gs
+ {
+ my($device, $model) = @_;
+ my($filter);
+ $filter = "gs -q -dBATCH -sDEVICE=$device";
+ if (defined $model)
+ { $filter .= " -sModel=$model"; }
+ $filter .= " -SOutputFile=- -";
+ }
+
+sub usage_and_exit
+ {
+ print "Usage: if-psprint [opts] gs_device[.gs_model]/smbdestination
+[opts]
+ -w width
+ -l lines
+ -i indent
+ -n user
+ -h host
+";
+ exit 1;
+ }
diff --git a/print/if-psprint/pkg/COMMENT b/print/if-psprint/pkg/COMMENT
new file mode 100644
index 00000000000..15b258d542f
--- /dev/null
+++ b/print/if-psprint/pkg/COMMENT
@@ -0,0 +1 @@
+Filter to print text or postscript to arbitrary printer, can use smb
diff --git a/print/if-psprint/pkg/DESCR b/print/if-psprint/pkg/DESCR
new file mode 100644
index 00000000000..da6210b55a6
--- /dev/null
+++ b/print/if-psprint/pkg/DESCR
@@ -0,0 +1,3 @@
+if-psprint is intended to print text, postscript, or native printer language
+to an arbitrary printer, either connected to a the local unix server, or
+remote machine via SMB (if samba is installed).
diff --git a/print/if-psprint/pkg/PLIST b/print/if-psprint/pkg/PLIST
new file mode 100644
index 00000000000..e21f3f55e87
--- /dev/null
+++ b/print/if-psprint/pkg/PLIST
@@ -0,0 +1,2 @@
+@comment $NetBSD: PLIST,v 1.1.1.1 2000/10/16 12:19:07 abs Exp $
+libexec/if-psprint