summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2011-07-02 12:47:50 +0000
committerMarc Espie <espie@cvs.openbsd.org>2011-07-02 12:47:50 +0000
commit3cb9d2cc3561dba1595dc3e17043a99a4a03b7af (patch)
tree8e83d1ab2141495e58f7331296a3975e601edd2a /libexec
parentf2f9870bac6d779cfdb25ccb7e8a9be09287ca61 (diff)
add file equivalence. Choose the most recent timestamp between man and
catman pages. okay millert@
Diffstat (limited to 'libexec')
-rw-r--r--libexec/makewhatis/OpenBSD/Makewhatis/Find.pm56
1 files changed, 42 insertions, 14 deletions
diff --git a/libexec/makewhatis/OpenBSD/Makewhatis/Find.pm b/libexec/makewhatis/OpenBSD/Makewhatis/Find.pm
index 8d38b860637..4b268d62f86 100644
--- a/libexec/makewhatis/OpenBSD/Makewhatis/Find.pm
+++ b/libexec/makewhatis/OpenBSD/Makewhatis/Find.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: Find.pm,v 1.2 2005/03/05 11:02:35 espie Exp $
+# $OpenBSD: Find.pm,v 1.3 2011/07/02 12:47:49 espie Exp $
# Copyright (c) 2000-2004 Marc Espie <espie@openbsd.org>
#
# Permission to use, copy, modify, and distribute this software for any
@@ -20,6 +20,21 @@ package OpenBSD::Makewhatis::Find;
use File::Find;
+# Find out all file names that correspond to existing stuff
+
+sub equivalents
+{
+ my $_ = shift;
+ my @l = ();
+ s/(?:\.Z|\.gz)$//;
+ push(@l, $_, "$_.Z", "$_.gz");
+ if (s,/cat([\dln]\w*?)/(.*)\.0$,/man$1/$2.$1,) {
+ push(@l, $_, "$_.Z", "$_.gz");
+ } elsif (s,/man([\dln]\w*?)/(.*)\.\1$,/cat$1/$2.0,) {
+ push(@l, $_, "$_.Z", "$_.gz");
+ }
+ return @l;
+}
# $list = find_manpages($dir)
#
@@ -27,19 +42,32 @@ use File::Find;
#
sub find_manpages($)
{
- my $dir = shift;
- my ($list, %nodes);
- $list=[];
- find(
- sub {
- return unless m/\.[\dln]\w*(?:\.Z|\.gz)?$/;
- return unless -f $_;
- my $unique = (stat _)[0]."/".(stat _)[1];
- return if defined $nodes{$unique};
- $nodes{$unique} = 1;
- push(@$list, $File::Find::name);
- }, $dir);
- return $list;
+ my $dir = shift;
+ my $h = {};
+ my $list=[];
+ my $nodes = {};
+ my $done = {};
+ find(
+ sub {
+ return unless m/\.[\dln]\w*(?:\.Z|\.gz)?$/;
+ return unless -f $_;
+ my $unique = join("/", (stat _)[0,1]);
+ return if defined $nodes->{$unique};
+ $nodes->{$unique} = 1;
+ push @$list, $File::Find::name;
+ $h->{$File::Find::name} = (stat _)[9];
+ }, $dir);
+ for my $i (keys %$h) {
+ next if $done->{$i};
+ # only keep stuff that actually exists
+ my @l = grep {defined $h->{$_}} equivalents($i);
+ # don't do it twice
+ $done->{$_} = 1 for @l;
+ # find the most recent one
+ @l = sort {$h->{$a} <=> $h->{$b}} @l;
+ push @$list, pop @l;
+ }
+ return $list;
}
1;