e2fb14fb762f90a696bb07a60dcd647151a6b1e4
6 use File
::Glob
qw(:glob);
11 our $prefix="/usr/local";
12 our $package='xfonts-traditional';
13 our $sharedir="$prefix/share/$package";
14 our @fonttrees=qw(/usr/share
/fonts/X11
/usr/local/share/fonts
/X11
);
15 our $donefile="$package.done";
16 our $logfile="$package.log";
17 our $fontprefix="trad--";
26 return unless $verbose;
27 print $reportfh @_,"\n" or die $!;
31 return join ' ', ((stat _
)[1,7,9,10]);
39 foreach my $path (@rulespath) {
40 my $script="$path/$key.rules";
41 $!=0; $@
=''; my $f = do $script;
43 reportloaded
("rules: loaded ",$script);
47 die "$! $? $script" unless $! == &ENOENT
;
49 return $cache{$key}=undef;
52 sub processbdf
($$$$) {
53 my ($inbdf,$outbdf,$logfile,$what) = @_;
56 my ($w,$h,$xo,$yo,$y,$bitmap,$glyph);
59 if ($state eq 'bitmap' && $y==$h) {
63 my $key= sprintf "%s,%d,%d,%d,%d", $foundry,$w,$h,$xo,$yo;
64 my $rules= loadrules
($key);
65 return (0,'no rules') if !$rules;
67 $modified += ($_ ne $glyph);
68 print $outbdf $_,"\n" or die $!
69 foreach split /\;/, $_; # /;
72 if ($state eq 'bitmap') {
73 m/^([0-9a-fA-F]+)\s+$/ or die $y;
74 length($1) == (($w+7 >> 3) << 1) or die "$1 $w";
79 if ($state eq 'idle' && m/^FOUNDRY\s+/) {
80 die if defined $foundry;
81 return (0,'foundry syntax') unless m/^FOUNDRY\s+\"(\w+)\"\s+/;
82 $foundry = $foundrymap{lc $1};
83 return (0,'no foundry') unless defined $foundry;
84 $_ = "FOUNDRY \"$foundry\"\n";
86 if ($state eq 'idle' && m/^FONT\s+/) {
88 return (0,'simple font name') unless m/^(FONT\s+)\-(\w+)\-/;
89 $font = $foundrymap{lc $2};
90 return (0,'no foundry') unless defined $font;
91 $_ = "FONT -$font-$'";
93 if ($state eq 'idle' && m/^STARTCHAR\s/) {
94 die unless defined $foundry;
95 die unless defined $font;
96 return (0,'foundry != font') unless $foundry eq $font;
100 if ($state eq 'startchar') {
101 if (m/^BBX\s+(\+?\d+)\s+(\+?\d+)\s+([-+]?\d+)\s+([-+]?\d+)\s+$/) {
102 ($w,$h,$xo,$yo) = ($1,$2,$3,$4);
104 if (m/^BITMAP\s+$/) {
105 die unless defined $w;
111 print $outbdf $_ or die $!;
113 die $! if $inbdf->error;
114 die $! if $outbdf->error or !$outbdf->flush;
115 die unless $state eq 'idle';
117 printf $logfile "%s: %d glyphs changed\n", $what, $modified
120 printf $logfile "%s: unchanged - no rules matched\n", $what
126 sub loadfoundries
() {
128 foreach my $path (@rulespath) {
130 die "$path $!" unless $!==&ENOENT
;
133 $foundryinfo .= statsummary
().' '.$path."\0\n";
135 my $p = "$path/foundries";
136 my $f = new IO
::File
$p;
138 die "$p $!" unless $!==&ENOENT
;
139 print $reportfh "foundries: none in $p\n" or die $! if $verbose;
146 m/^(\w+)\s+(\w+)$/ or die;
148 next if exists $foundrymap{$k};
151 $f->error and die $!;
152 reportloaded
('foundries: loaded ',$p);
154 die "no foundry maps\n" unless %foundrymap;
157 sub processpcfgz
($$$$) {
158 my ($inpcfgz,$outpcfgz,$logfile,$what) = @_;
160 my $current = new IO
::File
$inpcfgz, '<' or die "$inpcfgz $!";
161 my ($usread,$uswrite);
162 my ($reader,$writer);
164 foreach my $proc (['gunzip'], ['pcf2bdf'], [],
165 ['bdftopcf'],['',qw(gzip
-1)]) {
166 my $isfinal = (@
$proc && $proc->[0] eq '');
168 $reader = new IO
::Handle
or die $!;
169 $writer = new IO
::Handle
or die $!;
170 new IO
::Pipe
($reader,$writer) or die $!;
174 $writer = new IO
::File
$outpcfgz, '>' or die "$outpcfgz $!";
177 my $exe = $proc->[0];
178 my $child = fork; defined $child or die $!;
180 open STDIN
, '<&', $current or die $!;
181 open STDOUT
, '>&', $writer or die $!;
183 close $reader or die $!;
185 close $usread or die $! if $usread;
186 close $uswrite or die $! if $uswrite;
187 exec $exe @
$proc or die "$exe $!";
189 push @children, [ $child, $exe, defined $usread ];
190 close $current or die $!;
191 close $writer or die $!;
199 my $r = processbdf
($usread,$uswrite,$logfile,$what);
200 my $none = $r !~ m/^\d/;
202 flush
$uswrite or die $!;
204 close $uswrite or die $!;
206 close $usread or die $!;
207 foreach my $chinfo (@children) {
208 my ($child,$exe,$isoutput)=@
$chinfo;
213 kill 9, $child or die "$child $!";
218 $!=0; waitpid($child, 0) == $child or die "$child $!";
219 !$?
or ($?
&~128)==$sigok or die "$exe [$child] $sigok $?";
224 sub processfontdir
($) {
226 if (!opendir FD
, $fontdir) {
227 die "$fontdir $!" unless $!==&ENOENT
;
231 my $olddone = do "$fontdir/$donefile";
233 die "$fontdir $! $@ " unless $!==&ENOENT
;
234 } elsif ($olddone->{''} ne $foundryinfo) {
236 print $reportfh "reprocessing fonts (rules updated)\n" or die $!
237 unless $repro_reported++;
244 my $newdone = { '' => $foundryinfo };
245 my $log = new IO
::File
"$fontdir/$logfile", "w"
246 or die "$fontdir/$logfile $!";
247 my %outfiles; # bitmask: 1 /*exists*/ | 2 /*wanted*/
252 flush
$reportfh or die $!;
253 while (my $dent = scalar readdir FD
) {
254 if ($dent =~ m/^\Q$fontprefix\E.*\.new$/) {
255 unlink "$fontdir/$dent" or $!==&ENOENT
or die "$fontdir $dent $!";
258 next unless $dent =~ m/^[^.\/].*\
.pcf\
.gz
$/;
259 print $reportfh "processing $fontdir...\n" or die $!
261 if ($dent =~ m/^\Q$fontprefix/) {
262 $outfiles{$dent} |= 1;
265 if (!stat "$fontdir/$dent") {
266 die "$fontdir $dent $!" unless $!==&ENOENT
;
269 die "$fontdir $dent" unless -f _
;
272 my $stats = statsummary
();
273 my $tdone = $olddone->{$dent};
274 my $outdent = $fontprefix.$dent;
275 if (defined $tdone && $tdone eq $stats) {
276 $outfiles{$outdent} |= 2;
277 $newdone->{$dent} = $stats;
281 my $r = processpcfgz
("$fontdir/$dent",
282 "$fontdir/$outdent.new",
285 printf $log "%s: unchanged - %s\n", $dent, $r;
286 unlink "$fontdir/$outdent.new" or die "$fontdir $outdent $!";
288 rename "$fontdir/$outdent.new", "$fontdir/$outdent"
289 or die "$fontdir $outdent $!";
291 $outfiles{$outdent} |= 3;
293 $newdone->{$dent} = $stats;
297 foreach my $olddent (keys %outfiles) {
298 my $state = $outfiles{$olddent};
300 $affected++ if $state & 1;
303 unlink "$fontdir/$olddent" or die "$fontdir $olddent $!";
307 if (!stat "$fontdir/fonts.dir") {
308 $!==&ENOENT
or die "$fontdir $!";
310 $!=0; $?
=0; system 'mkfontdir',$fontdir;
311 die "$fontdir $? $!" if $?
or $!;
314 unlink "$fontdir/$logfile" or die "$fontdir $!";
315 unlink "$fontdir/$donefile" or $!==&ENOENT
or die "$fontdir $!";
317 my $newdoneh = new IO
::File
"$fontdir/$donefile.new", 'w'
318 or die "$fontdir $!";
319 print $newdoneh Dumper
($newdone) or die "$fontdir $!";
320 close $newdoneh or die "$fontdir $!";
321 rename "$fontdir/$donefile.new","$fontdir/$donefile"
322 or die "$fontdir $!";
324 if ($reported || %$newdone || $affected || $updated) {
325 printf " processed %s: %d pcfs, %d affected, %d updated.\n",
326 $fontdir, (scalar keys %$newdone), $affected, $updated;
330 sub processfonttree
($) {
333 dangling_symlinks
=> 0,
337 processfontdir
($File::Find
::name
);
342 our $stdin = new IO
::File
'<&STDIN' or die $!;
343 our $stdout = new IO
::File
'>&STDOUT' or die $!;
344 our $stderr = new IO
::File
'>&STDERR' or die $!;
348 'R|rules-include=s@' => \
@rulespath,
349 'share-dir=s' => \
$sharedir,
350 'verbose|v+' => \
$verbose,
353 sub define_mode
($$) {
354 my ($optname,$f) = @_;
355 push @options, $optname, sub {
356 die "only one mode may be specified\n" if defined $mode;
361 define_mode
('bdf-filter', sub {
362 die "no arguments allowed with --bdf-filter\n" if @ARGV;
365 my $r = processbdf
($stdin,$stdout,$reportfh,'stdin');
367 print STDERR
"stdin not processed: $r\n";
372 define_mode
('process-pcf', sub {
373 die "need source and destination pcf.gz\n" if @ARGV!=2;
375 my $r = processpcfgz
($ARGV[0],$ARGV[1],$reportfh,"pcf");
377 print STDERR
"pcf not processed: $r\n";
382 define_mode
('process-fontdirs', sub {
383 die "need font dir(s)\n" unless @ARGV;
385 foreach my $d (@ARGV) {
390 define_mode
('process-fonttrees', sub {
391 die "need font tree(s)\n" unless @ARGV;
393 foreach my $d (@ARGV) {
398 define_mode
('update', sub {
399 die "no arguments allowed with --postinst\n" unless !@ARGV;
401 foreach my $d (@fonttrees) {
406 Getopt
::Long
::Configure
(qw(bundling
));
407 GetOptions
(@options) or exit 127;
409 push @rulespath, "$sharedir/rules";
411 die "need a mode\n" unless $mode;