#!/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 $help = 0; GetOptions("debug!", "help|?" => \$help) or pod2usage(1); pod2usage(-exitstatus => 0, -verbose => 2) if $help; 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 = $? / 8; 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> and C<-debug> are accepted. See the tlpfiles documentation for details. =head1 DESCRIPTION B creates an updated C file in a TL tree with the C and C entries in the TL database. C is assumed to be found in C, where C is C<../..> of C<$0>. The new file is written to C 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) 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: #