View | Details | Raw Unified | Return to bug 698451
Collapse All | Expand All

(-)foomatic-rip.in (-214 / +221 lines)
Lines 404-413 Link Here
404
    $spooler = 'gnulpr';
404
    $spooler = 'gnulpr';
405
}
405
}
406
406
407
408
409
## Named command line options
410
411
# We do not use Getopt::Long because it does not work when between the
407
# We do not use Getopt::Long because it does not work when between the
412
# option and the argument is no space ("-w80" instead of "-w 80"). This
408
# option and the argument is no space ("-w80" instead of "-w 80"). This
413
# happens in the command line of LPRng, but also users could type in
409
# happens in the command line of LPRng, but also users could type in
Lines 425-562 Link Here
425
my $argstr = "\x01" . 
421
my $argstr = "\x01" . 
426
    join("\x01", map { removeunprintables($_) } @ARGV) . "\x01";
422
    join("\x01", map { removeunprintables($_) } @ARGV) . "\x01";
427
423
428
# Version check
424
my ($verbose, $quiet, $show_docs, $do_docs, $cupscolorprofile, $genpdqfile);
429
if ($argstr =~ /^\x01-(h|v|-help|-version)\x01$/i) {
425
430
    my $ver;
426
## Named command line options
431
    if ($ripversion =~ /^\$Revision=(.*)\$$/) {
427
432
	$ver = $1;
428
# CUPS calls foomatic-rip only with 5 or 6 positional parameters,
429
# not with named options, like for example "-p <string>". Also PPR
430
# does not used named options.
431
if (($spooler ne 'cups') && ($spooler ne 'ppr') && ($spooler ne 'ppr_int')) {
432
433
    # Version check
434
    if ($argstr =~ /^\x01-(h|v|-help|-version)\x01$/i) {
435
	my $ver;
436
	if ($ripversion =~ /^\$Revision=(.*)\$$/) {
437
	    $ver = $1;
438
	} else {
439
	    $ver = "Unknown";
440
	}
441
	print "foomatic-rip revision $ver\n";
442
	print "\"man foomatic-rip\" for help.\n";
443
	exit 0;
444
    }
445
446
    # Debug mode activated via command line
447
    if ($argstr =~ s/\x01--debug\x01/\x01/) {
448
	$debug = 1;
449
    }
450
451
    # Command line options for verbosity
452
    $verbose = ($argstr =~ s/\x01-v\x01/\x01/);
453
    $quiet = ($argstr =~ s/\x01-q\x01/\x01/);
454
    $show_docs = ($argstr =~ s/\x01-d\x01/\x01/);
455
456
    if ($debug) {
457
	# Grotesquely unsecure; use for debugging only
458
	open LOG, "> ${logfile}.log";
459
	$logh = *LOG;
460
461
	use IO::Handle;
462
	$logh->autoflush(1);
463
    } elsif (($quiet) && (!$verbose)) {
464
	# Quiet mode, do not log
465
	open LOG, "> /dev/null";
466
	$logh = *LOG;
467
468
	use IO::Handle;
469
	$logh->autoflush(1);
433
    } else {
470
    } else {
434
	$ver = "Unknown";
471
	# Default: log to STDERR
435
    }
472
	$logh=*STDERR;
436
    print "foomatic-rip revision $ver\n";
473
    }
437
    print "\"man foomatic-rip\" for help.\n";
474
438
    exit 0;
475
439
}
476
440
477
    ## Start debug logging
441
# Debug mode activated via command line
478
    if ($debug) {
442
if ($argstr =~ s/\x01--debug\x01/\x01/) {
479
	# If we are not in debug mode, we do this later, as we must find out at
443
    $debug = 1;
480
	# first which spooler is used. When printing without spooler we
444
}
481
	# suppress logging because foomatic-rip is called directly on the
445
482
	# command line and so we avoid logging onto the console.
446
# Command line options for verbosity
483
	print $logh "foomatic-rip version $ripversion running...\n";
447
my $verbose = ($argstr =~ s/\x01-v\x01/\x01/);
484
	# Print the command line only in debug mode, Mac OS X adds very many
448
my $quiet = ($argstr =~ s/\x01-q\x01/\x01/);
485
	# options so that CUPS cannot handle the output of the command line
449
my $show_docs = ($argstr =~ s/\x01-d\x01/\x01/);
486
	# in its log files. If CUPS encounters a line with more than 1024
450
my $do_docs;
487
	# characters sent into its log files, it aborts the job with an error.
451
my $cupscolorprofile;
488
	if (($debug) || ($spooler ne 'cups')) {
452
489
	    print $logh "called with arguments: '", join("', '",@ARGV), "'\n";
453
if ($debug) {
490
	}
454
    # Grotesquely unsecure; use for debugging only
491
    }
455
    open LOG, "> ${logfile}.log";
492
456
    $logh = *LOG;
493
457
494
458
    use IO::Handle;
495
    ## Continue with named options
459
    $logh->autoflush(1);
496
460
} elsif (($quiet) && (!$verbose)) {
497
    # Check for LPRng first so we do not pick up bogus ppd files by the -p
461
    # Quiet mode, do not log
498
    # option
462
    open LOG, "> /dev/null";
499
    if ($argstr =~ s/\x01--lprng\x01/\x01/) {
463
    $logh = *LOG;
500
	# We have LPRng
464
501
	$spooler = 'lprng';
465
    use IO::Handle;
502
    }
466
    $logh->autoflush(1);
503
    # 'PRINTCAP_ENTRY' environment variable is : LPRng
467
} else {
504
    #  the :ppd=/path/to/ppdfile printcap entry should be used
468
    # Default: log to STDERR
505
    if (defined($ENV{'PRINTCAP_ENTRY'})){
469
    $logh=*STDERR;
470
}
471
472
473
474
## Start debug logging
475
if ($debug) {
476
    # If we are not in debug mode, we do this later, as we must find out at
477
    # first which spooler is used. When printing without spooler we
478
    # suppress logging because foomatic-rip is called directly on the
479
    # command line and so we avoid logging onto the console.
480
    print $logh "foomatic-rip version $ripversion running...\n";
481
    # Print the command line only in debug mode, Mac OS X adds very many
482
    # options so that CUPS cannot handle the output of the command line
483
    # in its log files. If CUPS encounters a line with more than 1024
484
    # characters sent into its log files, it aborts the job with an error.
485
    if (($debug) || ($spooler ne 'cups')) {
486
	print $logh "called with arguments: '", join("', '",@ARGV), "'\n";
487
    }
488
}
489
490
491
492
## Continue with named options
493
494
# Check for LPRng first so we do not pick up bogus ppd files by the -p option
495
if ($argstr =~ s/\x01--lprng\x01/\x01/) {
496
    # We have LPRng
497
    $spooler = 'lprng';
498
}
499
# 'PRINTCAP_ENTRY' environment variable is : LPRng
500
#  the :ppd=/path/to/ppdfile printcap entry should be used
501
if (defined($ENV{'PRINTCAP_ENTRY'})){
502
	$spooler = 'lprng';
506
	$spooler = 'lprng';
503
	my( @pc);
507
	my( @pc);
504
	@pc = split( /\s*:\s*/, $ENV{'PRINTCAP_ENTRY'} );
508
	@pc = split( /\s*:\s*/, $ENV{'PRINTCAP_ENTRY'} );
505
	shift @pc;
509
	shift @pc;
506
	foreach (@pc) {
510
	foreach (@pc) {
507
		if( /^ppd=(.*)$/ or  /^ppdfile=(.*)$/ ){
511
	    if( /^ppd=(.*)$/ or  /^ppdfile=(.*)$/ ){
508
			$ppdfile = removespecialchars($1) if $1;
512
		$ppdfile = removespecialchars($1) if $1;
509
		}
513
	    }
510
	}
514
	}
511
} elsif ($argstr =~ s/\x01--lprng\x01/\x01/g) {
515
    } elsif ($argstr =~ s/\x01--lprng\x01/\x01/g) {
512
    # We have LPRng
516
	# We have LPRng
513
    $spooler = 'lprng';
517
	$spooler = 'lprng';
514
}
518
    }
515
519
516
520
    # Check for LPD/GNUlpr by typical options which the spooler puts onto
517
# PPD file name given via the command line
521
    # the filter's command line (options "-w": text width, "-l": text
518
# allow duplicates, and use the last specified one
522
    # length, "-i": indent, "-x", "-y": graphics size, "-c": raw printing,
519
while ( ($spooler ne 'lprng') and ($argstr =~ s/\x01-p(\x01|)([^\x01]+)\x01/\x01/)) {
523
    # "-n": user name, "-h": host name)
520
    $ppdfile = $2;
524
    if ($argstr =~ s/\x01-h(\x01|)([^\x01]+)\x01/\x01/) {
521
}
525
	# We have LPD or GNUlpr
522
while ($argstr =~ s/\x01--ppd(\x01|=|)([^\x01]+)\x01/\x01/) {
526
	if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) {
523
    $ppdfile = $2;
527
	    $spooler = 'lpd';
524
}
528
	}
525
529
	$jobhost = $2;
526
# Check for LPD/GNUlpr by typical options which the spooler puts onto
530
    }
527
# the filter's command line (options "-w": text width, "-l": text
531
    if ($argstr =~ s/\x01-n(\x01|)([^\x01]+)\x01/\x01/) {
528
# length, "-i": indent, "-x", "-y": graphics size, "-c": raw printing,
532
	# We have LPD or GNUlpr
529
# "-n": user name, "-h": host name)
533
	if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) {
530
if ($argstr =~ s/\x01-h(\x01|)([^\x01]+)\x01/\x01/) {
534
	    $spooler = 'lpd';
531
    # We have LPD or GNUlpr
535
	}
532
    if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) {
536
	$jobuser = $2;
533
	$spooler = 'lpd';
537
    }
534
    }
538
    if (($argstr =~ s/\x01-w(\x01|)\d+\x01/\x01/) ||
535
    $jobhost = $2;
539
	($argstr =~ s/\x01-l(\x01|)\d+\x01/\x01/) || 
536
}
540
	($argstr =~ s/\x01-x(\x01|)\d+\x01/\x01/) ||
537
if ($argstr =~ s/\x01-n(\x01|)([^\x01]+)\x01/\x01/) {
541
	($argstr =~ s/\x01-y(\x01|)\d+\x01/\x01/) || 
538
    # We have LPD or GNUlpr
542
	($argstr =~ s/\x01-i(\x01|)\d+\x01/\x01/) ||
539
    if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) {
543
	($argstr =~ s/\x01-c\x01/\x01/)) {
540
	$spooler = 'lpd';
544
	# We have LPD or GNUlpr
541
    }
545
	if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) {
542
    $jobuser = $2;
546
	    $spooler = 'lpd';
543
}
547
	}
544
if (($argstr =~ s/\x01-w(\x01|)\d+\x01/\x01/) ||
548
    }
545
    ($argstr =~ s/\x01-l(\x01|)\d+\x01/\x01/) || 
549
546
    ($argstr =~ s/\x01-x(\x01|)\d+\x01/\x01/) ||
550
    # PPD file name given via the command line
547
    ($argstr =~ s/\x01-y(\x01|)\d+\x01/\x01/) || 
551
    # allow duplicates, and use the last specified one
548
    ($argstr =~ s/\x01-i(\x01|)\d+\x01/\x01/) ||
552
    if (($spooler ne 'lprng') && ($spooler ne 'lpd') && ($spooler ne 'gnulpr')){
549
    ($argstr =~ s/\x01-c\x01/\x01/)) {
553
	while ($argstr =~ s/\x01-p(\x01|)([^\x01]+)\x01/\x01/) {
550
    # We have LPD or GNUlpr
554
	    $ppdfile = $2;
551
    if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) {
555
	}
552
	$spooler = 'lpd';
556
	while ($argstr =~ s/\x01--ppd(\x01|=|)([^\x01]+)\x01/\x01/) {
553
    }
557
	    $ppdfile = $2;
554
}
558
	}
555
559
    }
556
# LPRng delivers the option settings via the "-Z" argument
560
557
if ($argstr =~ s/\x01-Z(\x01|)([^\x01]+)\x01/\x01/) {
561
    # LPRng delivers the option settings via the "-Z" argument
558
    my @lpopts = split(/,/, $2);
562
    if ($argstr =~ s/\x01-Z(\x01|)([^\x01]+)\x01/\x01/) {
559
    foreach my $opt (@lpopts) {
563
	my @lpopts = split(/,/, $2);
564
	foreach my $opt (@lpopts) {
565
	    $opt =~ s/^\s+//;
566
	    $opt =~ s/\s+$//;
567
	    $opt = removeshellescapes($opt);
568
	    if ($opt =~ /\s+/) {
569
		$opt = "\"$opt\"";
570
	    }
571
	    $optstr .= "$opt ";
572
	}
573
	# We have LPRng
574
	$spooler = 'lprng';
575
    }
576
577
    # Job title and options for stock LPD
578
    if ($argstr =~ s/\x01-[jJ](\x01|)([^\x01]+)\x01/\x01/) {
579
	# An LPD
580
	$jobtitle = removeshellescapes($2);
581
	# Classic LPD hack
582
	if ($spooler eq "lpd") {
583
	    $optstr .= "$jobtitle ";
584
	}
585
    }
586
587
    # Check for CPS
588
    if ($argstr =~ s/\x01--cps\x01/\x01/) {
589
	# We have cps
590
	$spooler = 'cps';
591
    }
592
593
    # Options for spooler-less printing, CPS, or PDQ
594
    while ($argstr =~ s/\x01-o(\x01|)([^\x01]+)\x01/\x01/) {
595
	my $opt = $2;
560
	$opt =~ s/^\s+//;
596
	$opt =~ s/^\s+//;
561
	$opt =~ s/\s+$//;
597
	$opt =~ s/\s+$//;
562
	$opt = removeshellescapes($opt);
598
	$opt = removeshellescapes($opt);
Lines 564-643 Link Here
564
	    $opt = "\"$opt\"";
600
	    $opt = "\"$opt\"";
565
	}
601
	}
566
	$optstr .= "$opt ";
602
	$optstr .= "$opt ";
567
    }
603
	# If we don't print as a PPR RIP or as a CPS filter, we print without
568
    # We have LPRng
604
	# spooler (we check for PDQ later)
569
    $spooler = 'lprng';
605
	if (($spooler ne 'ppr') && ($spooler ne 'cps')) {
570
}
606
	    $spooler = 'direct';
571
607
	}
572
# Job title and options for stock LPD
608
    }
573
if ($argstr =~ s/\x01-[jJ](\x01|)([^\x01]+)\x01/\x01/) {
609
574
    # An LPD
610
    # Printer for spooler-less printing or PDQ
575
    $jobtitle = removeshellescapes($2);
611
    if ($argstr =~ s/\x01-d(\x01|)([^\x01]+)\x01/\x01/) {
576
    # Classic LPD hack
612
	$printer = removeshellescapes($2);
577
    if ($spooler eq "lpd") {
613
    }
578
	$optstr .= "$jobtitle ";
614
    # Printer for spooler-less printing, PDQ, or LPRng
579
    }
615
    if ($argstr =~ s/\x01-P(\x01|)([^\x01]+)\x01/\x01/) {
580
}
616
	$printer = removeshellescapes($2);
581
617
    }
582
# Check for CPS
618
583
if ($argstr =~ s/\x01--cps\x01/\x01/) {
619
    # Were we called from a PDQ wrapper?
584
    # We have cps
620
    if ($argstr =~ s/\x01--pdq\x01/\x01/) {
585
    $spooler = 'cps';
621
	# We have PDQ
586
}
622
	$spooler = 'pdq';
587
623
    }
588
# Options for spooler-less printing, CPS, or PDQ
624
589
while ($argstr =~ s/\x01-o(\x01|)([^\x01]+)\x01/\x01/) {
625
    # Were we called to build the PDQ driver declaration file?
590
    my $opt = $2;
626
    # "--appendpdq=<file>" appends the data to the <file>,
591
    $opt =~ s/^\s+//;
627
    # "--genpdq=<file>" creates/overwrites <file> for the data, and
592
    $opt =~ s/\s+$//;
628
    # "--genpdq" writes to standard output
593
    $opt = removeshellescapes($opt);
629
    $genpdqfile = "";
594
    if ($opt =~ /\s+/) {
630
    if (($argstr =~ s/\x01--(gen)(raw|)pdq(\x01|=|)([^\x01]*)\x01/\x01/) ||
595
	$opt = "\"$opt\"";
631
	($argstr =~ s/\x01--(append)(raw|)pdq(\x01|=|)([^\x01]+)\x01/\x01/)) {
596
    }
632
	# Determine output file name
597
    $optstr .= "$opt ";
633
	if (!$4) {
598
    # If we don't print as a PPR RIP or as a CPS filter, we print without
634
	    $genpdqfile = ">&STDOUT";
599
    # spooler (we check for PDQ later)
600
    if (($spooler ne 'ppr') && ($spooler ne 'cps')) {
601
	$spooler = 'direct';
602
    }
603
}
604
605
# Printer for spooler-less printing or PDQ
606
if ($argstr =~ s/\x01-d(\x01|)([^\x01]+)\x01/\x01/) {
607
    $printer = removeshellescapes($2);
608
}
609
# Printer for spooler-less printing, PDQ, or LPRng
610
if ($argstr =~ s/\x01-P(\x01|)([^\x01]+)\x01/\x01/) {
611
    $printer = removeshellescapes($2);
612
}
613
614
# Were we called from a PDQ wrapper?
615
if ($argstr =~ s/\x01--pdq\x01/\x01/) {
616
    # We have PDQ
617
    $spooler = 'pdq';
618
}
619
620
# Were we called to build the PDQ driver declaration file?
621
# "--appendpdq=<file>" appends the data to the <file>,
622
# "--genpdq=<file>" creates/overwrites <file> for the data, and
623
# "--genpdq" writes to standard output
624
my $genpdqfile = "";
625
if (($argstr =~ s/\x01--(gen)(raw|)pdq(\x01|=|)([^\x01]*)\x01/\x01/) ||
626
    ($argstr =~ s/\x01--(append)(raw|)pdq(\x01|=|)([^\x01]+)\x01/\x01/)) {
627
    # Determine output file name
628
    if (!$4) {
629
	$genpdqfile = ">&STDOUT";
630
    } else {
631
	if ($1 eq 'gen') {
632
	    $genpdqfile = "> " . removeshellescapes($4);
633
	} else {
635
	} else {
634
	    $genpdqfile = ">> " . removeshellescapes($4);
636
	    if ($1 eq 'gen') {
637
		$genpdqfile = "> " . removeshellescapes($4);
638
	    } else {
639
		$genpdqfile = ">> " . removeshellescapes($4);
640
	    }
635
	}
641
	}
636
    }
642
	# Do we want to have a PDQ driver declaration for a raw printer?
637
    # Do we want to have a PDQ driver declaration for a raw printer?
643
	if ($2 eq 'raw') {
638
    if ($2 eq 'raw') {
644
	    my $time = time();
639
	my $time = time();
645
	    my @pdqfile =
640
	my @pdqfile =
641
"driver \"Raw-Printer-$time\" {
646
"driver \"Raw-Printer-$time\" {
642
  # This PDQ driver declaration file was generated automatically by
647
  # This PDQ driver declaration file was generated automatically by
643
  # foomatic-rip to allow raw (filter-less) printing.
648
  # foomatic-rip to allow raw (filter-less) printing.
Lines 652-672 Link Here
652
    ln -s \$INPUT \$OUTPUT
657
    ln -s \$INPUT \$OUTPUT
653
  }
658
  }
654
}";
659
}";
655
	open PDQFILE, $genpdqfile or
660
	    open PDQFILE, $genpdqfile or
656
	    rip_die("Cannot write PDQ driver declaration file",
661
		rip_die("Cannot write PDQ driver declaration file",
657
		    $EXIT_PRNERR_NORETRY_BAD_SETTINGS);
662
			$EXIT_PRNERR_NORETRY_BAD_SETTINGS);
658
	print PDQFILE join('', @pdqfile);
663
	    print PDQFILE join('', @pdqfile);
659
	close PDQFILE;
664
	    close PDQFILE;
660
	exit $EXIT_PRINTED;
665
	    exit $EXIT_PRINTED;
666
	}
667
	# We have PDQ
668
	$spooler = 'pdq';
661
    }
669
    }
662
    # We have PDQ
670
663
    $spooler = 'pdq';
671
672
    # remove extra spacing if running as LPRng filter
673
    $added_lf = "" if $spooler eq 'lprng';
674
664
}
675
}
665
676
666
667
# remove extra spacing if running as LPRng filter
668
$added_lf = "" if $spooler eq 'lprng';
669
670
## Command line arguments without name
677
## Command line arguments without name
671
678
672
# Remaining arguments
679
# Remaining arguments

Return to bug 698451