diff options
author | Norbert Preining <preining@logic.at> | 2011-09-03 12:37:31 +0000 |
---|---|---|
committer | Norbert Preining <preining@logic.at> | 2011-09-03 12:37:31 +0000 |
commit | a2558adec96db705392e3d601c12fa811c198f4f (patch) | |
tree | 3c5290822ec47f474e0c06a3a89f2c515c66dc4e /Master/tlpkg | |
parent | b9eb99418cffbe10aa7cc67ea80f7d20683f3973 (diff) |
multi-updmap: change logic how config file is selected
git-svn-id: svn://tug.org/texlive/trunk@23778 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg')
-rw-r--r-- | Master/tlpkg/dev/multi-updmap.pl | 127 |
1 files changed, 65 insertions, 62 deletions
diff --git a/Master/tlpkg/dev/multi-updmap.pl b/Master/tlpkg/dev/multi-updmap.pl index a56b611e2a0..8723c91b455 100644 --- a/Master/tlpkg/dev/multi-updmap.pl +++ b/Master/tlpkg/dev/multi-updmap.pl @@ -24,7 +24,7 @@ # any fonts. The updmap.cfg has to me moved into TEXMFDIST/web2c/ # and tlmgr needs to update this file from the installed fonts. -my ($TEXMFROOT, $TEXMFMAIN, $TEXMFVAR); +my ($TEXMFROOT, $TEXMFMAIN, $TEXMFVAR, $TEXMFCONFIG); BEGIN { $^W=1; @@ -64,6 +64,7 @@ my @cmdline_options = ( "dvipsoutputdir=s", # the following does not work, Getopt::Long looses the first # entry in a multi setting, treat it separately in processOptions + # furthermore, it is not supported by older perls, so do it differently #"enable=s{1,2}", "edit", "force", @@ -78,6 +79,7 @@ my @cmdline_options = ( # the following is a correct specification of an option according # to the manual, but it does not work! # we will treat that option by itself in processOptions + # furthermore, it is not supported by older perls, so do it differently #"setoption=s@{1,2}", "showoptions=s@", "syncwithtrees", @@ -113,15 +115,23 @@ sub main { exit 0; } + # config file for changes + my $changes_config_file; + # determine which config files should be used # replaces the former "setupCfgFile" # we do NOT read texmf/web2c/updmap.cfg + # + # we also determine here where changes will be saved to if ($opts{'cnffile'}) { for my $f (@{$opts{'cnffile'}}) { if (! -f $f) { die "$prg: Config file \"$f\" not found."; } } + # in case that config files are given on the command line, the first + # in the list is the one where changes will be written to. + ($changes_config_file) = @{$opts{'cnffile'}}; } else { my @all_files = `kpsewhich -all updmap.cfg`; chomp(@all_files); @@ -133,13 +143,37 @@ sub main { push @used_files, $f; } } - @{$opts{'cnffile'}} = @used_files; + # determine the config file that we will use for changes + # if in the list of used files contains either one from + # TEXMFHOME or TEXMFCONFIG (which is TEXMFSYSCONFIG in the -sys case) + # then use the *top* file (which will be either one of the two), + # if none of the two exists, create a file in TEXMFCONFIG and use it + chomp(my $TEXMFHOME = `kpsewhich -var-value=TEXMFHOME`); + my @final = @used_files; + my $use_top = 0; + for my $f (@used_files) { + if ($f =~ m!($TEXMFHOME|$TEXMFCONFIG)/web2c/updmap.cfg!) { + $use_top = 1; + last; + } + } + if ($use_top) { + ($changes_config_file) = @used_files; + } else { + # add the empty config file + my $dn = "$TEXMFCONFIG/web2c"; + $changes_config_file = "$dn/updmap.cfg"; + # don't use used_files here, it goes into an infinite loop! + unshift @final, $changes_config_file; + } + @{$opts{'cnffile'}} = @final; } print "$prg is using the following updmap.cfg files (in precedence order):\n"; for my $f (@{$opts{'cnffile'}}) { print " $f\n"; } read_updmap_files(@{$opts{'cnffile'}}); + $alldata->{'changes_config'} = $changes_config_file; if ($opts{'listmaps'}) { for my $m (keys %{$alldata->{'maps'}}) { @@ -152,15 +186,14 @@ sub main { # we do changes always in the used config file with the highest # priority - my ($top_config_file) = @{$opts{'cnffile'}}; - my $bakFile = $top_config_file; + my $bakFile = $changes_config_file; $bakFile =~ s/\.cfg$/.bak/; my $changed = 0; if ($opts{'syncwithtrees'}) { my @missing = read_map_files(); if (@missing) { - print "Missing map files found, disabling them in $top_config_file\n"; + print "Missing map files found, disabling them in $changes_config_file\n"; for my $m (@missing) { $changed ||= disableMap($m); } @@ -177,9 +210,9 @@ sub main { $cmd = 'edit'; my $editor = $ENV{'VISUAL'} || $ENV{'EDITOR'}; $editor ||= (&win32 ? "notepad" : "vi"); - ©File($top_config_file, $bakFile); - system($editor, $top_config_file); - $changed = files_are_different($bakFile, $top_config_file); + ©File($changes_config_file, $bakFile); + system($editor, $changes_config_file); + $changed = files_are_different($bakFile, $changes_config_file); } elsif ($opts{'setoption'}) { $cmd = 'setOption'; $changed = setOptions (@{$opts{'setoption'}}); @@ -200,7 +233,7 @@ sub main { $updLSR->{mustexist}(0); if ($cmd && !$opts{'force'} && !$changed) { - print "$top_config_file unchanged. Map files not recreated.\n" + print "$changes_config_file unchanged. Map files not recreated.\n" if !$opts{'quiet'}; } else { if (!$opts{'nomkmap'}) { @@ -809,14 +842,10 @@ sub locateMap { sub processOptions { # first process the stupid setoption= s@{1,2} which is not accepted + # furthermore, try to work around missing s{1,2} support in older perls my $oldconfig = Getopt::Long::Configure(qw(pass_through)); our @setoptions; our @enable; - #GetOptions("setoption=s{1,2}" => \@setoptions, - # "enable=s{1,2}" => \@enable) or - # die "Try \"$prg --help\" for more information.\n"; - - # try to work around missing s{1,2} support in older perls sub read_one_or_two { my ($opt, $val) = @_; our @setoptions; @@ -829,10 +858,13 @@ sub processOptions { push @enable, $val; } } else { + my $vv = shift @ARGV; + die "Try \"$prg --help\" for more information.\n" + if !defined($vv); if ($opt eq "setoption") { - push @setoptions, "$val=" . shift @ARGV; + push @setoptions, "$val=$vv"; } else { - push @enable, "$val=" . shift @ARGV; + push @enable, "$val=$vv"; } } } @@ -840,40 +872,10 @@ sub processOptions { "enable=s@" => \&read_one_or_two) or die "Try \"$prg --help\" for more information.\n"; - Getopt::Long::Configure($oldconfig); - - # now revamp the @setoptions that they have the proper style - my @realset; - while (@setoptions) { - my $t = shift @setoptions; - if ($t =~ m/=/) { - push @realset, $t; - } else { - my $tt = shift @setoptions; - die "Try \"$prg --help\" for more information.\n" - if !defined($tt); - push @realset, "$t=$tt"; - } - } - if (@realset) { - @{$opts{'setoption'}} = @realset; - } - my @realenable; - while (@enable) { - my $t = shift @enable; - if ($t =~ m/=/) { - push @realenable, $t; - } else { - my $tt = shift @enable; - die "Try \"$prg --help\" for more information.\n" - if !defined($tt); - push @realenable, "$t=$tt"; - } - } - if (@realenable) { - @{$opts{'enable'}} = @realenable; - } + @{$opts{'setoption'}} = @setoptions if (@setoptions); + @{$opts{'enable'}} = @enable if (@enable); + Getopt::Long::Configure($oldconfig); # now continue with normal option handling @@ -919,13 +921,13 @@ sub setOptions { if !$key || !$val; &setOption ($key, $val); } - return save_updmap($alldata->{'top_config'}); + return save_updmap($alldata->{'changes_config'}); } sub enableMap { my ($type, $map) = @_; - my $tc = $alldata->{'top_config'}; + my $tc = $alldata->{'changes_config'}; die "$prg: invalid mapType $type" if ($type !~ m/^(Map|MixedMap)$/); die "$prg: top config file $tc has not been read." @@ -958,7 +960,7 @@ sub enableMap { sub disableMap { my $map = shift; - my $tc = $alldata->{'top_config'}; + my $tc = $alldata->{'changes_config'}; die "$prg: top config file $tc has not been read." if (!defined($alldata->{'updmap'}{$tc})); @@ -1001,6 +1003,10 @@ sub save_updmap { my %upd = %{$alldata->{'updmap'}{$fn}}; if ($upd{'changed'}) { open (FN, ">$fn") || die "$prg: can't write to $fn: $!"; + my @lines = @{$upd{'lines'}}; + if (!@lines) { + print "Creating new config file $fn\n"; + } # collect the lines with data my %line_to_setting; my %line_to_map; @@ -1024,7 +1030,6 @@ sub save_updmap { } } } - my @lines = @{$upd{'lines'}}; for my $i (0..$#lines) { if (defined($line_to_setting{$i})) { my $k = $line_to_setting{$i}; @@ -1066,13 +1071,13 @@ sub setOption { die "$prg: Unsupported option $opt." if (!defined($settings{$opt})); die "$0: Invalid value $val for option $opt." - if (!member($val, @{$settings{$opt}})); + if (!TeXLive::TLUtils::member($val, @{$settings{$opt}})); # silently accept this old option name, just in case. return if $opt eq "dvipdfmDownloadBase14"; #print "Setting option $opt to $val...\n" if !$opts{'quiet'}; - my $tc = $alldata->{'top_config'}; + my $tc = $alldata->{'changes_config'}; die "$prg: top config file $tc has not been read." if (!defined($alldata->{'updmap'}{$tc})); @@ -1191,8 +1196,7 @@ sub normalizeLines { # we only read what is necessary (speed!) # # initialized by read_updmap_files -# $alldata->{'top_config'} = first element of the following list, where -# all the changes are executed +# $alldata->{'changes_config'} = the config file where changes are saved # $alldata->{'order'} = [ list of updmap in decreasing priority ] # $alldata->{'updmap'}{$full_path_name_of_updmap}{'lines'} = \@lines # $alldata->{'updmap'}{$full_path_name_of_updmap}{'setting'}{$key}{'val'} = $val @@ -1236,8 +1240,6 @@ sub read_updmap_files { } } $alldata->{'order'} = \@l; - # get the first config file where we will do all the changes - $alldata->{'top_config'} = $l[0]; # first round determine which maps should be used and which type, as # different updmap.cfg files might specify different types of maps # (MixedMap or Map). @@ -1254,13 +1256,14 @@ sub read_updmap_files { sub read_updmap_file { my $fn = shift; + my %data; if (!open(FN,"<$fn")) { - log("Cannot read $fn: $!"); - return; + log("initializing empty $fn: $!"); + $data{'lines'} = [ ]; + return \%data; } # we count lines from 0 ..!!!! my $i = -1; - my %data; my @lines = <FN>; chomp(@lines); $data{'lines'} = [ @lines ]; |