chiark / gitweb /
update-xfonts-traditional: Rename log file handle variables to $logfh
[xfonts-traditional.git] / update-xfonts-traditional
index 63e9040d4a5572a8e14ba842526a48644c0a0621..f0961774867f4747653f865eca0e2b24cd3aaac0 100755 (executable)
@@ -24,6 +24,7 @@ our $reportfh;
 our $foundryinfo;
 our %props;
 our $tolerate_bad_fonts=1;
+our $always_reprocess;
 our $wanted_parallel;
 
 sub reportloaded {
@@ -54,7 +55,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 +131,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 +160,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,8 +171,14 @@ sub loadfoundries () {
     die "no foundry maps\n" unless %foundrymap;
 }
 
+sub filter_st_isok ($) {
+    my ($ch) = @_;
+    my $st = $ch->{St};
+    return !$st || $ch->{SigOK}{($st & ~128)};
+}
+
 sub processpcfgz ($$$$) {
-    my ($inpcfgz,$outpcfgz,$logfile,$what) = @_;
+    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);
@@ -220,7 +227,7 @@ sub processpcfgz ($$$$) {
            $current = $reader;
        }
     }
-    my $r = processbdf($usread,$uswrite,$logfile,$what);
+    my $r = processbdf($usread,$uswrite,$logfh,$what);
     my $none = $r !~ m/^\d/;
 
     $ch{'gunzip'}{SigOK}{13} = 1;
@@ -254,15 +261,9 @@ sub processpcfgz ($$$$) {
        $ch->{St} = $?;
     }
 
-    my $st_isok = sub {
-       my ($ch) = @_;
-       my $st = $ch->{St};
-       return !$st || $ch->{SigOK}{($st & ~128)};
-    };
-
     if ($tolerate_bad_fonts &&
        $r eq 'no bdf data' &&
-       $st_isok->($ch{'gunzip'}) &&
+       filter_st_isok($ch{'gunzip'}) &&
        ($ch{'pcf2bdf'}{St} & ~128) == 6)
     {
        $r = "pcf2bdf failed ($ch{'pcf2bdf'}{St})";
@@ -270,7 +271,7 @@ sub processpcfgz ($$$$) {
        $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".
                " failed $ch->{St}".
@@ -287,14 +288,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 +312,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 +379,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 +390,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 +457,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,
     );