⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 foomatic-rip

📁 HP喷墨打印机驱动代码 HP内部资料! 珍贵 珍贵 珍贵
💻
📖 第 1 页 / 共 5 页
字号:
#!/usr/bin/perl# The above Perl path may vary on your system; fix it!!!#  $Id: foomatic-rip.in,v 3.48 2004/06/15 14:55:06 till Exp $#  $Name:  $use strict;use POSIX;use Cwd;my $ripversion='$Revision: 3.48 $';#'# Fix emacs syntax highlighting# foomatic-rip is a spooler-independent filter script which takes# PostScript as standard input and generates the printer's page# description language (PDL)/raster format as standard output. This# kind of filter is usually called Raster Image Processor (RIP),# therefore the name "foomatic-rip".# Save it in one of the directories of your $PATH, so that it gets# found when called from the command line (for spooler-less printing),# link it to spooler-specific directories when you use CUPS or PPR:#    ln -s /usr/bin/foomatic-rip /usr/lib/cups/filter/#    ln -s /usr/bin/foomatic-rip /usr/lib/ppr/lib/#    ln -s /usr/bin/foomatic-rip /usr/lib/ppr/interfaces/# Mark this filter world-readable and world-executable (note that most# spoolers run the print filters as a special user, as "lp", not as# "root" or as the user who sent the job).# See http://www.linuxprinting.org/cups-doc.html#     http://www.linuxprinting.org/lpd-doc.html#     http://www.linuxprinting.org/ppr-doc.html#     http://www.linuxprinting.org/pdq-doc.html#     http://www.linuxprinting.org/direct-doc.html#     http://www.linuxprinting.org/ppd-doc.html# ==========================================================================##    User-configurable settings, edit them if needed## ==========================================================================# What path to use for filter programs and such.  Your printer driver# must be in the path, as must be the renderer, $enscriptcommand, and# possibly other stuff.	 The default path is often fine on Linux, but# may not be on other systems.#my $execpath = "/usr/local/bin:/usr/local/bin:/usr/bin:/bin";# CUPS raster drivers are searched heremy $cupsfilterpath = "/usr/local/lib/cups/filter:/usr/local/lib/cups/filter:/usr/local/libexec/cups/filter:/opt/cups/filter:/usr/lib/cups/filter";# Location of the configuration file "filter.conf", this file can be# used to change the settings of foomatic-rip without editing# foomatic-rip. itself. This variable must contain the full pathname # of the directory which contains the configuration file, usually# "/etc/foomatic".# Some versions of configure do not fully expand $sysconfdirmy $prefix = "/usr/local";my $configpath = "${prefix}/etc/foomatic";# For the stuff below, the settings in the configuration file have priority.# Set to 1 to insert postscript code for page accounting (CUPS only).my $ps_accounting = 1;my $accounting_prolog = "";# Enter here your personal command for converting non-postscript files# (especially text) to PostScript. If you leave it blank, at first the# line "textfilter: ..." from /etc/foomatic/filter.conf is read and# then the commands given on the list below are tried, beginning with# the first one.# You can set this to "a2ps", "enscript" or "mpage" to select one of the # default command strings.my $fileconverter = "";my($kid0,$kid1,$kid2,$kid3,$kid4);my($kidfailed,$kid3finished,$kid4finished);my($convkidfailed,$dockidfailed,$kid0finished,$kid1finished,$kid2finished);my($fileconverterpid,$rendererpid,$fileconverterhandle,$rendererhandle);my($jobhasjcl);# What 'echo' program to use.  It needs -e and -n.  Linux's builtin# and regular echo work fine; non-GNU platforms may need to install# gnu echo and put gecho here or something.#my $myecho = 'echo';# Set debug to 1 to enable the debug logfile for this filter; it will# appear as defined by $logfile. It will contain status from this# filter, plus the renderer's stderr output. You can also add a line# "debug: 1" to your /etc/foomatic/filter.conf to get all your# Foomatic filters into debug mode.## WARNING: This logfile is a security hole; do not use in production.my $debug = 0;# This is the location of the debug logfile (and also the copy of the# processed PostScript data) in case you have enabled debugging above.# The logfile will get the extension ".log", the PostScript data ".ps".my $logfile = "/tmp/foomatic-rip";# End interesting enduser options# ==========================================================================## foomatic-rip spooler-independent PS->Printer filter (RIP) of Foomatic## Copyright 2002 Grant Taylor <gtaylor@picante.com>#		 & Till Kamppeter <till.kamppeter@gmx.net>##  This program is free software; you can redistribute it and/or modify it#  under the terms of the GNU General Public License as published by the#  Free Software Foundation; either version 2 of the License, or (at your#  option) any later version.##  This program is distributed in the hope that it will be useful, but#  WITHOUT ANY WARRANTY; without even the implied warranty of#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General#  Public License for more details.##  You should have received a copy of the GNU General Public License#  along with this program; if not, write to the Free Software#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,#  USA.#my $added_lf = "\n";# Flush everything immediately.$|=1;## Constants used by this filter# Error codes, as some spooles behave different depending on the reason why# the RIP failed, we return an error code. As I have only found a table of# error codes for the PPR spooler. If our spooler is really PPR, these# definitions get overwritten by the ones of the PPR version currently in# use.my $EXIT_PRINTED = 0;         # file was printed normallymy $EXIT_PRNERR = 1;          # printer error occuredmy $EXIT_PRNERR_NORETRY = 2;  # printer error with no hope of retrymy $EXIT_JOBERR = 3;          # job is defectivemy $EXIT_SIGNAL = 4;          # terminated after catching signalmy $EXIT_ENGAGED = 5;         # printer is otherwise engaged (connection                            # refused)my $EXIT_STARVED = 6;         # starved for system resourcesmy $EXIT_PRNERR_NORETRY_ACCESS_DENIED = 7;     # bad password? bad port                                            # permissions?my $EXIT_PRNERR_NOT_RESPONDING = 8;            # just doesn't answer at all                                             # (turned off?)my $EXIT_PRNERR_NORETRY_BAD_SETTINGS = 9;      # interface settings are invalidmy $EXIT_PRNERR_NO_SUCH_ADDRESS = 10;          # address lookup failed, may be                                             # transientmy $EXIT_PRNERR_NORETRY_NO_SUCH_ADDRESS = 11;  # address lookup failed, not                                             # transientmy $EXIT_INCAPABLE = 50;                       # printer wants (lacks) features                                            # or resources# Standard Unix signal names#my SIGHUP = 1;#my SIGINT = 2;#my SIGQUIT = 3;#my SIGKILL = 9;#my SIGTERM = 15;#my SIGUSR1 = 10;#my SIGUSR2 = 12;#my SIGTTIN = 21;#my SIGTTOU = 22;## Some important variables# We don't know yet, which spooler will be used. If we don't detect# one.  we assume that we do spooler-less printing. Supported spoolers# are currently:#    cups    - CUPS - Common Unix Printing System#    lpd     - LPD - Line Printer Daemon#    lprng   - LPRng - LPR - New Generation#    gnulpr  - GNUlpr, an enhanced LPD (development stopped)#    ppr     - PPR (foomatic-rip runs as a PPR RIP)#    ppr_int - PPR (foomatic-rip runs as an interface)#    cps     - CPS - Coherent Printing System#    pdq     - PDQ - Print, Don't Queue (development stopped)#    direct  - Direct, spooler-less printingmy $spooler = 'direct';# PPD file namemy $ppdfile = "";# Printer modelmy $model = "";# Printer queue namemy $printer = "";# Printing optionsmy $optstr = "";# Job titlemy $jobtitle = "";# Post pipe (command into which the output of this filter should be piped)my $postpipe = "";# Files to be printedmy @filelist = ();# JCL prefix to put before the JCL options (Can be modified by a# "*JCLBegin:" keyword in the PPD file):my $jclbegin = "\033%-12345X\@PJL\n";# JCL command to switch the printer to the PostScript interpreter (Can# be modified by a "*JCLToPSInterpreter:" keyword in the PPD file):my $jcltointerpreter = "";# JCL command to close a print job (Can be modified by a "*JCLEnd:"# keyword in the PPD file):my $jclend = "\033%-12345X\@PJL RESET\n";# Under which name were we called and in which directory do we reside$0 =~ m!^(.*/)([^/]+)$!;my $programdir = $1;my $programname = $2;# Filters to convert non-PostScript filesmy @fileconverters =   (# a2ps (converts also other files than text)   'a2ps -1 @@--medium=@@PAGESIZE@@ @@--center-title=@@JOBTITLE@@ -o -',   # enscript   'enscript -G @@-M @@PAGESIZE@@ @@-b "Page $%|@@JOBTITLE@@ ' .   '--margins=36:36:36:36 --mark-wrapped-lines=arrow --word-wrap -p-',   # mpage   'mpage -o -1 @@-b @@PAGESIZE@@ @@-H -h @@JOBTITLE@@ -m36l36b36t36r ' .   '-f -P- -');# spooler-specific file converters, default for the specific spooler when# none of the converters above is chosen.my @fixed_args = (	defined($ARGV[0])?$ARGV[0]:"",	defined($ARGV[1])?$ARGV[1]:"",	defined($ARGV[2])?$ARGV[2]:"",	defined($ARGV[3])?$ARGV[3]:"",	defined($ARGV[4])?$ARGV[4]:"" );my $spoolerfileconverters = {    'cups' => "${programdir}texttops '$fixed_args[0]' '$fixed_args[1]' '$fixed_args[2]' " .		"'$fixed_args[3]' '$fixed_args[4] page-top=36 page-bottom=36 " .	"page-left=36 page-right=36 nolandscape cpi=12 lpi=7 " .	"columns=1 wrap'"    };## Config file# Read config file if presentmy %conf = readConfFile("$configpath/filter.conf");# Get execution path from config file$execpath = $conf{execpath} if defined $conf{execpath};$ENV{'PATH'} = $execpath;# Get CUPS filter path from config file$cupsfilterpath = $conf{cupsfilterpath} if defined $conf{cupsfilterpath};# Set debug mode$debug = $conf{debug} if defined $conf{debug};# Determine which filter to use for non-PostScript files to be converted# to PostScriptif (defined $conf{textfilter}) {    $fileconverter = $conf{textfilter};    $fileconverter eq 'a2ps' and $fileconverter = $fileconverters[0];    $fileconverter eq 'enscript' and $fileconverter = $fileconverters[1];    $fileconverter eq 'mpage' and $fileconverter = $fileconverters[2];}## Environment variables;# "PPD": PPD file name for CUPS or PPR (if we run as PPR RIP)if (defined($ENV{'PPD'})) {    $ppdfile = $ENV{'PPD'};    # CUPS and PPR (RIP filter) use the "PPD" environment variable to     # make the PPD file name available (we set CUPS here preliminarily,    # in the next step we check for PPR    $spooler = 'cups';}# "PPR_VERSION": PPRif (defined($ENV{'PPR_VERSION'})) {    # We have PPR    $spooler = 'ppr';}# "PPR_RIPOPTS": PPRif (defined($ENV{'PPR_RIPOPTS'})) {    # PPR 1.5 allows the user to specify options for the PPR RIP with the     # "--ripopts" option on the "ppr" command line. They are provided to    # the RIP via the "PPR_RIPOPTS" environment variable.    $optstr .= "$ENV{'PPR_RIPOPTS'} ";    # We have PPR    $spooler = 'ppr';}# "LPOPTS": Option settings for some LPD implementations (ex: GNUlpr)if (defined($ENV{'LPOPTS'})) {    my @lpopts = split(/,/, $ENV{'LPOPTS'});    foreach my $opt (@lpopts) {	$opt =~ s/^\s+//;	$opt =~ s/\s+$//;	if ($opt =~ /\s+/) {	    $opt = "\"$opt\"";	}	$optstr .= "$opt ";    }    # We have an LPD which accepts "-o" for options    $spooler = 'gnulpr';}## Named command line options# We do not use Getopt::Long because it does not work when between the# option and the argument is no space ("-w80" instead of "-w 80"). This# happens in the command line of LPRng, but also users could type in# options this way when printing without spooler.# Make one option string with a non-printable character as separator,# So we can parse it more easilymy $argstr = "\x01" . join("\x01",@ARGV) . "\x01";# Debug mode activated via command lineif ($argstr =~ s/\x01--debug\x01/\x01/) {    $debug = 1;}# Command line options for verbositymy $verbose = ($argstr =~ s/\x01-v\x01/\x01/);my $quiet = ($argstr =~ s/\x01-q\x01/\x01/);my $show_docs = ($argstr =~ s/\x01-d\x01/\x01/);my $do_docs;my $cupscolorprofile;# Where to send debugging log output tomy $logh;if ($debug) {    # Grotesquely unsecure; use for debugging only    open LOG, "> ${logfile}.log";    $logh = *LOG;    use IO::Handle;    $logh->autoflush(1);} elsif (($quiet) && (!$verbose)) {    # Quiet mode, do not log    close $logh;    open LOG, "> /dev/null";    $logh = *LOG;    use IO::Handle;    $logh->autoflush(1);} else {    # Default: log to STDERR    $logh=*STDERR;}## Start debug loggingif ($debug) {    # If we are not debug mode, we do this later, as we must find out at    # first which spooler is used. When printing without spooler we    # suppress logging because foomatic-rip is called directly on the    # command line and so we avoid logging onto the console.    print $logh "foomatic-rip version $ripversion running...\n";    # Print the command line only in debug mode, Mac OS X adds very many    # options so that CUPS cannot handle the output of the command line    # in its log files. If CUPS encounters a line with more than 1024    # characters sent into its log files, it aborts the job with an error.    if (($debug) || ($spooler ne 'cups')) {	print $logh "called with arguments: '", join("', '",@ARGV), "'\n";    }}## Continue with named options# Check for LPRng first so we do not pick up bogus ppd files by the -p optionif ($argstr =~ s/\x01--lprng\x01/\x01/) {    # We have LPRng    $spooler = 'lprng';}# 'PRINTCAP_ENTRY' environment variable is : LPRng#  the :ppd=/path/to/ppdfile printcap entry should be usedif (defined($ENV{'PRINTCAP_ENTRY'})){	$spooler = 'lprng';	my( @pc);	@pc = split( /\s*:\s*/, $ENV{'PRINTCAP_ENTRY'} );	shift @pc;	foreach (@pc) {		if( /^ppd=(.*)$/ or  /^ppdfile=(.*)$/ ){			$ppdfile = $1 if $1;		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -