chiark / gitweb /
update-xfonts-traditional: Factor out process_filter
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 May 2016 11:35:37 +0000 (12:35 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 1 May 2016 11:41:29 +0000 (12:41 +0100)
We are going to want to reuse this so that we can put bdfnorm in front
of every processbdf.

No functional change.

update-xfonts-traditional

index f0961774867f4747653f865eca0e2b24cd3aaac0..8dccad424924f88c36c012ceab5cc6a69a72cc14 100755 (executable)
@@ -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,13 +229,12 @@ 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
@@ -252,6 +253,7 @@ sub processpcfgz ($$$$) {
        $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 +263,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;
 }