use Data::Dumper;
use IO::Pipe;
use File::Find;
+use Sys::CPU;
our $prefix="/usr/local";
our $package='xfonts-traditional';
our %foundrymap;
our $verbose=0;
our $reportfh;
+our $foundryinfo;
+our %props;
+our $wanted_parallel;
sub reportloaded {
return unless $verbose;
print $reportfh @_,"\n" or die $!;
}
+sub statsummary () {
+ return join ' ', ((stat _)[1,7,9,10]);
+}
+
sub loadrules ($) {
my ($key) = @_;
our %cache;
my ($foundry,$font);
my ($w,$h,$xo,$yo,$y,$bitmap,$glyph);
my $modified=0;
+ %props = ();
+ my $anyinput=0;
while (<$inbdf>) {
+ $anyinput=1;
if ($state eq 'bitmap' && $y==$h) {
$glyph = uc $glyph;
$glyph =~ s/\;$//;
local ($_) = $glyph;
my $key= sprintf "%s,%d,%d,%d,%d", $foundry,$w,$h,$xo,$yo;
my $rules= loadrules($key);
- return (0,'no rules') if !$rules;
+ return 'no rules' if !$rules;
$rules->();
$modified += ($_ ne $glyph);
print $outbdf $_,"\n" or die $!
}
if ($state eq 'idle' && m/^FOUNDRY\s+/) {
die if defined $foundry;
- return (0,'foundry syntax') unless m/^FOUNDRY\s+\"(\w+)\"\s+/;
+ return 'foundry syntax' unless m/^FOUNDRY\s+\"(\w+)\"\s+/;
$foundry = $foundrymap{lc $1};
- return (0,'no foundry') unless defined $foundry;
+ return 'no foundry' unless defined $foundry;
$_ = "FOUNDRY \"$foundry\"\n";
}
if ($state eq 'idle' && m/^FONT\s+/) {
die if defined $font;
- return (0,'simple font name') unless m/^(FONT\s+)\-(\w+)\-/;
+ return 'simple font name' unless m/^(FONT\s+)\-(\w+)\-/;
$font = $foundrymap{lc $2};
- return (0,'no foundry') unless defined $font;
+ return 'no foundry' unless defined $font;
$_ = "FONT -$font-$'";
}
if ($state eq 'idle' && m/^STARTCHAR\s/) {
die unless defined $foundry;
die unless defined $font;
- return (0,'foundry != font') unless $foundry eq $font;
+ return 'foundry != font' unless $foundry eq $font;
$state='startchar';
$w=undef;
}
+ if (($state eq 'idle' || $state eq 'startchar') &&
+ m/^([A-Z_]+)\s+(.*\S)\s+$/) {
+ $props{$1}=$2;
+ }
if ($state eq 'startchar') {
if (m/^BBX\s+(\+?\d+)\s+(\+?\d+)\s+([-+]?\d+)\s+([-+]?\d+)\s+$/) {
($w,$h,$xo,$yo) = ($1,$2,$3,$4);
$y=0;
$glyph='';
$state='bitmap';
+ $props{' 7bit'}=
+ ($props{'CHARSET_REGISTRY'} =~ m/iso8859|utf|iso10646/i &&
+ $props{'ENCODING'} <= 127);
}
}
print $outbdf $_ or die $!;
die $! if $inbdf->error;
die $! if $outbdf->error or !$outbdf->flush;
die unless $state eq 'idle';
+ return 'no bdf data' # also special cased in processpcfgz
+ if !$anyinput;
if ($modified) {
printf $logfile "%s: %d glyphs changed\n", $what, $modified
or die $!;
}
sub loadfoundries () {
+ $foundryinfo = '';
foreach my $path (@rulespath) {
+ if (!stat $path) {
+ die "$path $!" unless $!==&ENOENT;
+ next;
+ }
+ $foundryinfo .= statsummary().' '.$path."\0\n";
+
my $p = "$path/foundries";
my $f = new IO::File $p;
if (!$f) {
print $reportfh "foundries: none in $p\n" or die $! if $verbose;
next;
}
+ stat $f or die $!;
while (<$f>) {
s/^\s*//; s/\s+$//;
next if m/^\#/;
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);
my ($reader,$writer);
my @children;
foreach my $proc (['gunzip'], ['pcf2bdf'], [],
- ['bdftopcf'],['',qw(gzip -1)]) {
+ ['bdftopcf'],['',qw(gzip -1 -n)]) {
my $isfinal = (@$proc && $proc->[0] eq '');
if (!$isfinal) {
$reader = new IO::Handle or die $!;
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;
+ }
+ if (!$olddone) {
$olddone = { };
$changed = 1;
}
- my $newdone = { };
- my $log = new IO::File "$fontdir/$logfile", "w"
- or die "$fontdir/$logfile $!";
+ my $newdone = { '' => $foundryinfo };
my %outfiles; # bitmask: 1 /*exists*/ | 2 /*wanted*/
my $updated=0;
my $reported=0;
my $anypcfs=0;
+ my $logpath = "$fontdir/$logfile";
+ unlink "$logpath" or $!==&ENOENT or die "$logpath $!";
+ my $log = new IO::File $logpath, ">>" or die "$logpath $!";
+
+ if (!$wanted_parallel) {
+ $wanted_parallel = Sys::CPU::cpu_count();
+ printf $reportfh "parallelism: %d\n", $wanted_parallel if $verbose>=2;
+ }
+ $wanted_parallel = 1 if $wanted_parallel < 1;
+
+ our %inprogress;
+
+ my $await = sub {
+ my $child = wait;
+ die $! unless defined $child;
+ my $job = $inprogress{$child};
+ die $child unless $job;
+
+ my $dent = $job->{Dent};
+ my $outdent = $job->{Outdent};
+ my $stats = $job->{Stats};
+ if ($?==0) {
+ $updated++;
+ $outfiles{$outdent} |= 3;
+ } elsif ($?==2*256) {
+ } else {
+ die "[$child] $dent $outdent $?";
+ }
+ $newdone->{$dent} = $stats;
+ $changed = 1;
+ delete $inprogress{$child};
+ };
+
flush $reportfh or die $!;
while (my $dent = scalar readdir FD) {
if ($dent =~ m/^\Q$fontprefix\E.*\.new$/) {
die "$fontdir $dent" unless -f _;
$anypcfs++;
- my $stats = join ' ', ((stat _)[1,7,9,10]);
+ my $stats = statsummary();
my $tdone = $olddone->{$dent};
my $outdent = $fontprefix.$dent;
if (defined $tdone && $tdone eq $stats) {
next;
}
- my $r = processpcfgz("$fontdir/$dent",
- "$fontdir/$outdent.new",
- $log, $dent);
- if ($r !~ m/^\d/) {
- printf $log "%s: unchanged - %s\n", $dent, $r;
- unlink "$fontdir/$outdent.new" or die "$fontdir $outdent $!";
- } else {
- rename "$fontdir/$outdent.new", "$fontdir/$outdent"
- or die "$fontdir $outdent $!";
- $updated++;
- $outfiles{$outdent} |= 3;
+ $await->() while scalar keys %inprogress >= $wanted_parallel;
+
+ my $child = fork; die unless defined $child;
+ if (!$child) {
+ my $r = processpcfgz("$fontdir/$dent",
+ "$fontdir/$outdent.new",
+ $log, $dent);
+ my $rc;
+ if ($r !~ m/^\d/) {
+ printf $log "%s: unchanged - %s\n", $dent, $r;
+ unlink "$fontdir/$outdent.new" or die "$fontdir $outdent $!";
+ $rc = 2;
+ } else {
+ rename "$fontdir/$outdent.new", "$fontdir/$outdent"
+ or die "$fontdir $outdent $!";
+ $rc = 0;
+ }
+ $log->flush or die "$logpath $!";
+ exit $rc;
}
- $newdone->{$dent} = $stats;
- $changed = 1;
+ $inprogress{$child} = {
+ Dent => $dent,
+ Outdent => $outdent,
+ Stats => $stats,
+ };
}
+ $await->() while scalar keys %inprogress;
+
my $affected=0;
foreach my $olddent (keys %outfiles) {
my $state = $outfiles{$olddent};
die "$fontdir $? $!" if $? or $!;
}
if (!$anypcfs) {
- unlink "$fontdir/$logfile" or die "$fontdir $!";
+ unlink "$logpath" or die "$fontdir $!";
unlink "$fontdir/$donefile" or $!==&ENOENT or die "$fontdir $!";
} elsif ($changed) {
my $newdoneh = new IO::File "$fontdir/$donefile.new", 'w'
'R|rules-include=s@' => \@rulespath,
'share-dir=s' => \$sharedir,
'verbose|v+' => \$verbose,
+ 'j|parallel=i' => \$wanted_parallel,
);
sub define_mode ($$) {