📄 foomatic-rip
字号:
}} elsif ($argstr =~ s/\x01--lprng\x01/\x01/g) { # We have LPRng $spooler = 'lprng';}# PPD file name given via the command line# allow duplicates, and use the last specified onewhile ( ($spooler ne 'lprng') and ($argstr =~ s/\x01-p(\x01|)([^\x01]+)\x01/\x01/)) { $ppdfile = $2;}while ($argstr =~ s/\x01--ppd(\x01|=|)([^\x01]+)\x01/\x01/) { $ppdfile = $2;}# Check for LPD/GNUlpr by typical options which the spooler puts onto# the filter's command line (options "-w": text width, "-l": text# length, "-i": indent, "-x", "-y": graphics size, "-c": raw printing,# "-n": user name, "-h": host name)if (($argstr =~ s/\x01-w(\x01|)\d+\x01/\x01/) || ($argstr =~ s/\x01-l(\x01|)\d+\x01/\x01/) || ($argstr =~ s/\x01-x(\x01|)\d+\x01/\x01/) || ($argstr =~ s/\x01-y(\x01|)\d+\x01/\x01/) || ($argstr =~ s/\x01-i(\x01|)\d+\x01/\x01/) || ($argstr =~ s/\x01-c\x01/\x01/) || ($argstr =~ s/\x01-n(\x01|)[^\x01]+\x01/\x01/) || ($argstr =~ s/\x01-h(\x01|)[^\x01]+\x01/\x01/)) { # We have LPD or GNUlpr if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) { $spooler = 'lpd'; }}# LPRng delivers the option settings via the "-Z" argumentif ($argstr =~ s/\x01-Z(\x01|)([^\x01]+)\x01/\x01/) { my @lpopts = split(/,/, $2); foreach my $opt (@lpopts) { $opt =~ s/^\s+//; $opt =~ s/\s+$//; if ($opt =~ /\s+/) { $opt = "\"$opt\""; } $optstr .= "$opt "; } # We have LPRng $spooler = 'lprng';}# Job title and options for stock LPDif ($argstr =~ s/\x01-[jJ](\x01|)([^\x01]+)\x01/\x01/) { # An LPD $jobtitle = $2; # Classic LPD hack if ($spooler eq "lpd") { $optstr .= "$jobtitle "; }}# Check for CPSif ($argstr =~ s/\x01--cps\x01/\x01/) { # We have cps $spooler = 'cps';}# Options for spooler-less printing, CPS, or PDQwhile ($argstr =~ s/\x01-o(\x01|)([^\x01]+)\x01/\x01/) { my $opt = $2; $opt =~ s/^\s+//; $opt =~ s/\s+$//; if ($opt =~ /\s+/) { $opt = "\"$opt\""; } $optstr .= "$opt "; # If we don't print as a PPR RIP or as a CPS filter, we print without # spooler (we check for PDQ later) if (($spooler ne 'ppr') && ($spooler ne 'cps')) { $spooler = 'direct'; }}# Printer for spooler-less printing or PDQif ($argstr =~ s/\x01-d(\x01|)([^\x01]+)\x01/\x01/) { $printer = $2;}# Printer for spooler-less printing, PDQ, or LPRngif ($argstr =~ s/\x01-P(\x01|)([^\x01]+)\x01/\x01/) { $printer = $2;}# Were we called from a PDQ wrapper?if ($argstr =~ s/\x01--pdq\x01/\x01/) { # We have PDQ $spooler = 'pdq';}# Were we called to build the PDQ driver declaration file?# "--appendpdq=<file>" appends the data to the <file>,# "--genpdq=<file>" creates/overwrites <file> for the data, and# "--genpdq" writes to standard outputmy $genpdqfile = "";if (($argstr =~ s/\x01--(gen)(raw|)pdq(\x01|=|)([^\x01]*)\x01/\x01/) || ($argstr =~ s/\x01--(append)(raw|)pdq(\x01|=|)([^\x01]+)\x01/\x01/)) { # Determine output file name if (!$4) { $genpdqfile = ">&STDOUT"; } else { if ($1 eq 'gen') { $genpdqfile = "> $4"; } else { $genpdqfile = ">> $4"; } } # Do we want to have a PDQ driver declaration for a raw printer? if ($2 eq 'raw') { my $time = time(); my @pdqfile ="driver \"Raw-Printer-$time\" { # This PDQ driver declaration file was generated automatically by # foomatic-rip to allow raw (filter-less) printing. language_driver all { # We accept all file types and pass them through without any changes filetype_regx \"\" convert_exec { ln -s \$INPUT \$OUTPUT } } filter_exec { ln -s \$INPUT \$OUTPUT }}"; open PDQFILE, $genpdqfile or rip_die("Cannot write PDQ driver declaration file", $EXIT_PRNERR_NORETRY_BAD_SETTINGS); print PDQFILE join('', @pdqfile); close PDQFILE; exit $EXIT_PRINTED; } # We have PDQ $spooler = 'pdq';}# remove extra spacing if running as LPRng filter$added_lf = "" if $spooler eq 'lprng';## Command line arguments without name# Remaining argumentsmy @rargs = split(/\x01/, $argstr);shift @rargs;# Load definitions for PPR error messages, check whether we run as# PPR interface or as PPR RIPmy( $ppr_printer, $ppr_address, $ppr_options, $ppr_jobbreak, $ppr_feedback, $ppr_codes, $ppr_jobname, $ppr_routing, $ppr_for, $ppr_filetype, $ppr_filetoprint );if ($spooler eq 'ppr') { # Read interface.sh so we will know the correct exit codes and # also signal.sh for the signal codes my $deffound = 0; # Did we find one of the definition files my @definitions; for my $file (("lib/interface.sh", "lib/signal.sh")) { open FILE, "$file" || do { print $logh "error opening $file.\n"; next; }; $deffound = 1; while(my $line = <FILE>) { # Translate the shell script to Perl if (($line !~ m/^\s*$/) && ($line !~ m/^\s*\#/)) { $line =~ s/^\s*([^\#\s]*)/\$$1;/; push (@definitions, $line); } } close FILE; } if ($deffound) { # Apply the definitions loaded from PPR eval join('',@definitions) || do { print $logh "unable to evaluate definitions\n"; rip_die ("Error in definitions evaluation", $EXIT_PRNERR_NORETRY_BAD_SETTINGS); }; } # Check whether we run as a PPR interface (if not, we run as a PPR RIP) if (($rargs[3] =~ /^\s*\d\d?\s*$/) && ($rargs[5] =~ /^\s*\d\d?\s*$/) && (($#rargs == 10) || ($#rargs == 9) || ($#rargs == 7))) { # PPR calls interfaces with many command line parameters, # where the forth and the sixth is a small integer # number. In addition, we have 8 (PPR <= 1.31), 10 # (PPR>=1.32), 11 (PPR >= 1.50) command line parameters. # We also check whether the current working directory is a # PPR directory. # Get all command line parameters $ppr_printer = $rargs[0]; $ppr_address = $rargs[1]; $ppr_options = $rargs[2]; $ppr_jobbreak = $rargs[3]; $ppr_feedback = $rargs[4]; $ppr_codes = $rargs[5]; $ppr_jobname = $rargs[6]; $ppr_routing = $rargs[7]; $ppr_for = $rargs[8]; $ppr_filetype = $rargs[9]; $ppr_filetoprint = $rargs[10]; # Common job parameters $printer = $ppr_printer; $jobtitle = $ppr_jobname; if ((!$jobtitle) && ($ppr_filetoprint)) { $jobtitle = $ppr_filetoprint; } $optstr .= "$ppr_options $ppr_routing"; # Get the path of the PPD file from the queue configuration $ppdfile = `LANG=en_US; ppad show $ppr_printer | grep PPDFile`; $ppdfile =~ s/PPDFile:\s+//; if ($ppdfile !~ m!^/!) { $ppdfile = "../../share/ppr/PPDFiles/$ppdfile"; } chomp($ppdfile); # We have PPR and run as an interface $spooler = 'ppr_int'; }}# CUPSmy( $cups_jobid, $cups_user, $cups_jobtitle, $cups_copies, $cups_options, $cups_filename );if ($spooler eq 'cups') { # Get all command line parameters $cups_jobid = $rargs[0]; $cups_user = $rargs[1]; $cups_jobtitle = $rargs[2]; $cups_copies = $rargs[3]; $cups_options = $rargs[4]; $cups_filename = $rargs[5]; # Common job parameters #$printer = $cups_printer; $jobtitle = $cups_jobtitle; $optstr .= $cups_options; # Check for and handle inputfile vs stdin if ((defined($cups_filename)) && ($cups_filename) && ($cups_filename ne '-')) { # We get the input from a file @filelist = ($cups_filename); print $logh "Getting input from file $cups_filename\n"; }}# LPD/LPRng/GNUlprif (($spooler eq 'lpd') || ($spooler eq 'lprng' and !$ppdfile) || ($spooler eq 'gnulpr')) { # Get PPD file name as the last command line argument $ppdfile = $rargs[$#rargs];}# No spooler, CPS, or PDQif (($spooler eq 'direct') || ($spooler eq 'cps') || ($spooler eq 'pdq')) { # Which files do we want to print? @filelist = @rargs;}## Additional spooler-specific preparations# CUPSif ($spooler eq 'cups') { # This piece of PostScript code (initial idea 2001 by Michael # Allerhand (michael.allerhand at ed dot ac dot uk, vastly # improved by Till Kamppeter in 2002) lets GhostScript output # the page accounting information which CUPS needs on standard # error. if (defined $conf{ps_accounting}) { $ps_accounting = $conf{ps_accounting}; } $accounting_prolog = $ps_accounting ? "[{%% Code for writing CUPS accounting tags on standard error/cupsPSLevel2 % Determine whether we can do PostScript level 2 or newer systemdict/languagelevel 2 copy known{get exec}{pop pop 1}ifelse 2 gedef/cupsGetNumCopies { % Read the number of Copies requested for the current % page cupsPSLevel2 { % PS Level 2+: Get number of copies from Page Device dictionary currentpagedevice /NumCopies get } { % PS Level 1: Number of copies not in Page Device dictionary null } ifelse % Check whether the number is defined, if it is \"null\" use #copies % instead dup null eq { pop #copies } if % Check whether the number is defined now, if it is still \"null\" use 1 % instead dup null eq { pop 1 } if} bind def/cupsWrite { % write a string onto standard error (%stderr) (w) file exch writestring} bind def/cupsEndPage { % write page log info when we were invoked by \"showpage\" % or \"copypage\" return \"true\" or \"false\" as we had no % redefinition of \"EndPage\" 2 ne % If the reason code is 0 or 1, we have finshed a page % (we were invoked by \"showpage\" or \"copypage\"), % write log info and exit with \"true\" to push out the page. % In case of reason code 2, we are invoked during device % deactivation (happens also at a \"setpagedevice\" call), % here we should not log and return \"false\" { % write \"Page <# of page> <# of copies><LF>\" to stderr (PAGE: ) cupsWrite % we must add 1 here, the number on the stack is the number % of \"showpage\" already executed during this job 1 add 40 string cvs cupsWrite % space ( ) cupsWrite % get the number of copies for this page cupsGetNumCopies 40 string cvs cupsWrite % line feed (\\n) cupsWrite % page should be ejected true } { pop % ignore the number of pages already printed % do not eject paper false } ifelse} bind def<</EndPage{cupsEndPage}>>setpagedevice} stopped cleartomark" : ""; # On which queue are we printing? # CUPS gives the PPD file the same name as the printer queue, # so we can get the queue name from the name of the PPD file. $ppdfile =~ m!^(.*/)([^/]+)\.ppd$!; $printer = $2;}# No spooler, CPS, or PDQif (($spooler eq 'direct') || ($spooler eq 'cps') || ($spooler eq 'pdq')) { # Path for personal Foomatic configuration my $user_default_path = "$ENV{'HOME'}/.foomatic"; if (!$ppdfile) { if (!$printer) { # No printer definition file selected, check whether we have a # default printer defined. for my $conf_file (("./.directconfig", "./directconfig", "./.config", "$user_default_path/direct/.config", "$user_default_path/direct.conf", "$configpath/direct/.config", "$configpath/direct.conf")) { if (open CONFIG, "< $conf_file") { while (my $line = <CONFIG>) { chomp $line; if ($line =~ /^default\s*:\s*([^:\s]+)\s*$/) { $printer = $1; last; } } close CONFIG; } if ($printer) { last; } } } # Neither in a config file nor on the command line a printer was
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -