X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=xfonts-traditional.git;a=blobdiff_plain;f=update-xfonts-traditional;h=494d637969ddcf53db31e94c9201ccc45d3518c0;hp=63e9040d4a5572a8e14ba842526a48644c0a0621;hb=fbafd43c60babe5532e3b18ee5d1abdd412fbee9;hpb=1987c934200d2f253320fc7b2c1c05827c9bc9cd diff --git a/update-xfonts-traditional b/update-xfonts-traditional index 63e9040..494d637 100755 --- a/update-xfonts-traditional +++ b/update-xfonts-traditional @@ -16,6 +16,7 @@ our @fonttrees=qw(/usr/share/fonts/X11 /usr/local/share/fonts/X11); our $donefile="$package.done"; our $logfile="$package.log"; our $fontprefix="trad--"; +our $bdfnorm="bdfnorm"; our @rulespath; our $mode; our %foundrymap; @@ -24,6 +25,7 @@ our $reportfh; our $foundryinfo; our %props; our $tolerate_bad_fonts=1; +our $always_reprocess; our $wanted_parallel; sub reportloaded { @@ -54,7 +56,7 @@ sub loadrules ($) { } sub processbdf ($$$$) { - my ($inbdf,$outbdf,$logfile,$what) = @_; + my ($inbdf,$outbdf,$logfh,$what) = @_; my $state='idle'; my ($foundry,$font); my ($w,$h,$xo,$yo,$y,$bitmap,$glyph); @@ -130,10 +132,10 @@ sub processbdf ($$$$) { return 'no bdf data' # also special cased in processpcfgz if !$anyinput; if ($modified) { - printf $logfile "%s: %d glyphs changed\n", $what, $modified + printf $logfh "%s: %d glyphs changed\n", $what, $modified or die $!; } else { - printf $logfile "%s: unchanged - no rules matched\n", $what + printf $logfh "%s: unchanged - no rules matched\n", $what or die $!; } return $modified; @@ -159,7 +161,7 @@ sub loadfoundries () { while (<$f>) { s/^\s*//; s/\s+$//; next if m/^\#/; - m/^(\w+)\s+(\w+)$/ or die; + m/^([.0-9A-Za-z]+)\s+([.0-9A-Za-z]+)$/ or die; my $k = lc $1; next if exists $foundrymap{$k}; $foundrymap{$k}=$2; @@ -170,16 +172,24 @@ sub loadfoundries () { die "no foundry maps\n" unless %foundrymap; } -sub processpcfgz ($$$$) { - my ($inpcfgz,$outpcfgz,$logfile,$what) = @_; - print $reportfh "processing $inpcfgz to $outpcfgz\n" if $verbose>=2; - my $current = new IO::File $inpcfgz, '<' or die "$inpcfgz $!"; - my ($usread,$uswrite); +our %ch; + +sub filter_st_isok ($) { + my ($ch) = @_; + my $st = $ch->{St}; + return !$st || $ch->{SigOK}{($st & ~128)}; +} + +sub process_filter ($$$$$$$$) { + my ($rr, $input, $output,$what,$logfh, + $procs, $sigpipeok, $after_hook) = @_; my ($reader,$writer); my @children; - my %ch; - foreach my $proc (['gunzip'], ['pcf2bdf'], [], - ['bdftopcf'],['',qw(gzip -1 -n)]) { + my ($usread,$uswrite); + + my $current = $input; + + foreach my $proc (@$procs) { my $isfinal = (@$proc && $proc->[0] eq ''); if (!$isfinal) { $reader = new IO::Handle or die $!; @@ -188,7 +198,7 @@ sub processpcfgz ($$$$) { } else { shift @$proc; $reader = undef; - $writer = new IO::File $outpcfgz, '>' or die "$outpcfgz $!"; + $writer = $output; } if (@$proc) { my $exe = $proc->[0]; @@ -220,31 +230,38 @@ sub processpcfgz ($$$$) { $current = $reader; } } - my $r = processbdf($usread,$uswrite,$logfile,$what); - my $none = $r !~ m/^\d/; + $$rr = processbdf($usread,$uswrite,$logfh,$what); + my $none = $$rr !~ m/^\d/; - $ch{'gunzip'}{SigOK}{13} = 1; - # ... we never care if pcf2bdf didn't want all the output from gunzip + $ch{$_}{SigOK}{13} = 1 foreach @$sigpipeok; - if ($none || !$r) { + if ($none || !$$rr) { # We're not going to install or use this so we can kill our # input and output filters. We kill the input filters so that # we don't risk waiting for them. (If the input filter died # for some other reason then sending it a KILL now won't # affect its exit status.) We kill the output filters (before # we close the output pipe) so we don't produce messages from - # our output filters about corrupted data. + # our output filters about corrupted data. And we tolerate + # SIGPIPE in all the input filters. flush $uswrite or die $!; + my $filterkind = 'input'; foreach my $ch (@children) { if ($ch->{Stage} ne 'self') { kill 9, $ch->{Pid} or die "$ch->{Pid} $ch->{Exe} $!"; $ch->{SigOK}{9} = 1; + } else { + $filterkind = 'output'; + next; + } + if ($filterkind eq 'input') { + $ch->{SigOK}{13} = 1; } } - $ch{'pcf2bdf'}{SigOK}{13} = 1; # ... we might not have read all the output from pcf2bdf, which is OK } + close $uswrite or die $!; close $usread or die $!; @@ -254,29 +271,44 @@ sub processpcfgz ($$$$) { $ch->{St} = $?; } - my $st_isok = sub { - my ($ch) = @_; - my $st = $ch->{St}; - return !$st || $ch->{SigOK}{($st & ~128)}; - }; + $after_hook->(); - if ($tolerate_bad_fonts && - $r eq 'no bdf data' && - $st_isok->($ch{'gunzip'}) && - ($ch{'pcf2bdf'}{St} & ~128) == 6) - { - $r = "pcf2bdf failed ($ch{'pcf2bdf'}{St})"; - print STDERR "warning: $r: skipping $inpcfgz\n"; - $ch{'pcf2bdf'}{SigOK}{6} = 1; - } foreach my $ch (@children) { - if (!$st_isok->($ch)) { + if (!filter_st_isok($ch)) { die "update-xfonts-traditional:". - " $ch->{Exe} [$ch->{Pid}] for $inpcfgz". + " $ch->{Exe} [$ch->{Pid}] for $what". " failed $ch->{St}". " (".(join ' ', keys %{ $ch->{SigOK} })." ok)\n"; } } +} + +sub processpcfgz ($$$$) { + my ($inpcfgz,$outpcfgz,$logfh,$what) = @_; + print $reportfh "processing $inpcfgz to $outpcfgz\n" if $verbose>=2; + my $input = new IO::File $inpcfgz, '<' or die "$inpcfgz $!"; + my $output = new IO::File $outpcfgz, '>' or die "$outpcfgz $!"; + + my $r; + process_filter(\$r, $input, $output, $inpcfgz, $logfh, + [ + ['gunzip'], ['pcf2bdf'], [$bdfnorm], + [], + ['bdftopcf'],['',qw(gzip -1 -n)] + ], + [qw(gunzip)], + # ... we never care if pcf2bdf didn't want all the data + sub { + if ($tolerate_bad_fonts && + $r eq 'no bdf data' && + filter_st_isok($ch{'gunzip'}) && + ($ch{'pcf2bdf'}{St} & ~128) == 6) + { + $r = "pcf2bdf failed ($ch{'pcf2bdf'}{St})"; + print STDERR "warning: $r: skipping $inpcfgz\n"; + $ch{'pcf2bdf'}{SigOK}{6} = 1; + } + }); return $r; } @@ -287,14 +319,17 @@ sub processfontdir ($) { return; } my $changed = 0; - my $olddone = do "$fontdir/$donefile"; - if (!$olddone) { - die "$fontdir $! $@ " unless $!==&ENOENT; - } elsif ($olddone->{''} ne $foundryinfo) { - our $repro_reported; - print $reportfh "reprocessing fonts (rules updated)\n" or die $! - unless $repro_reported++; - $olddone = undef; + my $olddone; + if (!$always_reprocess) { + $olddone = do "$fontdir/$donefile"; + if (!$olddone) { + die "$fontdir $! $@ " unless $!==&ENOENT; + } elsif ($olddone->{''} ne $foundryinfo) { + our $repro_reported; + print $reportfh "reprocessing fonts (rules updated)\n" or die $! + unless $repro_reported++; + $olddone = undef; + } } if (!$olddone) { $olddone = { }; @@ -308,7 +343,7 @@ sub processfontdir ($) { my $logpath = "$fontdir/$logfile"; unlink "$logpath" or $!==&ENOENT or die "$logpath $!"; - my $log = new IO::File $logpath, ">>" or die "$logpath $!"; + my $logfh = new IO::File $logpath, ">>" or die "$logpath $!"; if (!$wanted_parallel) { $wanted_parallel = Sys::CPU::cpu_count(); @@ -375,10 +410,10 @@ sub processfontdir ($) { if (!$child) { my $r = processpcfgz("$fontdir/$dent", "$fontdir/$outdent.new", - $log, $dent); + $logfh, $dent); my $rc; if ($r !~ m/^\d/) { - printf $log "%s: unchanged - %s\n", $dent, $r; + printf $logfh "%s: unchanged - %s\n", $dent, $r; unlink "$fontdir/$outdent.new" or die "$fontdir $outdent $!"; $rc = 2; } else { @@ -386,7 +421,7 @@ sub processfontdir ($) { or die "$fontdir $outdent $!"; $rc = 0; } - $log->flush or die "$logpath $!"; + $logfh->flush or die "$logpath $!"; exit $rc; } $inprogress{$child} = { @@ -453,6 +488,7 @@ our (@options)=( 'share-dir=s' => \$sharedir, 'verbose|v+' => \$verbose, 'j|parallel=i' => \$wanted_parallel, + 'always-reprocess!' => \$always_reprocess, 'tolerate-bad-fonts!' => \$tolerate_bad_fonts, ); @@ -513,6 +549,7 @@ Getopt::Long::Configure(qw(bundling)); GetOptions(@options) or exit 127; push @rulespath, "$sharedir/rules"; +$bdfnorm = "$sharedir/$bdfnorm"; die "need a mode\n" unless $mode;