From f9238b191d14686b9beba78893dff0a8dff9c087 Mon Sep 17 00:00:00 2001 From: Roger Leigh Date: Sun, 26 Oct 2008 16:18:09 +0000 Subject: Imported Upstream version 5.0.2 --- src/cups/cups-genppdupdate.in | 141 ++++++++++++++++++++++++++++++------------ 1 file changed, 103 insertions(+), 38 deletions(-) (limited to 'src/cups/cups-genppdupdate.in') diff --git a/src/cups/cups-genppdupdate.in b/src/cups/cups-genppdupdate.in index ee49a0b..119c350 100644 --- a/src/cups/cups-genppdupdate.in +++ b/src/cups/cups-genppdupdate.in @@ -1,5 +1,5 @@ #! @PERL@ -w -# $Id: cups-genppdupdate.in,v 1.25.8.2 2007/05/29 01:47:26 rlk Exp $ +# $Id: cups-genppdupdate.in,v 1.25.8.4 2007/12/29 20:42:25 rlk Exp $ # Update CUPS PPDs for Gutenprint queues. # Copyright (C) 2002-2003 Roger Leigh (rleigh@debian.org) # @@ -37,6 +37,8 @@ our $opt_h; # Help our $opt_n; # No action our $opt_q; # Quiet mode our $opt_s; # Source PPD location +our $opt_p; # New PPD location +our $opt_P; # PPD generator location our $opt_v; # Verbose mode our $opt_N; # Don't update PPD file options our $opt_o; # Output directory @@ -62,6 +64,11 @@ my $updated_ppd_count = 0; my $exit_after_parse_args = 0; my $serverdir = "@cups_conf_serverbin@"; +my $driver_bin = "$serverdir/driver/gutenprint.$version"; +my $driver_version = `$driver_bin VERSION`; +chomp $driver_version; + +$Getopt::Std::STANDARD_HELP_VERSION = 1; $Getopt::Std::STANDARD_HELP_VERSION = 1; @@ -192,6 +199,8 @@ sub HELP_MESSAGE($;$$$) { print $fh " -n No-action. Don't overwrite any PPD files.\n"; print $fh " -q Quiet mode. No messages except errors.\n"; print $fh " -s ppd_dir Use ppd_dir as the source PPD directory.\n"; + print $fh " -p ppd_dir Update PPD files in ppd_dir.\n"; + print $fh " -P driver Use the specified driver binary to generate PPD files.\n"; print $fh " -v Verbose messages.\n"; print $fh " -N Reset options to defaults.\n"; print $fh " -o out_dir Output PPD files to out_dir.\n"; @@ -213,7 +222,7 @@ sub help() { } sub parse_options () { - if (!getopts('d:hnqs:vNo:')) { + if (!getopts('d:hnqs:vNo:p:P:')) { help(); } if ($opt_n) { @@ -230,6 +239,22 @@ sub parse_options () { die "$opt_s: invalid directory: $!\n"; } } + if ($opt_p) { + if (-d $opt_p) { + $ppd_dir = "$opt_p"; + } + else { + die "$opt_p: invalid directory: $!\n"; + } + } + if ($opt_P) { + if (-x $opt_P) { + $driver_bin = "$opt_P"; + } + else { + die "$opt_P: invalid executable: $!\n"; + } + } if ($opt_v) { $verbose = 1; $quiet = 0; @@ -246,7 +271,7 @@ sub parse_options () { $ppd_out_dir = "$opt_o"; } else { - die "$opt_s: invalid directory: $!\n"; + die "$opt_o: invalid directory: $!\n"; } } if ($opt_h) { @@ -263,30 +288,34 @@ sub get_ppd_contents($$$$$) { my $source_data; my ($new_ppd_filename); - if ($use_static_ppd eq "no") { - my ($driver_bin) = "$serverdir/driver/gutenprint.$version"; - my ($driver_version) = `$driver_bin VERSION`; - chomp $driver_version; - if ($driver_version eq "@VERSION@") { - my ($simplified); - if ($filename =~ m,.*/([^/]*)(.sim)(.ppd)?(.gz)?$,) { - $simplified = "simple"; - } else { - $simplified = "expert"; + if ($use_static_ppd eq "no" && $driver_version eq "@VERSION@") { + my ($simplified); + if ($filename =~ m,.*/([^/]*)(.sim)(.ppd)?(.gz)?$,) { + $simplified = "simple"; + } else { + $simplified = "expert"; + } + my ($url); + my (@url_list); + if ($locale) { + if ($region) { + push @url_list, "gutenprint.$version://$driver/$simplified/${locale}_${region}"; } - my ($url); - foreach $url ("gutenprint.$version://$driver/$simplified/${locale}_${region}", - "gutenprint.$version://$driver/$simplified/${locale}", - "gutenprint.$version://$driver/$simplified") { - $new_ppd_filename = $url; - if (open PPD, "$driver_bin cat $url 2>/dev/null |") { - while () { - $source_data .= $_; - } - close PPD; - if ($source_data) { - return ( $new_ppd_filename, $source_data ); - } + push @url_list, "gutenprint.$version://$driver/$simplified/${locale}"; + } + push @url_list, "gutenprint.$version://$driver/$simplified"; + foreach $url (@url_list) { + $new_ppd_filename = $url; + if ($debug & 8) { + print "Trying $driver_bin cat $url for $driver, $simplified, $locale, $region\n"; + } + if (open PPD, "$driver_bin cat $url 2>/dev/null |") { + while () { + $source_data .= $_; + } + close PPD; + if ($source_data) { + return ( $new_ppd_filename, $source_data ); } } } @@ -372,7 +401,7 @@ sub update_ppd ($) { } } if (! $valid) { - print STDERR "$ppd_source_filename: this PPD file cannot be upgraded automatically (only files based on Gutenprint 4.3.21 and newer can be)\n"; + print STDERR "$ppd_source_filename: this PPD file cannot be upgraded automatically (only files based on Gutenprint 5.0.0 and newer can be)\n"; return 0; } if ($debug & 2) { @@ -408,7 +437,8 @@ sub update_ppd ($) { $driver, $locale, $region); if (! $source_data) { - die "Unable to retrieve PPD file!\n"; + print "Unable to retrieve PPD file!\n"; + return 0; } # Save new PPD in a temporary file, for processing... @@ -426,12 +456,19 @@ sub update_ppd ($) { my %new_default_types = get_default_types($tmpfile); my %defaults = get_defaults(ORIG); my %options = get_options($tmpfile, %new_default_types); + my %resolution_map = get_resolution_map($tmpfile); # Close original and temporary files... - close ORIG or die "$_: can't close file: $!"; - close $tmpfile or die "can't close temporary file $tmpfile: $!"; + if (! close ORIG) { + print "$_: can't close file: $!\n"; + return 0; + } + if (! close $tmpfile) { + print "can't close temporary file $tmpfile: $!\n"; + return 0; + } if ($debug & 4) { @@ -456,6 +493,12 @@ sub update_ppd ($) { } print "\n"; } + if (keys %resolution_map) { + print "Resolution Map:\n"; + foreach (sort keys %resolution_map) { + print "$_: $resolution_map{$_}\n"; + } + } print "Non-UI Defaults:\n"; foreach (sort keys %defaults) { my ($xkey) = $_; @@ -488,10 +531,9 @@ sub update_ppd ($) { # Loop through each default in turn. default_loop: - foreach (sort keys %defaults) { - my $default_option = $_; + foreach my $default_option (sort keys %defaults) { my $option; - ($option = $_) =~ s/Default//; # Strip off `Default' + ($option = $default_option) =~ s/Default//; # Strip off `Default' # Check method is valid my $orig_method = $orig_default_types{$option}; my $new_method = $new_default_types{$option}; @@ -501,12 +543,16 @@ default_loop: } if ($new_method eq "PickOne") { # Check the old setting is valid - foreach (@{$options{$option}}) { - if ($defaults{$default_option} eq $_) { # Valid option + foreach my $opt (@{$options{$option}}) { + my $def_option = $defaults{$default_option}; + if (($def_option eq $opt) || + ($option eq "Resolution" && + (defined $resolution_map{$defaults{$default_option}}) && + ($def_option = $resolution_map{$defaults{$default_option}}) eq $opt)) { # Valid option # Set the option in the new PPD - $source_data =~ s/\*($default_option).*/*$1:$defaults{$default_option}/m; + $source_data =~ s/\*($default_option).*/*$1:$def_option/m; if ($verbose) { - print "$ppd_source_filename: Set *$default_option to $defaults{$default_option}\n"; + print "$ppd_source_filename: Set *$default_option to $def_option\n"; } next default_loop; } @@ -514,7 +560,7 @@ default_loop: warn "Warning: $ppd_source_filename: Invalid option: *$default_option: $defaults{$default_option}. Using default setting.\n"; next; } - warn "Warning: $ppd_source_filename: PPD OpenUI method $new_default_types{$_} not understood.\n"; + warn "Warning: $ppd_source_filename: PPD OpenUI method $new_default_types{$default_option} not understood.\n"; } } @@ -657,6 +703,25 @@ sub get_default_types(*) { } +# Return the default options from the given PPD filename +sub get_resolution_map(*) { + my $fh = $_[0]; + my %resolution_map; + + # Read each line of the original PPD file, and store all OpenUI + # names and their types in a hash... + seek ($fh, 0, 0) or die "can't seek to start of PPD file"; + while (<$fh>) { + if ( m/^\*StpResolutionMap:/ ) { + chomp; + my ($junk, $new, $old) = split; + $resolution_map{$old} = $new; + } + } + return %resolution_map; +} + + # Return the default options from the given PPD filename sub get_defaults(*) { my $fh = $_[0]; -- cgit v1.2.3