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

(-)foomatic-gswrapper.in (-1 / +1 lines)
Lines 1-6 Link Here
1
#!@PERL@
1
#!@PERL@
2
# -*- perl -*-
2
# -*- perl -*-
3
# $Revision$
3
# $Revision=3.0.2.139$
4
4
5
# This is a little Ghostscript regularization script.  It massages
5
# This is a little Ghostscript regularization script.  It massages
6
# arguments to make Ghostscript execute properly as a filter, with
6
# arguments to make Ghostscript execute properly as a filter, with
(-)foomatic-rip.in (-229 / +235 lines)
Lines 5-11 Link Here
5
use POSIX;
5
use POSIX;
6
use Cwd;
6
use Cwd;
7
7
8
my $ripversion='$Revision$';
8
my $ripversion='$Revision=3.0.2.139$';
9
#'# Fix emacs syntax highlighting
9
#'# Fix emacs syntax highlighting
10
10
11
# foomatic-rip is a spooler-independent filter script which takes
11
# foomatic-rip is a spooler-independent filter script which takes
Lines 404-562 Link Here
404
    $spooler = 'gnulpr';
404
    $spooler = 'gnulpr';
405
}
405
}
406
406
407
407
my ($argstr, $verbose, $quiet, $show_docs, $do_docs, $cupscolorprofile,
408
    $genpdqfile);
408
409
409
## Named command line options
410
## Named command line options
410
411
411
# We do not use Getopt::Long because it does not work when between the
412
# CUPS calls foomatic-rip only with 5 or 6 positional parameters,
412
# option and the argument is no space ("-w80" instead of "-w 80"). This
413
# not with named options, like for example "-p <string>" */
413
# happens in the command line of LPRng, but also users could type in
414
if ($spooler ne 'cups') {
414
# options this way when printing without spooler.
415
415
416
    # We do not use Getopt::Long because it does not work when between the
416
# Make one option string with a non-printable character as separator,
417
    # option and the argument is no space ("-w80" instead of "-w 80"). This
417
# So we can parse it more easily.
418
    # happens in the command line of LPRng, but also users could type in
418
419
    # options this way when printing without spooler.
419
# To avoid the separator to be in the options itselves, it is filters
420
420
# out of the options. This does not break anything as having non
421
    # Make one option string with a non-printable character as separator,
421
# printable characters in the command line options does not make sense
422
    # So we can parse it more easily.
422
# nor is this needed. This way misinterpretation and even abuse is
423
423
# prevented.
424
    # To avoid the separator to be in the options itselves, it is filters
424
425
    # out of the options. This does not break anything as having non
425
my $argstr = "\x01" . 
426
    # printable characters in the command line options does not make sense
426
    join("\x01", map { removeunprintables($_) } @ARGV) . "\x01";
427
    # nor is this needed. This way misinterpretation and even abuse is
427
428
    # prevented.
428
# Version check
429
429
if ($argstr =~ /^\x01-(h|v|-help|-version)\x01$/i) {
430
    $argstr = "\x01" . 
430
    my $ver;
431
	join("\x01", map { removeunprintables($_) } @ARGV) . "\x01";
431
    if ($ripversion =~ /^\$Revision=(.*)\$$/) {
432
432
	$ver = $1;
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
517
# PPD file name given via the command line
521
    # PPD file name given via the command line
518
# allow duplicates, and use the last specified one
522
    # allow duplicates, and use the last specified one
519
while ( ($spooler ne 'lprng') and ($argstr =~ s/\x01-p(\x01|)([^\x01]+)\x01/\x01/)) {
523
    while ( ($spooler ne 'lprng') and ($argstr =~ s/\x01-p(\x01|)([^\x01]+)\x01/\x01/)) {
520
    $ppdfile = $2;
524
	$ppdfile = $2;
521
}
525
    }
522
while ($argstr =~ s/\x01--ppd(\x01|=|)([^\x01]+)\x01/\x01/) {
526
    while ($argstr =~ s/\x01--ppd(\x01|=|)([^\x01]+)\x01/\x01/) {
523
    $ppdfile = $2;
527
	$ppdfile = $2;
524
}
528
    }
525
529
526
# Check for LPD/GNUlpr by typical options which the spooler puts onto
530
    # Check for LPD/GNUlpr by typical options which the spooler puts onto
527
# the filter's command line (options "-w": text width, "-l": text
531
    # the filter's command line (options "-w": text width, "-l": text
528
# length, "-i": indent, "-x", "-y": graphics size, "-c": raw printing,
532
    # length, "-i": indent, "-x", "-y": graphics size, "-c": raw printing,
529
# "-n": user name, "-h": host name)
533
    # "-n": user name, "-h": host name)
530
if ($argstr =~ s/\x01-h(\x01|)([^\x01]+)\x01/\x01/) {
534
    if ($argstr =~ s/\x01-h(\x01|)([^\x01]+)\x01/\x01/) {
531
    # We have LPD or GNUlpr
535
	# We have LPD or GNUlpr
532
    if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) {
536
	if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) {
533
	$spooler = 'lpd';
537
	    $spooler = 'lpd';
534
    }
538
	}
535
    $jobhost = $2;
539
	$jobhost = $2;
536
}
540
    }
537
if ($argstr =~ s/\x01-n(\x01|)([^\x01]+)\x01/\x01/) {
541
    if ($argstr =~ s/\x01-n(\x01|)([^\x01]+)\x01/\x01/) {
538
    # We have LPD or GNUlpr
542
	# We have LPD or GNUlpr
539
    if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) {
543
	if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) {
540
	$spooler = 'lpd';
544
	    $spooler = 'lpd';
541
    }
545
	}
542
    $jobuser = $2;
546
	$jobuser = $2;
543
}
547
    }
544
if (($argstr =~ s/\x01-w(\x01|)\d+\x01/\x01/) ||
548
    if (($argstr =~ s/\x01-w(\x01|)\d+\x01/\x01/) ||
545
    ($argstr =~ s/\x01-l(\x01|)\d+\x01/\x01/) || 
549
	($argstr =~ s/\x01-l(\x01|)\d+\x01/\x01/) || 
546
    ($argstr =~ s/\x01-x(\x01|)\d+\x01/\x01/) ||
550
	($argstr =~ s/\x01-x(\x01|)\d+\x01/\x01/) ||
547
    ($argstr =~ s/\x01-y(\x01|)\d+\x01/\x01/) || 
551
	($argstr =~ s/\x01-y(\x01|)\d+\x01/\x01/) || 
548
    ($argstr =~ s/\x01-i(\x01|)\d+\x01/\x01/) ||
552
	($argstr =~ s/\x01-i(\x01|)\d+\x01/\x01/) ||
549
    ($argstr =~ s/\x01-c\x01/\x01/)) {
553
	($argstr =~ s/\x01-c\x01/\x01/)) {
550
    # We have LPD or GNUlpr
554
	# We have LPD or GNUlpr
551
    if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) {
555
	if (($spooler ne 'lpd') && ($spooler ne 'gnulpr') && ($spooler ne 'lprng')) {
552
	$spooler = 'lpd';
556
	    $spooler = 'lpd';
553
    }
557
	}
554
}
558
    }
555
559
556
# LPRng delivers the option settings via the "-Z" argument
560
    # LPRng delivers the option settings via the "-Z" argument
557
if ($argstr =~ s/\x01-Z(\x01|)([^\x01]+)\x01/\x01/) {
561
    if ($argstr =~ s/\x01-Z(\x01|)([^\x01]+)\x01/\x01/) {
558
    my @lpopts = split(/,/, $2);
562
	my @lpopts = split(/,/, $2);
559
    foreach my $opt (@lpopts) {
563
	foreach my $opt (@lpopts) {
564
	    $opt =~ s/^\s+//;
565
	    $opt =~ s/\s+$//;
566
	    $opt = removeshellescapes($opt);
567
	    if ($opt =~ /\s+/) {
568
		$opt = "\"$opt\"";
569
	    }
570
	    $optstr .= "$opt ";
571
	}
572
	# We have LPRng
573
	$spooler = 'lprng';
574
    }
575
576
    # Job title and options for stock LPD
577
    if ($argstr =~ s/\x01-[jJ](\x01|)([^\x01]+)\x01/\x01/) {
578
	# An LPD
579
	$jobtitle = removeshellescapes($2);
580
	# Classic LPD hack
581
	if ($spooler eq "lpd") {
582
	    $optstr .= "$jobtitle ";
583
	}
584
    }
585
586
    # Check for CPS
587
    if ($argstr =~ s/\x01--cps\x01/\x01/) {
588
	# We have cps
589
	$spooler = 'cps';
590
    }
591
592
    # Options for spooler-less printing, CPS, or PDQ
593
    while ($argstr =~ s/\x01-o(\x01|)([^\x01]+)\x01/\x01/) {
594
	my $opt = $2;
560
	$opt =~ s/^\s+//;
595
	$opt =~ s/^\s+//;
561
	$opt =~ s/\s+$//;
596
	$opt =~ s/\s+$//;
562
	$opt = removeshellescapes($opt);
597
	$opt = removeshellescapes($opt);
Lines 564-643 Link Here
564
	    $opt = "\"$opt\"";
599
	    $opt = "\"$opt\"";
565
	}
600
	}
566
	$optstr .= "$opt ";
601
	$optstr .= "$opt ";
567
    }
602
	# If we don't print as a PPR RIP or as a CPS filter, we print without
568
    # We have LPRng
603
	# spooler (we check for PDQ later)
569
    $spooler = 'lprng';
604
	if (($spooler ne 'ppr') && ($spooler ne 'cps')) {
570
}
605
	    $spooler = 'direct';
571
606
	}
572
# Job title and options for stock LPD
607
    }
573
if ($argstr =~ s/\x01-[jJ](\x01|)([^\x01]+)\x01/\x01/) {
608
574
    # An LPD
609
    # Printer for spooler-less printing or PDQ
575
    $jobtitle = removeshellescapes($2);
610
    if ($argstr =~ s/\x01-d(\x01|)([^\x01]+)\x01/\x01/) {
576
    # Classic LPD hack
611
	$printer = removeshellescapes($2);
577
    if ($spooler eq "lpd") {
612
    }
578
	$optstr .= "$jobtitle ";
613
    # Printer for spooler-less printing, PDQ, or LPRng
579
    }
614
    if ($argstr =~ s/\x01-P(\x01|)([^\x01]+)\x01/\x01/) {
580
}
615
	$printer = removeshellescapes($2);
581
616
    }
582
# Check for CPS
617
583
if ($argstr =~ s/\x01--cps\x01/\x01/) {
618
    # Were we called from a PDQ wrapper?
584
    # We have cps
619
    if ($argstr =~ s/\x01--pdq\x01/\x01/) {
585
    $spooler = 'cps';
620
	# We have PDQ
586
}
621
	$spooler = 'pdq';
587
622
    }
588
# Options for spooler-less printing, CPS, or PDQ
623
589
while ($argstr =~ s/\x01-o(\x01|)([^\x01]+)\x01/\x01/) {
624
    # Were we called to build the PDQ driver declaration file?
590
    my $opt = $2;
625
    # "--appendpdq=<file>" appends the data to the <file>,
591
    $opt =~ s/^\s+//;
626
    # "--genpdq=<file>" creates/overwrites <file> for the data, and
592
    $opt =~ s/\s+$//;
627
    # "--genpdq" writes to standard output
593
    $opt = removeshellescapes($opt);
628
    $genpdqfile = "";
594
    if ($opt =~ /\s+/) {
629
    if (($argstr =~ s/\x01--(gen)(raw|)pdq(\x01|=|)([^\x01]*)\x01/\x01/) ||
595
	$opt = "\"$opt\"";
630
	($argstr =~ s/\x01--(append)(raw|)pdq(\x01|=|)([^\x01]+)\x01/\x01/)) {
596
    }
631
	# Determine output file name
597
    $optstr .= "$opt ";
632
	if (!$4) {
598
    # If we don't print as a PPR RIP or as a CPS filter, we print without
633
	    $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 {
634
	} else {
634
	    $genpdqfile = ">> " . removeshellescapes($4);
635
	    if ($1 eq 'gen') {
636
		$genpdqfile = "> " . removeshellescapes($4);
637
	    } else {
638
		$genpdqfile = ">> " . removeshellescapes($4);
639
	    }
635
	}
640
	}
636
    }
641
	# 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?
642
	if ($2 eq 'raw') {
638
    if ($2 eq 'raw') {
643
	    my $time = time();
639
	my $time = time();
644
	    my @pdqfile =
640
	my @pdqfile =
641
"driver \"Raw-Printer-$time\" {
645
"driver \"Raw-Printer-$time\" {
642
  # This PDQ driver declaration file was generated automatically by
646
  # This PDQ driver declaration file was generated automatically by
643
  # foomatic-rip to allow raw (filter-less) printing.
647
  # foomatic-rip to allow raw (filter-less) printing.
Lines 652-672 Link Here
652
    ln -s \$INPUT \$OUTPUT
656
    ln -s \$INPUT \$OUTPUT
653
  }
657
  }
654
}";
658
}";
655
	open PDQFILE, $genpdqfile or
659
	    open PDQFILE, $genpdqfile or
656
	    rip_die("Cannot write PDQ driver declaration file",
660
		rip_die("Cannot write PDQ driver declaration file",
657
		    $EXIT_PRNERR_NORETRY_BAD_SETTINGS);
661
			$EXIT_PRNERR_NORETRY_BAD_SETTINGS);
658
	print PDQFILE join('', @pdqfile);
662
	    print PDQFILE join('', @pdqfile);
659
	close PDQFILE;
663
	    close PDQFILE;
660
	exit $EXIT_PRINTED;
664
	    exit $EXIT_PRINTED;
665
	}
666
	# We have PDQ
667
	$spooler = 'pdq';
661
    }
668
    }
662
    # We have PDQ
669
663
    $spooler = 'pdq';
670
671
    # remove extra spacing if running as LPRng filter
672
    $added_lf = "" if $spooler eq 'lprng';
673
664
}
674
}
665
675
666
667
# remove extra spacing if running as LPRng filter
668
$added_lf = "" if $spooler eq 'lprng';
669
670
## Command line arguments without name
676
## Command line arguments without name
671
677
672
# Remaining arguments
678
# Remaining arguments

Return to bug 698451