|
Lines 337-346
if (defined($ENV{'LPOPTS'})) {
Link Here
|
| 337 |
$spooler = 'gnulpr'; |
337 |
$spooler = 'gnulpr'; |
| 338 |
} |
338 |
} |
| 339 |
|
339 |
|
| 340 |
|
|
|
| 341 |
|
| 342 |
## Named command line options |
| 343 |
|
| 344 |
# We do not use Getopt::Long because it does not work when between the |
340 |
# We do not use Getopt::Long because it does not work when between the |
| 345 |
# option and the argument is no space ("-w80" instead of "-w 80"). This |
341 |
# option and the argument is no space ("-w80" instead of "-w 80"). This |
| 346 |
# happens in the command line of LPRng, but also users could type in |
342 |
# happens in the command line of LPRng, but also users could type in |
|
Lines 358-555
if (defined($ENV{'LPOPTS'})) {
Link Here
|
| 358 |
my $argstr = "\x01" . |
354 |
my $argstr = "\x01" . |
| 359 |
join("\x01", map { removeunprintables($_) } @ARGV) . "\x01"; |
355 |
join("\x01", map { removeunprintables($_) } @ARGV) . "\x01"; |
| 360 |
|
356 |
|
| 361 |
# Debug mode activated via command line |
357 |
# Where to send debugging log output. Initialized to STDERR until the command |
| 362 |
if ($argstr =~ s/\x01--debug\x01/\x01/) { |
358 |
# line arguments are parsed. |
| 363 |
$debug = 1; |
359 |
my $logh = *STDERR; |
| 364 |
} |
|
|
| 365 |
|
| 366 |
# Command line options for verbosity |
| 367 |
my $verbose = ($argstr =~ s/\x01-v\x01/\x01/); |
| 368 |
my $quiet = ($argstr =~ s/\x01-q\x01/\x01/); |
| 369 |
my $show_docs = ($argstr =~ s/\x01-d\x01/\x01/); |
| 370 |
my $do_docs; |
| 371 |
my $cupscolorprofile; |
| 372 |
|
| 373 |
# Where to send debugging log output to |
| 374 |
my $logh; |
| 375 |
|
| 376 |
if ($debug) { |
| 377 |
# Grotesquely unsecure; use for debugging only |
| 378 |
open LOG, "> ${logfile}.log"; |
| 379 |
$logh = *LOG; |
| 380 |
|
| 381 |
use IO::Handle; |
| 382 |
$logh->autoflush(1); |
| 383 |
} elsif (($quiet) && (!$verbose)) { |
| 384 |
# Quiet mode, do not log |
| 385 |
close $logh; |
| 386 |
open LOG, "> /dev/null"; |
| 387 |
$logh = *LOG; |
| 388 |
|
| 389 |
use IO::Handle; |
| 390 |
$logh->autoflush(1); |
| 391 |
} else { |
| 392 |
# Default: log to STDERR |
| 393 |
$logh=*STDERR; |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
## Start debug logging |
| 399 |
if ($debug) { |
| 400 |
# If we are not in debug mode, we do this later, as we must find out at |
| 401 |
# first which spooler is used. When printing without spooler we |
| 402 |
# suppress logging because foomatic-rip is called directly on the |
| 403 |
# command line and so we avoid logging onto the console. |
| 404 |
print $logh "foomatic-rip version $ripversion running...\n"; |
| 405 |
# Print the command line only in debug mode, Mac OS X adds very many |
| 406 |
# options so that CUPS cannot handle the output of the command line |
| 407 |
# in its log files. If CUPS encounters a line with more than 1024 |
| 408 |
# characters sent into its log files, it aborts the job with an error. |
| 409 |
if (($debug) || ($spooler ne 'cups')) { |
| 410 |
print $logh "called with arguments: '", join("', '",@ARGV), "'\n"; |
| 411 |
} |
| 412 |
} |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
## Continue with named options |
| 417 |
|
| 418 |
# Check for LPRng first so we do not pick up bogus ppd files by the -p option |
| 419 |
if ($argstr =~ s/\x01--lprng\x01/\x01/) { |
| 420 |
# We have LPRng |
| 421 |
$spooler = 'lprng'; |
| 422 |
} |
| 423 |
# 'PRINTCAP_ENTRY' environment variable is : LPRng |
| 424 |
# the :ppd=/path/to/ppdfile printcap entry should be used |
| 425 |
if (defined($ENV{'PRINTCAP_ENTRY'})){ |
| 426 |
$spooler = 'lprng'; |
| 427 |
my( @pc); |
| 428 |
@pc = split( /\s*:\s*/, $ENV{'PRINTCAP_ENTRY'} ); |
| 429 |
shift @pc; |
| 430 |
foreach (@pc) { |
| 431 |
if( /^ppd=(.*)$/ or /^ppdfile=(.*)$/ ){ |
| 432 |
$ppdfile = removespecialchars($1) if $1; |
| 433 |
} |
| 434 |
} |
| 435 |
} elsif ($argstr =~ s/\x01--lprng\x01/\x01/g) { |
| 436 |
# We have LPRng |
| 437 |
$spooler = 'lprng'; |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
# PPD file name given via the command line |
| 442 |
# allow duplicates, and use the last specified one |
| 443 |
while ( ($spooler ne 'lprng') and ($argstr =~ s/\x01-p(\x01|)([^\x01]+)\x01/\x01/)) { |
| 444 |
$ppdfile = removeshellescapes($2); |
| 445 |
} |
| 446 |
while ($argstr =~ s/\x01--ppd(\x01|=|)([^\x01]+)\x01/\x01/) { |
| 447 |
$ppdfile = removeshellescapes($2); |
| 448 |
} |
| 449 |
|
| 450 |
# Check for LPD/GNUlpr by typical options which the spooler puts onto |
| 451 |
# the filter's command line (options "-w": text width, "-l": text |
| 452 |
# length, "-i": indent, "-x", "-y": graphics size, "-c": raw printing, |
| 453 |
# "-n": user name, "-h": host name) |
| 454 |
if (($argstr =~ s/\x01-w(\x01|)\d+\x01/\x01/) || |
| 455 |
($argstr =~ s/\x01-l(\x01|)\d+\x01/\x01/) || |
| 456 |
($argstr =~ s/\x01-x(\x01|)\d+\x01/\x01/) || |
| 457 |
($argstr =~ s/\x01-y(\x01|)\d+\x01/\x01/) || |
| 458 |
($argstr =~ s/\x01-i(\x01|)\d+\x01/\x01/) || |
| 459 |
($argstr =~ s/\x01-c\x01/\x01/) || |
| 460 |
($argstr =~ s/\x01-n(\x01|)[^\x01]+\x01/\x01/) || |
| 461 |
($argstr =~ s/\x01-h(\x01|)[^\x01]+\x01/\x01/)) { |
| 462 |
# We have LPD or GNUlpr |
| 463 |
if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) { |
| 464 |
$spooler = 'lpd'; |
| 465 |
} |
| 466 |
} |
| 467 |
|
360 |
|
| 468 |
# LPRng delivers the option settings via the "-Z" argument |
361 |
## Named command line options |
| 469 |
if ($argstr =~ s/\x01-Z(\x01|)([^\x01]+)\x01/\x01/) { |
|
|
| 470 |
my @lpopts = split(/,/, $2); |
| 471 |
foreach my $opt (@lpopts) { |
| 472 |
$opt =~ s/^\s+//; |
| 473 |
$opt =~ s/\s+$//; |
| 474 |
$opt = removeshellescapes($opt); |
| 475 |
if ($opt =~ /\s+/) { |
| 476 |
$opt = "\"$opt\""; |
| 477 |
} |
| 478 |
$optstr .= "$opt "; |
| 479 |
} |
| 480 |
# We have LPRng |
| 481 |
$spooler = 'lprng'; |
| 482 |
} |
| 483 |
|
362 |
|
| 484 |
# Job title and options for stock LPD |
363 |
my ($verbose, $quiet, $show_docs, $do_docs, $cupscolorprofile, $genpdqfile); |
| 485 |
if ($argstr =~ s/\x01-[jJ](\x01|)([^\x01]+)\x01/\x01/) { |
|
|
| 486 |
# An LPD |
| 487 |
$jobtitle = removeshellescapes($2); |
| 488 |
# Classic LPD hack |
| 489 |
if ($spooler eq "lpd") { |
| 490 |
$optstr .= "$jobtitle "; |
| 491 |
} |
| 492 |
} |
| 493 |
|
364 |
|
| 494 |
# Check for CPS |
365 |
# CUPS calls foomatic-rip only with 5 or 6 positional parameters, |
| 495 |
if ($argstr =~ s/\x01--cps\x01/\x01/) { |
366 |
# not with named options, like for example "-p <string>". Also PPR |
| 496 |
# We have cps |
367 |
# does not used named options. |
| 497 |
$spooler = 'cps'; |
368 |
if (($spooler ne 'cups') && ($spooler ne 'ppr') && ($spooler ne 'ppr_int')) { |
| 498 |
} |
369 |
|
|
|
370 |
# Debug mode activated via command line |
| 371 |
if ($argstr =~ s/\x01--debug\x01/\x01/) { |
| 372 |
$debug = 1; |
| 373 |
} |
| 374 |
|
| 375 |
# Command line options for verbosity |
| 376 |
$verbose = ($argstr =~ s/\x01-v\x01/\x01/); |
| 377 |
$quiet = ($argstr =~ s/\x01-q\x01/\x01/); |
| 378 |
$show_docs = ($argstr =~ s/\x01-d\x01/\x01/); |
| 379 |
|
| 380 |
if ($debug) { |
| 381 |
# Grotesquely unsecure; use for debugging only |
| 382 |
open LOG, "> ${logfile}.log"; |
| 383 |
$logh = *LOG; |
| 384 |
|
| 385 |
use IO::Handle; |
| 386 |
$logh->autoflush(1); |
| 387 |
} elsif (($quiet) && (!$verbose)) { |
| 388 |
# Quiet mode, do not log |
| 389 |
close $logh; |
| 390 |
open LOG, "> /dev/null"; |
| 391 |
$logh = *LOG; |
| 499 |
|
392 |
|
| 500 |
# Options for spooler-less printing, CPS, or PDQ |
393 |
use IO::Handle; |
| 501 |
while ($argstr =~ s/\x01-o(\x01|)([^\x01]+)\x01/\x01/) { |
394 |
$logh->autoflush(1); |
| 502 |
my $opt = $2; |
395 |
} else { |
| 503 |
$opt =~ s/^\s+//; |
396 |
# Default: log to STDERR |
| 504 |
$opt =~ s/\s+$//; |
397 |
$logh=*STDERR; |
| 505 |
$opt = removeshellescapes($opt); |
|
|
| 506 |
if ($opt =~ /\s+/) { |
| 507 |
$opt = "\"$opt\""; |
| 508 |
} |
| 509 |
$optstr .= "$opt "; |
| 510 |
# If we don't print as a PPR RIP or as a CPS filter, we print without |
| 511 |
# spooler (we check for PDQ later) |
| 512 |
if (($spooler ne 'ppr') && ($spooler ne 'cps')) { |
| 513 |
$spooler = 'direct'; |
| 514 |
} |
398 |
} |
| 515 |
} |
|
|
| 516 |
|
399 |
|
| 517 |
# Printer for spooler-less printing or PDQ |
|
|
| 518 |
if ($argstr =~ s/\x01-d(\x01|)([^\x01]+)\x01/\x01/) { |
| 519 |
$printer = removeshellescapes($2); |
| 520 |
} |
| 521 |
# Printer for spooler-less printing, PDQ, or LPRng |
| 522 |
if ($argstr =~ s/\x01-P(\x01|)([^\x01]+)\x01/\x01/) { |
| 523 |
$printer = removeshellescapes($2); |
| 524 |
} |
| 525 |
|
400 |
|
| 526 |
# Were we called from a PDQ wrapper? |
|
|
| 527 |
if ($argstr =~ s/\x01--pdq\x01/\x01/) { |
| 528 |
# We have PDQ |
| 529 |
$spooler = 'pdq'; |
| 530 |
} |
| 531 |
|
401 |
|
| 532 |
# Were we called to build the PDQ driver declaration file? |
402 |
## Start debug logging |
| 533 |
# "--appendpdq=<file>" appends the data to the <file>, |
403 |
if ($debug) { |
| 534 |
# "--genpdq=<file>" creates/overwrites <file> for the data, and |
404 |
# If we are not in debug mode, we do this later, as we must find out at |
| 535 |
# "--genpdq" writes to standard output |
405 |
# first which spooler is used. When printing without spooler we |
| 536 |
my $genpdqfile = ""; |
406 |
# suppress logging because foomatic-rip is called directly on the |
| 537 |
if (($argstr =~ s/\x01--(gen)(raw|)pdq(\x01|=|)([^\x01]*)\x01/\x01/) || |
407 |
# command line and so we avoid logging onto the console. |
| 538 |
($argstr =~ s/\x01--(append)(raw|)pdq(\x01|=|)([^\x01]+)\x01/\x01/)) { |
408 |
print $logh "foomatic-rip version $ripversion running...\n"; |
| 539 |
# Determine output file name |
409 |
# Print the command line only in debug mode, Mac OS X adds very many |
| 540 |
if (!$4) { |
410 |
# options so that CUPS cannot handle the output of the command line |
| 541 |
$genpdqfile = ">&STDOUT"; |
411 |
# in its log files. If CUPS encounters a line with more than 1024 |
| 542 |
} else { |
412 |
# characters sent into its log files, it aborts the job with an error. |
| 543 |
if ($1 eq 'gen') { |
413 |
if (($debug) || ($spooler ne 'cups')) { |
| 544 |
$genpdqfile = "> " . removeshellescapes($4); |
414 |
print $logh "called with arguments: '", join("', '",@ARGV), "'\n"; |
| 545 |
} else { |
415 |
} |
| 546 |
$genpdqfile = ">> " . removeshellescapes($4); |
416 |
} |
| 547 |
} |
417 |
|
| 548 |
} |
418 |
|
| 549 |
# Do we want to have a PDQ driver declaration for a raw printer? |
419 |
|
| 550 |
if ($2 eq 'raw') { |
420 |
## Continue with named options |
| 551 |
my $time = time(); |
421 |
|
| 552 |
my @pdqfile = |
422 |
# Check for LPRng first so we do not pick up bogus ppd files by the -p option |
|
|
423 |
if ($argstr =~ s/\x01--lprng\x01/\x01/) { |
| 424 |
# We have LPRng |
| 425 |
$spooler = 'lprng'; |
| 426 |
} |
| 427 |
# 'PRINTCAP_ENTRY' environment variable is : LPRng |
| 428 |
# the :ppd=/path/to/ppdfile printcap entry should be used |
| 429 |
if (defined($ENV{'PRINTCAP_ENTRY'})){ |
| 430 |
$spooler = 'lprng'; |
| 431 |
my( @pc); |
| 432 |
@pc = split( /\s*:\s*/, $ENV{'PRINTCAP_ENTRY'} ); |
| 433 |
shift @pc; |
| 434 |
foreach (@pc) { |
| 435 |
if( /^ppd=(.*)$/ or /^ppdfile=(.*)$/ ){ |
| 436 |
$ppdfile = removespecialchars($1) if $1; |
| 437 |
} |
| 438 |
} |
| 439 |
} elsif ($argstr =~ s/\x01--lprng\x01/\x01/g) { |
| 440 |
# We have LPRng |
| 441 |
$spooler = 'lprng'; |
| 442 |
} |
| 443 |
|
| 444 |
# Check for LPD/GNUlpr by typical options which the spooler puts onto |
| 445 |
# the filter's command line (options "-w": text width, "-l": text |
| 446 |
# length, "-i": indent, "-x", "-y": graphics size, "-c": raw printing, |
| 447 |
# "-n": user name, "-h": host name) |
| 448 |
if (($argstr =~ s/\x01-w(\x01|)\d+\x01/\x01/) || |
| 449 |
($argstr =~ s/\x01-l(\x01|)\d+\x01/\x01/) || |
| 450 |
($argstr =~ s/\x01-x(\x01|)\d+\x01/\x01/) || |
| 451 |
($argstr =~ s/\x01-y(\x01|)\d+\x01/\x01/) || |
| 452 |
($argstr =~ s/\x01-i(\x01|)\d+\x01/\x01/) || |
| 453 |
($argstr =~ s/\x01-c\x01/\x01/) || |
| 454 |
($argstr =~ s/\x01-n(\x01|)[^\x01]+\x01/\x01/) || |
| 455 |
($argstr =~ s/\x01-h(\x01|)[^\x01]+\x01/\x01/)) { |
| 456 |
# We have LPD or GNUlpr |
| 457 |
if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) { |
| 458 |
$spooler = 'lpd'; |
| 459 |
} |
| 460 |
} |
| 461 |
|
| 462 |
# PPD file name given via the command line |
| 463 |
# allow duplicates, and use the last specified one |
| 464 |
if (($spooler ne 'lprng') && ($spooler ne 'lpd') && ($spooler ne 'gnulpr')){ |
| 465 |
while ($argstr =~ s/\x01-p(\x01|)([^\x01]+)\x01/\x01/) { |
| 466 |
$ppdfile = removeshellescapes($2); |
| 467 |
} |
| 468 |
while ($argstr =~ s/\x01--ppd(\x01|=|)([^\x01]+)\x01/\x01/) { |
| 469 |
$ppdfile = removeshellescapes($2); |
| 470 |
} |
| 471 |
} |
| 472 |
|
| 473 |
# LPRng delivers the option settings via the "-Z" argument |
| 474 |
if ($argstr =~ s/\x01-Z(\x01|)([^\x01]+)\x01/\x01/) { |
| 475 |
my @lpopts = split(/,/, $2); |
| 476 |
foreach my $opt (@lpopts) { |
| 477 |
$opt =~ s/^\s+//; |
| 478 |
$opt =~ s/\s+$//; |
| 479 |
$opt = removeshellescapes($opt); |
| 480 |
if ($opt =~ /\s+/) { |
| 481 |
$opt = "\"$opt\""; |
| 482 |
} |
| 483 |
$optstr .= "$opt "; |
| 484 |
} |
| 485 |
# We have LPRng |
| 486 |
$spooler = 'lprng'; |
| 487 |
} |
| 488 |
|
| 489 |
# Job title and options for stock LPD |
| 490 |
if ($argstr =~ s/\x01-[jJ](\x01|)([^\x01]+)\x01/\x01/) { |
| 491 |
# An LPD |
| 492 |
$jobtitle = removeshellescapes($2); |
| 493 |
# Classic LPD hack |
| 494 |
if ($spooler eq "lpd") { |
| 495 |
$optstr .= "$jobtitle "; |
| 496 |
} |
| 497 |
} |
| 498 |
|
| 499 |
# Check for CPS |
| 500 |
if ($argstr =~ s/\x01--cps\x01/\x01/) { |
| 501 |
# We have cps |
| 502 |
$spooler = 'cps'; |
| 503 |
} |
| 504 |
|
| 505 |
# Options for spooler-less printing, CPS, or PDQ |
| 506 |
while ($argstr =~ s/\x01-o(\x01|)([^\x01]+)\x01/\x01/) { |
| 507 |
my $opt = $2; |
| 508 |
$opt =~ s/^\s+//; |
| 509 |
$opt =~ s/\s+$//; |
| 510 |
$opt = removeshellescapes($opt); |
| 511 |
if ($opt =~ /\s+/) { |
| 512 |
$opt = "\"$opt\""; |
| 513 |
} |
| 514 |
$optstr .= "$opt "; |
| 515 |
# If we don't print as a PPR RIP or as a CPS filter, we print without |
| 516 |
# spooler (we check for PDQ later) |
| 517 |
if (($spooler ne 'ppr') && ($spooler ne 'cps')) { |
| 518 |
$spooler = 'direct'; |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
# Printer for spooler-less printing or PDQ |
| 523 |
if ($argstr =~ s/\x01-d(\x01|)([^\x01]+)\x01/\x01/) { |
| 524 |
$printer = removeshellescapes($2); |
| 525 |
} |
| 526 |
# Printer for spooler-less printing, PDQ, or LPRng |
| 527 |
if ($argstr =~ s/\x01-P(\x01|)([^\x01]+)\x01/\x01/) { |
| 528 |
$printer = removeshellescapes($2); |
| 529 |
} |
| 530 |
|
| 531 |
# Were we called from a PDQ wrapper? |
| 532 |
if ($argstr =~ s/\x01--pdq\x01/\x01/) { |
| 533 |
# We have PDQ |
| 534 |
$spooler = 'pdq'; |
| 535 |
} |
| 536 |
|
| 537 |
# Were we called to build the PDQ driver declaration file? |
| 538 |
# "--appendpdq=<file>" appends the data to the <file>, |
| 539 |
# "--genpdq=<file>" creates/overwrites <file> for the data, and |
| 540 |
# "--genpdq" writes to standard output |
| 541 |
$genpdqfile = ""; |
| 542 |
if (($argstr =~ s/\x01--(gen)(raw|)pdq(\x01|=|)([^\x01]*)\x01/\x01/) || |
| 543 |
($argstr =~ s/\x01--(append)(raw|)pdq(\x01|=|)([^\x01]+)\x01/\x01/)) { |
| 544 |
# Determine output file name |
| 545 |
if (!$4) { |
| 546 |
$genpdqfile = ">&STDOUT"; |
| 547 |
} else { |
| 548 |
if ($1 eq 'gen') { |
| 549 |
$genpdqfile = "> " . removeshellescapes($4); |
| 550 |
} else { |
| 551 |
$genpdqfile = ">> " . removeshellescapes($4); |
| 552 |
} |
| 553 |
} |
| 554 |
# Do we want to have a PDQ driver declaration for a raw printer? |
| 555 |
if ($2 eq 'raw') { |
| 556 |
my $time = time(); |
| 557 |
my @pdqfile = |
| 553 |
"driver \"Raw-Printer-$time\" { |
558 |
"driver \"Raw-Printer-$time\" { |
| 554 |
# This PDQ driver declaration file was generated automatically by |
559 |
# This PDQ driver declaration file was generated automatically by |
| 555 |
# foomatic-rip to allow raw (filter-less) printing. |
560 |
# foomatic-rip to allow raw (filter-less) printing. |
|
Lines 561-583
if (($argstr =~ s/\x01--(gen)(raw|)pdq(\
Link Here
|
| 561 |
} |
566 |
} |
| 562 |
} |
567 |
} |
| 563 |
filter_exec { |
568 |
filter_exec { |
| 564 |
ln -s \$INPUT \$OUTPUT |
569 |
ln -s \$INPUT \$OUTPUT |
| 565 |
} |
570 |
} |
| 566 |
}"; |
571 |
}"; |
| 567 |
open PDQFILE, $genpdqfile or |
572 |
open PDQFILE, $genpdqfile or |
| 568 |
rip_die("Cannot write PDQ driver declaration file", |
573 |
rip_die("Cannot write PDQ driver declaration file", |
| 569 |
$EXIT_PRNERR_NORETRY_BAD_SETTINGS); |
574 |
$EXIT_PRNERR_NORETRY_BAD_SETTINGS); |
| 570 |
print PDQFILE join('', @pdqfile); |
575 |
print PDQFILE join('', @pdqfile); |
| 571 |
close PDQFILE; |
576 |
close PDQFILE; |
| 572 |
exit $EXIT_PRINTED; |
577 |
exit $EXIT_PRINTED; |
|
|
578 |
} |
| 579 |
# We have PDQ |
| 580 |
$spooler = 'pdq'; |
| 573 |
} |
581 |
} |
| 574 |
# We have PDQ |
|
|
| 575 |
$spooler = 'pdq'; |
| 576 |
} |
| 577 |
|
582 |
|
| 578 |
|
583 |
|
| 579 |
# remove extra spacing if running as LPRng filter |
584 |
# remove extra spacing if running as LPRng filter |
| 580 |
$added_lf = "" if $spooler eq 'lprng'; |
585 |
$added_lf = "" if $spooler eq 'lprng'; |
|
|
586 |
|
| 587 |
} |
| 581 |
|
588 |
|
| 582 |
## Command line arguments without name |
589 |
## Command line arguments without name |
| 583 |
|
590 |
|