summaryrefslogtreecommitdiff
path: root/foomatic-rip.in
diff options
context:
space:
mode:
Diffstat (limited to 'foomatic-rip.in')
-rwxr-xr-xfoomatic-rip.in87
1 files changed, 75 insertions, 12 deletions
diff --git a/foomatic-rip.in b/foomatic-rip.in
index 74e6798..8c72927 100755
--- a/foomatic-rip.in
+++ b/foomatic-rip.in
@@ -5,7 +5,7 @@ use strict;
use POSIX;
use Cwd;
-my $ripversion='$Revision: 3.43.2.13 $';
+my $ripversion='$Revision: 3.43.2.15 $';
#'# Fix emacs syntax highlighting
# foomatic-rip is a spooler-independent filter script which takes
@@ -204,8 +204,22 @@ my $printer = "";
# Printing options
my $optstr = "";
+# Job ID
+my $jobid = "";
+
+# User who sent job
+my $jobuser = ((getpwuid($<))[0] || `whoami` || "");
+chomp $jobuser;
+
+# Host from which job was sent
+my $jobhost = `hostname`;
+chomp $jobhost;
+
# Job title
-my $jobtitle = "";
+my $jobtitle = "$jobuser\@$jobhost";
+
+# Number of copies
+my $copies = "1";
# Post pipe (command into which the output of this filter should be piped)
my $postpipe = "";
@@ -225,6 +239,10 @@ my $jcltointerpreter = "";
# keyword in the PPD file):
my $jclend = "\033%-12345X\@PJL RESET\n";
+# Prefix for starting every JCL command (Can be modified by
+# "*FoomaticJCLPrefix:" keyword in the PPD file):
+my $jclprefix = "\@PJL ";
+
# Under which name were we called and in which directory do we reside
$0 =~ m!^(.*/)([^/]+)$!;
my $programdir = $1;
@@ -442,14 +460,26 @@ while ($argstr =~ s/\x01--ppd(\x01|=|)([^\x01]+)\x01/\x01/) {
# 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-h(\x01|)([^\x01]+)\x01/\x01/) {
+ # We have LPD or GNUlpr
+ if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) {
+ $spooler = 'lpd';
+ }
+ $jobhost = $2;
+}
+if ($argstr =~ s/\x01-n(\x01|)([^\x01]+)\x01/\x01/) {
+ # We have LPD or GNUlpr
+ if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) {
+ $spooler = 'lpd';
+ }
+ $jobuser = $2;
+}
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/)) {
+ ($argstr =~ s/\x01-c\x01/\x01/)) {
# We have LPD or GNUlpr
if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) {
$spooler = 'lpd';
@@ -685,7 +715,10 @@ if ($spooler eq 'cups') {
# Common job parameters
#$printer = $cups_printer;
+ $jobid = $cups_jobid;
$jobtitle = $cups_jobtitle;
+ $jobuser = $cups_user;
+ $copies = $cups_copies;
$optstr .= $cups_options;
# Check for and handle inputfile vs stdin
@@ -1017,6 +1050,7 @@ my $currentargument = ""; # We are currently reading this argument
# @datablob, and correct the default settings according to the ones of
# the main PPD structure
my @datablob;
+my $jclprefixset = 0;
# Parse the PPD file
sub undossify( $ );
@@ -1454,12 +1488,12 @@ while(<PPD>) {
} else {
$dat->{'args_byname'}{$argname}{'vals_byname'}{$setting}{'driverval'} = unhtmlify($code);
}
- } elsif (m!^\*JCL(Begin|ToPSInterpreter|End):\s*\"(.*)$!) {
- # "*JCL(Begin|ToPSInterpreter|End): <code>"
+ } elsif (m!^\*(Foomatic|)JCL(Begin|ToPSInterpreter|End|Prefix):\s*\"(.*)$!) {
+ # "*(Foomatic|)JCL(Begin|ToPSInterpreter|End|Prefix): <code>"
# The printer supports PJL/JCL when there is such a line
$dat->{'jcl'} = 1;
- my $item = $1;
- my $line = $2;
+ my $item = $2;
+ my $line = $3;
# Store the value
# Code string can have multiple lines, read all of them
my $code = "";
@@ -1479,10 +1513,14 @@ while(<PPD>) {
$code .= $1;
if ($item eq 'Begin') {
$jclbegin = unhexify($code);
+ $jclprefix = "" if (!$jclprefixset) && ($jclbegin !~ /PJL/s);
} elsif ($item eq 'ToPSInterpreter') {
$jcltointerpreter = unhexify($code);
} elsif ($item eq 'End') {
$jclend = unhexify($code);
+ } elsif ($item eq 'Prefix') {
+ $jclprefix = unhexify($code);
+ $jclprefixset = 1;
}
} elsif (m!^\*\% COMDATA \#(.*)$!) {
# If we have an old Foomatic 2.0.x PPD file, collect its Perl data
@@ -4494,7 +4532,7 @@ sub getdocgeneratorhandle {
}
print "Option '$name':\n$commentstr $typestr argument\n";
- print " This options corresponds to a PJL command\n" if ($arg->{'style'} eq 'J');
+ print " This options corresponds to a JCL command\n" if ($arg->{'style'} eq 'J');
if ($type eq 'bool') {
print " Possible choices:\n";
@@ -4804,13 +4842,38 @@ sub removespecialchars {
}
sub unhtmlify {
- # Replace HTML/XML entities by the original characters
my $str = $_[0];
+
+ # Replace HTML/XML entities by the original characters
$str =~ s/\&apos;/\'/g;
$str =~ s/\&quot;/\"/g;
$str =~ s/\&gt;/\>/g;
$str =~ s/\&lt;/\</g;
$str =~ s/\&amp;/\&/g;
+
+ # Replace special entities by job data
+ $str =~ s/\&job;/$jobid/g;
+ $str =~ s/\&user;/$jobuser/g;
+ $str =~ s/\&host;/$jobhost/g;
+ $str =~ s/\&title;/$jobtitle/g;
+ $str =~ s/\&copies;/$copies/g;
+ $str =~ s/\&options;/$optstr/g;
+
+ my ($sec, $min, $hour, $mday, $mon, $year) = (localtime)[0..5];
+ my $yearstr = sprintf("%04d", $year + 1900);
+ my $monstr = sprintf("%02d", $mon + 1);
+ my $mdaystr = sprintf("%02d", $mday);
+ my $hourstr = sprintf("%02d", $hour);
+ my $minstr = sprintf("%02d", $min);
+ my $secstr = sprintf("%02d", $sec);
+
+ $str =~ s/\&year;/$yearstr/g;
+ $str =~ s/\&month;/$monstr/g;
+ $str =~ s/\&date;/$mdaystr/g;
+ $str =~ s/\&hour;/$hourstr/g;
+ $str =~ s/\&min;/$minstr/g;
+ $str =~ s/\&sec;/$secstr/g;
+
return $str;
}
@@ -5835,7 +5898,7 @@ sub buildcommandline {
# JCL argument
$dat->{'jcl'} = 1;
# put JCL commands onto JCL stack...
- push (@jclprepend, "\@PJL $cmdvar\n") if $cmdvar;
+ push (@jclprepend, "$jclprefix$cmdvar\n") if $cmdvar;
} elsif ($arg->{'style'} eq 'C') {
# command-line argument