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
|
#!/usr/bin/perl
$^W = 1;
use strict;
use Data::Dumper;
my %settings = (
dvipsPreferOutline => [ qw/true false/ ],
LW35 => [ qw/URW URWkb ADOBE ADOBEkb/ ],
dvipsDownloadBase35 => [ qw/true false/ ],
pdftexDownloadBase14 => [ qw/true false/ ],
dvipdfmDownloadBase14 => [ qw/true false/ ],
);
&main();
sub main {
my (@l) = `kpsewhich -all updmap.cfg`;
chomp(@l);
my @UpdMaps;
my %MergedData;
# we read it in *reverse* order and simple fill up the combined data
# thus if there are multiple definitions/settings, the one coming from
# the first in the original list will win!
for my $l (reverse @l) {
my $updmap = readUpdmap($l);
if (defined($updmap->{'setting'})) {
for my $k (keys %{$updmap->{'setting'}}) {
$MergedData{'setting'}{$k} = $updmap->{'setting'}{$k};
}
}
if (defined($updmap->{'MixedMap'})) {
for my $k (keys %{$updmap->{'MixedMap'}}) {
my $mapdata = $updmap->{'MixedMap'}{$k};
for my $f (keys %$mapdata) {
$MergedData{'fonts'}{$f} = $mapdata->{$f};
}
}
}
if (defined($updmap->{'Map'})) {
for my $k (keys %{$updmap->{'Map'}}) {
my $mapdata = $updmap->{'Map'}{$k};
for my $f (keys %$mapdata) {
$MergedData{'fonts'}{$f} = $mapdata->{$f};
}
}
}
}
$Data::Dumper::Indent = 1;
print Data::Dumper->Dump([\%MergedData], [qw(mapdata)]);
}
sub readUpdmap {
my $fn = shift;
if (!open(FN,"<$fn")) {
log("Cannot read $fn: $!");
return;
}
my $i = 0;
my %data;
while (<FN>) {
$i++;
chomp;
next if /^\s*$/;
next if /^\s*#/;
my ($a, $b, @rest) = split ' ';
if (@rest) {
warning("updmap: line $i in $fn contains a syntax error, more than two words!\n");
}
if (defined($settings{$a})) {
my @possible_values = @{$settings{$a}};
if (scalar(grep($_ eq $b, @possible_values))) {
$data{'setting'}{$a} = $b;
} else {
warning("updmap: unknown setting for $a: $b, ignored!\n");
}
} elsif ($a eq "Map" || $a eq "MixedMap") {
if (defined($data{$a}{$b})) {
warning("updmap: double mentioning of $b in $fn\n");
} else {
my $ret = readMapFile($b);
if (defined($ret)) {
$data{$a}{$b} = readMapFile($b);
} else {
warning("updmap: map file $b mentioned in $fn cannot be found!\n");
}
}
} else {
warning("updmap: unrecognized line $i in $fn: $_\n");
}
}
close(FN) || warn("Cannot close $fn: $!");
return \%data;
}
sub readMapFile {
my $mn = shift;
my $fn = `kpsewhich $mn`;
chomp($fn);
return if (!$fn);
open(MF,"<$fn") || return;
my %data;
while (<MF>) {
chomp;
next if /^\s*$/;
next if /^\s*%/;
my ($a, $b) = split(' ', $_, 2);
$data{$a} = $b;
}
return \%data;
}
sub warning {
print STDERR @_;
}
|