summaryrefslogtreecommitdiff
path: root/update-xfonts-traditional
diff options
context:
space:
mode:
authorIan Jackson <ijackson@chiark.greenend.org.uk>2012-01-08 18:30:33 +0000
committerIan Jackson <ijackson@chiark.greenend.org.uk>2012-01-08 18:30:33 +0000
commita94959e6226a210101a74f7a0e9d3c488f70dccf (patch)
tree536755bd3a9aedc9c2300dc5d1612d5d08589b67 /update-xfonts-traditional
parentbaaae94921a3f95a4600c2e101384e00fcf34dc2 (diff)
wip update
Diffstat (limited to 'update-xfonts-traditional')
-rwxr-xr-xupdate-xfonts-traditional60
1 files changed, 50 insertions, 10 deletions
diff --git a/update-xfonts-traditional b/update-xfonts-traditional
index fbafe0b..6063259 100755
--- a/update-xfonts-traditional
+++ b/update-xfonts-traditional
@@ -4,12 +4,14 @@ use POSIX;
use IO::File;
use Getopt::Long;
use File::Glob qw(:glob);
+use Data::Dumper;
our $prefix="/usr/local";
our $package='xfonts-traditional';
our $sharedir="$prefix/share/$package";
our @fontsdirs=qw(/usr/share/fonts/X11 /usr/local/share/fonts/X11);
our $donefile="$package.done";
+our $logfile="$package.log";
our $fontprefix="trad--";
our @rulespath;
our $mode;
@@ -40,8 +42,8 @@ sub loadrules ($) {
return $cache{$key}=undef;
}
-sub processbdf ($$$) {
- my ($inbdf,$outbdf,$what) = @_;
+sub processbdf ($$$$) {
+ my ($inbdf,$outbdf,$logfile,$what) = @_;
my $state='idle';
my ($foundry,$font);
my ($w,$h,$xo,$yo,$y,$bitmap,$glyph);
@@ -105,10 +107,10 @@ sub processbdf ($$$) {
die $! if $outbdf->error or !$outbdf->flush;
die unless $state eq 'idle';
if ($modified) {
- printf $reportfh "%s: %d glyphs changed\n", $what, $modified
+ printf $logfile "%s: %d glyphs changed\n", $what, $modified
or die $!;
} else {
- printf $reportfh "%s: unchanged - no rules matched\n", $what
+ printf $logfile "%s: unchanged - no rules matched\n", $what
or die $!;
}
return $modified;
@@ -157,16 +159,24 @@ sub processfontdir ($) {
die "$fontdir $!" unless $!==&ENOENT;
return;
}
- my $done = do "$fontdir/$donefile";
+ my $olddone = do "$fontdir/$donefile";
if (!$done) {
die "$fontdir $! $@ " unless $!==&ENOENT;
$done = { };
}
+ my $newdone = { };
+ my $log = new IO::File "$fontdir/$logfile", "w"
+ or die "$fontdir/$logfile $!";
my %found;
- while (my $dent = readdir FD) {
+ my $changed;
+ while ($!=0, my $dent = readdir FD) {
+ if ($dent =~ m/^\Q$fontprefix\E.*\.new$/) {
+ unlink "$fontdir/$dent" or $!==&ENOENT or die "$fontdir $dent $!";
+ next;
+ }
next unless $dent =~ m/^[^.\/].*\.pcf\.gz$/;
if ($dent =~ m/^\Q$fontprefix/) {
- $found{$dent} = 1;
+ $found{$dent} ||= 1;
next;
}
if (!stat $dent) {
@@ -175,12 +185,42 @@ sub processfontdir ($) {
}
die "$fontdir $dent" unless -f _;
my $stats = join ' ', ((stat _)[1,7,9,10]);
- $tdone = $done{$dent};
+ $tdone = $olddone->{$dent};
if (defined $tdone && $tdone eq $stats) {
$found{$dent} = 2;
+ $newdone->{$dent} = $stats;
next;
}
-
+ my $outdent = $fontprefix.$dent;
+
+ my $r = processpcfgz("$fontdir/$dent","$fontdir/$outdent.new");
+ if ($r !~ m/^\d/) {
+ print $logfile "%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 $!";
+ $changed = 1;
+ }
+ $found{$outdent} = 2;
+ }
+ die "$fontdir $!" if $!;
+ foreach my $olddent (keys %found) {
+ next if $found{olddent} != 1;
+ unlink "$fontdir/$olddent" or die "$fontdir $olddent $!";
+ $changed = 1;
+ }
+ if ($changed) {
+ $!=0; $?=0; system 'mkfontdir',$fontdir;
+ die "$fontdir $? $!" if $? or $!;
+ my $newdoneh = new IO::File "$fontdir/$donefile.new", 'w'
+ or die "$fontdir $!";
+ print $newdoneh Dumper($newdone) or die "$fontdir $!";
+ close $newdoneh or die "$fontdir $!";
+ rename "$fontdir/$donefile.new","$fontdir/$donefile"
+ or die "$fontdir $!";
+ }
+}
our $stdin = new IO::File '<&STDIN' or die $!;
our $stdout = new IO::File '>&STDOUT' or die $!;
@@ -191,7 +231,7 @@ define_mode('bdf-filter', sub {
die "no arguments allowed with --bdf-filter\n" if @ARGV;
$reportfh = $stderr;
loadfoundries();
- my $r = processbdf($stdin,$stdout,'stdin');
+ my $r = processbdf($stdin,$stdout,$reportfh,'stdin');
if ($r !~ m/^\d/) {
print STDERR "stdin not processed: $r\n";
exit 2;