X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=xfonts-traditional.git;a=blobdiff_plain;f=update-xfonts-traditional;h=eb11b0fef49c5b87b5be4bd598316c0cdcf0cafd;hp=9d05e3a2fa466d983c83cdcafc5f1380428e0e9e;hb=7f092ad2dd37b319591107ab6a3086d0d3a6e800;hpb=71e1fff3fdd26d849f5f0a9bf34354c3d020e848 diff --git a/update-xfonts-traditional b/update-xfonts-traditional index 9d05e3a..eb11b0f 100755 --- a/update-xfonts-traditional +++ b/update-xfonts-traditional @@ -6,11 +6,12 @@ use Getopt::Long; use File::Glob qw(:glob); use Data::Dumper; use IO::Pipe; +use File::Find; our $prefix="/usr/local"; our $package='xfonts-traditional'; our $sharedir="$prefix/share/$package"; -our @fontparentdirs=qw(/usr/share/fonts/X11 /usr/local/share/fonts/X11); +our @fonttrees=qw(/usr/share/fonts/X11 /usr/local/share/fonts/X11); our $donefile="$package.done"; our $logfile="$package.log"; our $fontprefix="trad--"; @@ -117,20 +118,6 @@ sub processbdf ($$$$) { return $modified; } -our (@options)=( - 'R|rules-include=s@' => \@rulespath, - 'share-dir=s' => \$sharedir, - 'verbose|v+' => \$verbose, - ); - -sub define_mode ($$) { - my ($optname,$f) = @_; - push @options, $optname, sub { - die "only one mode may be specified\n" if defined $mode; - $mode=$f; - }; -} - sub loadfoundries () { foreach my $path (@rulespath) { my $p = "$path/foundries"; @@ -227,19 +214,21 @@ sub processfontdir ($) { die "$fontdir $!" unless $!==&ENOENT; return; } + my $changed = 0; my $olddone = do "$fontdir/$donefile"; if (!$olddone) { die "$fontdir $! $@ " unless $!==&ENOENT; $olddone = { }; + $changed = 1; } my $newdone = { }; my $log = new IO::File "$fontdir/$logfile", "w" or die "$fontdir/$logfile $!"; my %outfiles; # bitmask: 1 /*exists*/ | 2 /*wanted*/ - my $changed; my $updated=0; + my $reported=0; + my $anypcfs=0; - print $reportfh "processing $fontdir...\n" or die $!; flush $reportfh or die $!; while (my $dent = scalar readdir FD) { if ($dent =~ m/^\Q$fontprefix\E.*\.new$/) { @@ -247,6 +236,8 @@ sub processfontdir ($) { next; } next unless $dent =~ m/^[^.\/].*\.pcf\.gz$/; + print $reportfh "processing $fontdir...\n" or die $! + unless $reported++; if ($dent =~ m/^\Q$fontprefix/) { $outfiles{$dent} |= 1; next; @@ -256,6 +247,8 @@ sub processfontdir ($) { next; } die "$fontdir $dent" unless -f _; + $anypcfs++; + my $stats = join ' ', ((stat _)[1,7,9,10]); my $tdone = $olddone->{$dent}; my $outdent = $fontprefix.$dent; @@ -276,9 +269,9 @@ sub processfontdir ($) { or die "$fontdir $outdent $!"; $updated++; $outfiles{$outdent} |= 3; - $changed = 1; } $newdone->{$dent} = $stats; + $changed = 1; } my $affected=0; foreach my $olddent (keys %outfiles) { @@ -289,13 +282,18 @@ sub processfontdir ($) { } unlink "$fontdir/$olddent" or die "$fontdir $olddent $!"; $changed = 1; + $updated++; + } + if (!stat "$fontdir/fonts.dir") { + $!==&ENOENT or die "$fontdir $!"; + } else { + $!=0; $?=0; system 'mkfontdir',$fontdir; + die "$fontdir $? $!" if $? or $!; } - if (!%$newdone) { + if (!$anypcfs) { unlink "$fontdir/$logfile" or die "$fontdir $!"; unlink "$fontdir/$donefile" or $!==&ENOENT or die "$fontdir $!"; } elsif ($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 $!"; @@ -303,8 +301,22 @@ sub processfontdir ($) { rename "$fontdir/$donefile.new","$fontdir/$donefile" or die "$fontdir $!"; } - printf " processed %s: %d pcfs, %d affected, %d updated.\n", - $fontdir, (scalar keys %$newdone), $affected, $updated; + if ($reported || %$newdone || $affected || $updated) { + printf " processed %s: %d pcfs, %d affected, %d updated.\n", + $fontdir, (scalar keys %$newdone), $affected, $updated; + } +} + +sub processfonttree ($) { + my ($tree) = @_; + find({ follow => 1, + dangling_symlinks => 0, + no_chdir => 1, + wanted => sub { + return unless -d _; + processfontdir($File::Find::name); + }}, + $tree); } our $stdin = new IO::File '<&STDIN' or die $!; @@ -312,6 +324,20 @@ our $stdout = new IO::File '>&STDOUT' or die $!; our $stderr = new IO::File '>&STDERR' or die $!; $reportfh = $stdout; +our (@options)=( + 'R|rules-include=s@' => \@rulespath, + 'share-dir=s' => \$sharedir, + 'verbose|v+' => \$verbose, + ); + +sub define_mode ($$) { + my ($optname,$f) = @_; + push @options, $optname, sub { + die "only one mode may be specified\n" if defined $mode; + $mode=$f; + }; +} + define_mode('bdf-filter', sub { die "no arguments allowed with --bdf-filter\n" if @ARGV; $reportfh = $stderr; @@ -333,7 +359,7 @@ define_mode('process-pcf', sub { } }); -define_mode('process-fontdir', sub { +define_mode('process-fontdirs', sub { die "need font dir(s)\n" unless @ARGV; loadfoundries(); foreach my $d (@ARGV) { @@ -341,6 +367,22 @@ define_mode('process-fontdir', sub { } }); +define_mode('process-fonttrees', sub { + die "need font tree(s)\n" unless @ARGV; + loadfoundries(); + foreach my $d (@ARGV) { + processfonttree($d); + } +}); + +define_mode('update', sub { + die "no arguments allowed with --postinst\n" unless !@ARGV; + loadfoundries(); + foreach my $d (@fonttrees) { + processfonttree($d); + } +}); + Getopt::Long::Configure(qw(bundling)); GetOptions(@options) or exit 127; @@ -349,12 +391,3 @@ push @rulespath, "$sharedir/rules"; die "need a mode\n" unless $mode; $mode->(); - -# 70 zcat /usr/share/fonts/X11/misc/6x13.pcf.gz |pcf2bdf >in.bdf -# 71 ./utility out.bdf -# 83 bdftopcf out.bdf >out.pcf -# 84 gzip out.pcf -# 85 cp out.pcf.gz /usr/share/fonts/X11/misc/ -# really mkfontdir /usr/share/fonts/X11/misc/ -# xset fp rehash -# xfontsel