X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=xfonts-traditional.git;a=blobdiff_plain;f=update-xfonts-traditional;h=01ae14584e645a15533bace6d52ce8c20024c8be;hp=f0961774867f4747653f865eca0e2b24cd3aaac0;hb=a6bafbd15bc99ab5efc7a20e86dd78fbb4ac4166;hpb=2b5b1a7d495b3415f5f6694da6ac7139d13bced3 diff --git a/update-xfonts-traditional b/update-xfonts-traditional index f096177..01ae145 100755 --- a/update-xfonts-traditional +++ b/update-xfonts-traditional @@ -171,22 +171,24 @@ sub loadfoundries () { die "no foundry maps\n" unless %foundrymap; } +our %ch; + sub filter_st_isok ($) { my ($ch) = @_; my $st = $ch->{St}; return !$st || $ch->{SigOK}{($st & ~128)}; } -sub processpcfgz ($$$$) { - my ($inpcfgz,$outpcfgz,$logfh,$what) = @_; - print $reportfh "processing $inpcfgz to $outpcfgz\n" if $verbose>=2; - my $current = new IO::File $inpcfgz, '<' or die "$inpcfgz $!"; - my ($usread,$uswrite); +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 $!; @@ -195,7 +197,7 @@ sub processpcfgz ($$$$) { } else { shift @$proc; $reader = undef; - $writer = new IO::File $outpcfgz, '>' or die "$outpcfgz $!"; + $writer = $output; } if (@$proc) { my $exe = $proc->[0]; @@ -227,31 +229,38 @@ sub processpcfgz ($$$$) { $current = $reader; } } - my $r = processbdf($usread,$uswrite,$logfh,$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 $!; @@ -261,23 +270,44 @@ sub processpcfgz ($$$$) { $ch->{St} = $?; } - 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; - } + $after_hook->(); + foreach my $ch (@children) { 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'], + [], + ['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; }