1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
#!/usr/bin/env perl
# $Id: tlpdb2list 5188 2007-10-14 20:32:44Z karl $
# Copyright 2007 Karl Berry.
# This file is licensed under the GNU General Public License version 2
# or any later version.
#
# Update the map files in updmap.cfg from tlpdb -- a convenience, since
# the only other way to enable new maps is to do an install. (updmap
# --syncwithtrees disables old maps, but does not enable new.)
BEGIN {
$^W = 1;
($mydir = $0) =~ s,/[^/]*$,,;
unshift (@INC, "$mydir/..");
}
use strict;
use TeXLive::TLPOBJ;
use TeXLive::TLPDB;
use Getopt::Long;
use Pod::Usage;
use File::Path;
our $NEW_UPDMAP_CFG;
our $mydir;
our $opt_debug = 0;
my $man = 0;
my $help = 0;
GetOptions("debug!", "help|?" => \$help, "man" => \$man) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
exit (&main ());
sub main
{
# get the db.
chomp (my $Master = `cd $mydir/../.. && pwd`); # xx TLPDB should default
my $tlpdb_path = "$Master/texlive.tlpdb";
my $tlpdb = TeXLive::TLPDB->new ("location" => $tlpdb_path);
# get list of packages.
my %maps;
for my $pkg ($tlpdb->list_packages) {
my $obj = $tlpdb->get_package ($pkg);
die "$0: no TeX Live package named $pkg in $tlpdb_path.\n" if ! $obj;
# record any maps.
my @executes = $obj->executes;
for (my $e = 0; $e < @executes; $e++) {
my ($action,$value) = split (" ", $executes[$e]);
if ($action =~ /add.*Map/) {
$maps{$action} .= " " if exists $maps{$action};
$maps{$action} .= $value;
}
}
}
return &update_updmap_cfg ($Master, %maps);
}
# update updmap.cfg per MAPS.
#
sub update_updmap_cfg
{
my ($Master, %maps) = @_;
# read old file.
my $UPDMAP_CFG = "$Master/texmf/web2c/updmap.cfg";
my @updmap = `cat $UPDMAP_CFG`;
# find last comment line (which is where the maps start).
my $last_comment;
for ($last_comment = $#updmap; $last_comment >= 0; $last_comment--) {
last if $updmap[$last_comment] =~ /^#/;
}
die "no last comment in $UPDMAP_CFG?!" if $last_comment < 0;
# write new file.
local *NEW_UPDMAP_CFG;
my $new_updmap_cfg = "$UPDMAP_CFG.new"; # just the filename
$NEW_UPDMAP_CFG = ">$new_updmap_cfg"; # for open
open (NEW_UPDMAP_CFG) || die "open($NEW_UPDMAP_CFG) failed: $!";
# first copy everything up to and including the last comment.
for (my $i = 0; $i <= $last_comment; $i++) {
print NEW_UPDMAP_CFG $updmap[$i];
}
# add our map lines, preserving alphabetical order.
for my $action (sort keys %maps) {
my @maps = split (/ /, $maps{$action});
(my $key = $action) =~ s/^add//; # addMap in tlp, Map in updmap.cfg
@maps = map { "$key $_\n" } sort @maps;
print NEW_UPDMAP_CFG @maps;
}
close (NEW_UPDMAP_CFG) || warn "close($NEW_UPDMAP_CFG) failed: $!";
# show differences.
print `diff $UPDMAP_CFG $new_updmap_cfg`;
my $ret = $?;
if ($ret == 0) {
unlink ($new_updmap_cfg) || die "unlink($new_updmap_cfg) failed: $!";
}
return $ret;
}
__END__
=head1 NAME
tlpdb2updmap - update updmap.cfg from a TeX Live database
=head1 SYNOPSIS
tlpdb2updmap [OPTION]...
=head1 OPTIONS
The standard options C<-help>, C<-debug>, and C<-man> are accepted.
See the tlpfiles documentation for details.
=head1 DESCRIPTION
B<tlpdb2updmap> creates an updated C<updmap.cfg> file in a TL tree with
the C<Map> and C<MixedMap> entries in the TL database.
C<updmap.cfg> is assumed to be found in
C<Master/texmf/web2c/updmap.cfg>, where C<Master/> is C<../..> of
C<$0>.
The new file is written to C<updmap.cfg.new> in that same directory, if
there are any changes. A diff is also shown, and the exit status is one.
Exit status is zero if no differences.
No repository actions are performed in any case.
=head1 AUTHORS AND COPYRIGHT
This script and its documentation were written for the TeX Live
distribution (L<http://tug.org/texlive>) and both are licensed under the
GNU General Public License Version 2 or later.
=cut
### Local Variables:
### perl-indent-level: 2
### tab-width: 2
### indent-tabs-mode: nil
### End:
# vim:set tabstop=2: #
|