| 1 | #!/usr/local/bin/perl | ||||||||||||||||||||||||||||||||||
| 2 | 2 | eval 'exec perl -S $0 "$@"' | |||||||||||||||||||||||||||||||||
| 3 | if 0; | ||||||||||||||||||||||||||||||||||
| 4 | # -*- Mode: Perl -*- | ||||||||||||||||||||||||||||||||||
| 5 | # Author : Ulrich Pfeifer | ||||||||||||||||||||||||||||||||||
| 6 | # Created On : Mon Jan 22 13:00:41 1996 | ||||||||||||||||||||||||||||||||||
| 7 | # Last Modified On: Sun Jan 6 22:26:28 2013 | ||||||||||||||||||||||||||||||||||
| 8 | # Language : Perl | ||||||||||||||||||||||||||||||||||
| 9 | # Update Count : 399 | ||||||||||||||||||||||||||||||||||
| 10 | # Status : Unknown, Use with caution! | ||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||
| 12 | # (C) Copyright 1996-2005, Ulrich Pfeifer, all rights reserved. | ||||||||||||||||||||||||||||||||||
| 13 | # This file is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||
| 14 | # under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||||||||
| 17 | # %SEEN is used to store the mtime and absolute pathes to | ||||||||||||||||||||||||||||||||||
| 18 | # files which have been indexed. | ||||||||||||||||||||||||||||||||||
| 19 | # | ||||||||||||||||||||||||||||||||||
| 20 | # %FN $FN{'last'} greatest documentid | ||||||||||||||||||||||||||||||||||
| 21 | # $FN{$did} a pair of $mtf and $filename where $mtf is the | ||||||||||||||||||||||||||||||||||
| 22 | # number of occurances of the most frequent word in | ||||||||||||||||||||||||||||||||||
| 23 | # the document with number $did. | ||||||||||||||||||||||||||||||||||
| 24 | # | ||||||||||||||||||||||||||||||||||
| 25 | # %IDF $IDF{'*all*'} number of documents (essentially the same as | ||||||||||||||||||||||||||||||||||
| 26 | # $FN{'last'}) | ||||||||||||||||||||||||||||||||||
| 27 | # $IDF{$word} number of documents containing $word | ||||||||||||||||||||||||||||||||||
| 28 | # | ||||||||||||||||||||||||||||||||||
| 29 | # %IF $IF{$word} list of pairs ($docid,$tf) where $docid is | ||||||||||||||||||||||||||||||||||
| 30 | # the number of a document containing $word $tf | ||||||||||||||||||||||||||||||||||
| 31 | # | ||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | use Fcntl; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | use less 'time'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 36 | 2 | ▶ | use Text::English; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | use Config; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | # NDBM_File as LAST resort | ||||||||||||||||||||||||||||||||||
| 40 | 2 | ▶ | BEGIN { @AnyDBM_File::ISA = qw(DB_File GDBM_File SDBM_File ODBM_File NDBM_File) } | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 41 | 2 | ▶ | use AnyDBM_File; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 2 | $p = 'w'; # compressed int patch available | |||||||||||||||||||||||||||||||||
| 44 | 2 | $nroff = 'nroff' || 'nroff'; | |||||||||||||||||||||||||||||||||
| 45 | 2 | $man1direxp = ''; | |||||||||||||||||||||||||||||||||
| 46 | 2 | $man3direxp = ''; | |||||||||||||||||||||||||||||||||
| 47 | 2 | $IDIR = ''; | |||||||||||||||||||||||||||||||||
| 48 | 2 | $prefix = '/usr/local'; | |||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | 2 | $pager= $Config{'pager'}; | |||||||||||||||||||||||||||||||||
| 51 | 2 | ▶ | if ($Config{'osname'} eq 'hpux') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 52 | 0 | $pager= "col | $pager"; | |||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | if (exists $ENV{PAGER}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 55 | $pager=$ENV{PAGER} | ||||||||||||||||||||||||||||||||||
| 56 | 0 | } | |||||||||||||||||||||||||||||||||
| 57 | 2 | $stemmer = \&Text::English::stem; | |||||||||||||||||||||||||||||||||
| 58 | 2 | $debug = 0; | |||||||||||||||||||||||||||||||||
| 59 | 2 | $opt_index = ''; # make perl -w happy | |||||||||||||||||||||||||||||||||
| 60 | 2 | $opt_menu = 1; | |||||||||||||||||||||||||||||||||
| 61 | 2 | $opt_maxhits = 20; | |||||||||||||||||||||||||||||||||
| 62 | 2 | $opt_cbreak = 1; | |||||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | &GetOptions( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 64 | 'index', | ||||||||||||||||||||||||||||||||||
| 65 | 'cbreak!', | ||||||||||||||||||||||||||||||||||
| 66 | 'maxhits=i', | ||||||||||||||||||||||||||||||||||
| 67 | 'menu!', | ||||||||||||||||||||||||||||||||||
| 68 | 'verbose', | ||||||||||||||||||||||||||||||||||
| 69 | 'dict:i', | ||||||||||||||||||||||||||||||||||
| 70 | 'idir=s', | ||||||||||||||||||||||||||||||||||
| 71 | ) || die "Usage: $0 [-index] [words ...]\n"; | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | if (defined $opt_idir) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 74 | 2 | $IDIR = $opt_idir; # avoid to many changes below. | |||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | 2 | ▶ | if (defined $opt_dict) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $opt_dict ||= 100; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opt_dict ||= 100
MC/DC0%0/1
$opt_dict ||= 100
$opt_dict
Truth table0%0/2
A
A= $opt_dict
| |||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||
| 81 | 2 | my $GC_REQUIRED = 0; # garbage collect required? Global variable. | |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | 2 | ▶ | if ($opt_index) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||
| 85 | # check whether we can use Pod::Text to extract POD | ||||||||||||||||||||||||||||||||||
| 86 | 1 | $PodText = 0; | |||||||||||||||||||||||||||||||||
| 87 | 1 | eval { | |||||||||||||||||||||||||||||||||
| 88 | 1 | require Pod::Text; | |||||||||||||||||||||||||||||||||
| 89 | 1 | print "Using Pod::Text\n"; | |||||||||||||||||||||||||||||||||
| 90 | 1 | $PodText = 1; | |||||||||||||||||||||||||||||||||
| 91 | }; | ||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | 1 | $IoScalar = 0; | |||||||||||||||||||||||||||||||||
| 95 | 1 | eval { | |||||||||||||||||||||||||||||||||
| 96 | 1 | require IO::Scalar; | |||||||||||||||||||||||||||||||||
| 97 | 0 | print "Using IO::Scalar\n"; | |||||||||||||||||||||||||||||||||
| 98 | 0 | $IoScalar = 1; | |||||||||||||||||||||||||||||||||
| 99 | }; | ||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||
| 101 | 1 | &initstop; | |||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||
| 103 | 1 | ▶ | tie (%IF, AnyDBM_File, "$IDIR/index_if", O_CREAT|O_RDWR, 0644) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 104 | or die "Could not tie $IDIR/index_if: $!\n"; | ||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | tie (%IDF, AnyDBM_File, "$IDIR/index_idf", O_CREAT|O_RDWR, 0644) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 106 | or die "Could not tie $IDIR/index_idf: $!\n"; | ||||||||||||||||||||||||||||||||||
| 107 | 1 | ▶ | tie (%SEEN, AnyDBM_File, "$IDIR/index_seen", O_CREAT|O_RDWR, 0644) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 108 | or die "Could not tie $IDIR/index_seen: $!\n"; | ||||||||||||||||||||||||||||||||||
| 109 | 1 | ▶ | tie (%FN, AnyDBM_File, "$IDIR/index_fn", O_CREAT|O_RDWR, 0644) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 110 | or die "Could not tie $IDIR/index_fn: $!\n"; | ||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||
| 112 | 1 | require File::Find; | |||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | unless (@ARGV) { # breaks compatibility :-( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 115 | 0 | my %seen; | |||||||||||||||||||||||||||||||||
| 116 | my @perllib = grep(length && -d && !$seen{$_}++, | ||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | @Config{qw(installprivlib installarchlib installsitelib installvendorlib installscript installsitearch)}); | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
length $_ && -d $_ && !$seen{$_}++
length $_ and -d $_
MC/DC0%0/3
length $_ && -d $_ && !$seen{$_}++
length $_
-d $_
!$seen{$_}++
Truth table0%0/4
A and B && not(C)
A= length $_B= -d $_C= !$seen{$_}++
| |||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||
| 119 | 0 | for $dir (@perllib) { | |||||||||||||||||||||||||||||||||
| 120 | 0 | print "Scanning $dir ... \n"; | |||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if (-l $dir) { # debian symlinks installarchlib but we do not want to follow links in general | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 122 | 0 | my $target = readlink $dir; | |||||||||||||||||||||||||||||||||
| 123 | 0 | $dir =~ s:[^/]+$:$target:; | |||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||
| 125 | 0 | File::Find::find( \&wanted, $dir ); | |||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||
| 129 | 1 | for $name (@ARGV) { | |||||||||||||||||||||||||||||||||
| 130 | 3 | add_to_index($name); | |||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||
| 132 | # Check if all (previuosly) indexed files are still available | ||||||||||||||||||||||||||||||||||
| 133 | # This may take some time. | ||||||||||||||||||||||||||||||||||
| 134 | 1 | warn "Validating index ...\n"; | |||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | while (my ($fns, $value) = each %SEEN) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 136 | 3 | ▶ | my $path = $fns; $path = $prefix.'/'.$path unless $path =~ m:^/:; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 137 | 3 | ▶ | unless (-f $path) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 138 | 0 | my ($mtime, $did) = unpack "$p$p", $value; | |||||||||||||||||||||||||||||||||
| 139 | # mark document as deleted | ||||||||||||||||||||||||||||||||||
| 140 | 0 | warn "Marking document $did ($fns) as deleted\n"; | |||||||||||||||||||||||||||||||||
| 141 | 0 | delete $FN{$did}; | |||||||||||||||||||||||||||||||||
| 142 | 0 | delete $SEEN{$fns}; | |||||||||||||||||||||||||||||||||
| 143 | 0 | $GC_REQUIRED++; | |||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||
| 146 | 1 | ▶ | if ($GC_REQUIRED) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 147 | 0 | print STDERR "Garbage collecting\r"; | |||||||||||||||||||||||||||||||||
| 148 | # garbage collection, this is awfully slow | ||||||||||||||||||||||||||||||||||
| 149 | 0 | my $progress = 0; | |||||||||||||||||||||||||||||||||
| 150 | 0 | my $words = keys %IF; | |||||||||||||||||||||||||||||||||
| 151 | 0 | my %if_new; | |||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | tie (%if_new, AnyDBM_File, "$IDIR/index_if.new", O_CREAT|O_RDWR, 0644) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 153 | or die "Could not tie $IDIR/index_if: $!\n"; | ||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | while (my ($word,$list) = each %IF) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 155 | 0 | print STDERR "Garbage collecting ".(++$progress)."/".$words."\r"; | |||||||||||||||||||||||||||||||||
| 156 | 0 | my %post = unpack($p.'*',$list); | |||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||
| 158 | #delete $IF{$word}; | ||||||||||||||||||||||||||||||||||
| 159 | 0 | $IDF{$word} = 0; | |||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | while (my ($did,$tf) = each %post) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if (exists $FN{$did}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | $if_new{$word} = '' unless defined $if{$word}; # perl -w | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 163 | 0 | $if_new{$word} .= pack($p.$p, $did, $tf); | |||||||||||||||||||||||||||||||||
| 164 | 0 | $IDF{$word}++; | |||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||
| 168 | 0 | untie %if_new; | |||||||||||||||||||||||||||||||||
| 169 | 0 | untie %IF; | |||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | opendir(IDX, $IDIR) or die "Could not read dir '$IDIR': $!"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 171 | 0 | for $file (readdir DIR) { | |||||||||||||||||||||||||||||||||
| 172 | 0 | my $old = $file; | |||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | if ($file =~ s/^index_if\.new/index_if/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 174 | 0 | rename "$IDIR/$old", "$IDIR/$file"; | |||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||
| 177 | 0 | print STDERR "\rGarbage collecting ... done"; | |||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||
| 179 | 1 | ▶ | untie %IF unless $GC_REQUIRED; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 180 | 1 | untie %IDF; | |||||||||||||||||||||||||||||||||
| 181 | 1 | untie %FN; | |||||||||||||||||||||||||||||||||
| 182 | 1 | untie %SEEN; | |||||||||||||||||||||||||||||||||
| 183 | } elsif ($opt_dict) { | ||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | tie (%IDF, AnyDBM_File, "$IDIR/index_idf", O_RDONLY, 0644) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 185 | or die "Could not tie $IDIR/index_idf: $!\n". | ||||||||||||||||||||||||||||||||||
| 186 | "Did you run '$0 -index'?\n"; | ||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | while (($key,$val) = each %IDF) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | printf "%-20s %d\n", $key, $val if $val >= $opt_dict; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||
| 190 | 0 | untie %IDF; | |||||||||||||||||||||||||||||||||
| 191 | } else { | ||||||||||||||||||||||||||||||||||
| 192 | 1 | ▶ | tie (%IF, AnyDBM_File, "$IDIR/index_if", O_RDONLY, 0644) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 193 | or die "Could not tie $IDIR/index_if: $!\n". | ||||||||||||||||||||||||||||||||||
| 194 | "Did you run '$0 -index'?\n"; | ||||||||||||||||||||||||||||||||||
| 195 | 1 | ▶ | tie (%IDF, AnyDBM_File, "$IDIR/index_idf", O_RDONLY, 0644) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 196 | or die "Could not tie $IDIR/index_idf: $!\n"; | ||||||||||||||||||||||||||||||||||
| 197 | 1 | ▶ | tie (%FN, AnyDBM_File, "$IDIR/index_fn", O_RDONLY, 0644) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 198 | or die "Could not tie $IDIR/index_fn: $!\n"; | ||||||||||||||||||||||||||||||||||
| 199 | 1 | &search(@ARGV); | |||||||||||||||||||||||||||||||||
| 200 | 1 | untie %IF; | |||||||||||||||||||||||||||||||||
| 201 | 1 | untie %IDF; | |||||||||||||||||||||||||||||||||
| 202 | 1 | untie %FN; | |||||||||||||||||||||||||||||||||
| 203 | 1 | untie %SEEN; | |||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | sub wanted { | ||||||||||||||||||||||||||||||||
|
Subroutine
wanted: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 207 | 0 | my $fns = $File::Find::name; | |||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | if ($File::Find::name eq $man3direxp) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 210 | 0 | $File::Find::prune = 1; | |||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if (-f $_ and $File::Find::name =~ /man|bin|\.(pod|pm|txt)$/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f $_ and $File::Find::name =~ /man|bin|\.(pod|pm|txt)$/
MC/DC0%0/2
-f $_ and $File::Find::name =~ /man|bin|\.(pod|pm|txt)$/
-f $_
$File::Find::name =~ /man|bin|\.(pod|pm|txt)$/
Truth table0%0/3
A and B
A= -f $_B= $File::Find::name =~ /man|bin|\.(pod|pm|txt)$/
| |||||||||||||||||||||||||||||||||||
| 213 | 0 | add_to_index($File::Find::name); | |||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||
| 217 | 3 | ▶ | sub index { | ||||||||||||||||||||||||||||||||
|
Subroutine
index: called CC=32 SCAR=56.1
| |||||||||||||||||||||||||||||||||||
| 218 | 3 | my $fn = shift; | |||||||||||||||||||||||||||||||||
| 219 | 3 | my $fns = shift; | |||||||||||||||||||||||||||||||||
| 220 | 3 | my $did = shift; | |||||||||||||||||||||||||||||||||
| 221 | 3 | my %tf; | |||||||||||||||||||||||||||||||||
| 222 | 3 | my $maxtf = 0; | |||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||
| 224 | 3 | ▶ | if ($fn =~ /\.txt$/) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | open (IN, "<$fn") || warn "Could not open $fn: $!\n", return (0); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | while ($line = <IN>) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | warn "=> $line\n" if $debug; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 228 | 0 | for $word (&normalize($line)) { | |||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | next if $stop{$word}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 230 | 0 | $tf{$word}++; | |||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||
| 233 | 0 | close IN; | |||||||||||||||||||||||||||||||||
| 234 | ▶ | } elsif($PodText and -T $fn) { | |||||||||||||||||||||||||||||||||
|
Condition33%1/3
$PodText and -T $fn
MC/DC0%0/2
$PodText and -T $fn
$PodText
-T $fn
Truth table33%1/3
A and B
A= $PodTextB= -T $fn
| |||||||||||||||||||||||||||||||||||
| 235 | 3 | my $result; | |||||||||||||||||||||||||||||||||
| 236 | 3 | my $parser = Pod::Text->new(sentence => 0, width => 78); | |||||||||||||||||||||||||||||||||
| 237 | 3 | ▶ | if ($IoScalar) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 238 | 0 | my $tmpfile = new IO::Scalar; | |||||||||||||||||||||||||||||||||
| 239 | 0 | open(IN,"<$fn"); | |||||||||||||||||||||||||||||||||
| 240 | 0 | $parser->parse_from_filehandle(*IN, $tmpfile); | |||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | warn "===> $fn, $tmpfile" if $debug; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 242 | #for my $line (split /\n/, $tmpfile) { | ||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | while ($tmpfile =~ s/^(.*\n)//) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | warn "=> $1\n" if $debug; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 245 | 0 | for $word (&normalize($1)) { | |||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | next if $stop{$word}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 247 | 0 | $tf{$word}++; | |||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||
| 250 | 0 | close IN; | |||||||||||||||||||||||||||||||||
| 251 | } else { | ||||||||||||||||||||||||||||||||||
| 252 | 3 | my $tmpfile = "$IDIR/tmppod.txt"; | |||||||||||||||||||||||||||||||||
| 253 | 3 | $parser->parse_from_file($fn, $tmpfile); | |||||||||||||||||||||||||||||||||
| 254 | 3 | ▶ | open (IN, "<$tmpfile") || warn "Could not open $fn: $!\n", return (0); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 255 | 3 | ▶ | while ($line = <IN>) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 256 | 88 | ▶ | warn "=> $line\n" if $debug; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 257 | 88 | for $word (&normalize($line)) { | |||||||||||||||||||||||||||||||||
| 258 | 286 | ▶ | next if $stop{$word}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 259 | 216 | $tf{$word}++; | |||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||
| 262 | 3 | close IN; | |||||||||||||||||||||||||||||||||
| 263 | 3 | unlink $tmpfile; | |||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||
| 265 | } else { | ||||||||||||||||||||||||||||||||||
| 266 | # no Pod::Text found | ||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | open(IN, "<$fn") || warn "Could not open $fn: $!\n", return (0); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | while ($line = <IN>) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | warn "=> $line\n" if $debug; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | if ($line =~ /^=head/) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 271 | 0 | $pod = 1; | |||||||||||||||||||||||||||||||||
| 272 | } elsif ($line =~ /^=cut/){ | ||||||||||||||||||||||||||||||||||
| 273 | 0 | $pod = 0; | |||||||||||||||||||||||||||||||||
| 274 | } else { | ||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | next unless $pod; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||
| 277 | 0 | for $word (&normalize($line)) { | |||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | next if $stop{$word}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 279 | 0 | $tf{$word}++; | |||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||
| 282 | 0 | close(IN); | |||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||
| 284 | 3 | for $tf (values %tf) { | |||||||||||||||||||||||||||||||||
| 285 | 100 | ▶ | $maxtf = $tf if $tf > $maxtf; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||
| 287 | 3 | for $word (keys %tf) { | |||||||||||||||||||||||||||||||||
| 288 | 100 | $IDF{$word}++; | |||||||||||||||||||||||||||||||||
| 289 | 100 | ▶ | $IF{$word} = '' unless defined $IF{$word}; # perl -w | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 290 | 100 | $IF{$word} .= pack($p.$p, $did, $tf{$word}); | |||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||
| 292 | 3 | $FN{$did} = pack($p, $maxtf).$fns; | |||||||||||||||||||||||||||||||||
| 293 | 3 | print STDERR "$fns\n"; | |||||||||||||||||||||||||||||||||
| 294 | 3 | 1; | |||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||
| 297 | 3 | ▶ | sub add_to_index { | ||||||||||||||||||||||||||||||||
|
Subroutine
add_to_index: called CC=6 SCAR=22.6
| |||||||||||||||||||||||||||||||||||
| 298 | 3 | my ($name) = @_; | |||||||||||||||||||||||||||||||||
| 299 | 3 | my $fns = $name; $fns =~ s:\Q$prefix/::; | |||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||
| 301 | 3 | ▶ | if (exists $SEEN{$fns}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 302 | 0 | my ($mtime, $did) = unpack "$p$p", $SEEN{$fns}; | |||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | if ((stat $name)[9] > $mtime) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 304 | # mark document as deleted | ||||||||||||||||||||||||||||||||||
| 305 | 0 | delete $FN{$did}; | |||||||||||||||||||||||||||||||||
| 306 | 0 | warn "Marking document $did ($name) as deleted\n"; | |||||||||||||||||||||||||||||||||
| 307 | 0 | $GC_REQUIRED++; | |||||||||||||||||||||||||||||||||
| 308 | } else { | ||||||||||||||||||||||||||||||||||
| 309 | # index up to date | ||||||||||||||||||||||||||||||||||
| 310 | 0 | next; | |||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||
| 313 | 3 | ▶ | next unless -f $name; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 314 | 3 | ▶ | if ($name !~ /(~|,v)$/) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 315 | 3 | $did = $FN{'last'}++; | |||||||||||||||||||||||||||||||||
| 316 | 3 | ▶ | if (&index($name, $fns, $did)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 317 | 3 | my ($mtime) = (stat $name)[9]; | |||||||||||||||||||||||||||||||||
| 318 | 3 | $SEEN{$fns} = pack "$p$p", (stat $name)[9], $did; | |||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||
| 323 | 548 | ▶ | sub normalize { | ||||||||||||||||||||||||||||||||
|
Subroutine
normalize: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||
| 324 | 548 | my $line = join ' ', @_; | |||||||||||||||||||||||||||||||||
| 325 | 548 | my @result; | |||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||
| 327 | 548 | $line =~ tr/A-Z/a-z/; | |||||||||||||||||||||||||||||||||
| 328 | 548 | $line =~ tr/a-z0-9_/ /cs; | |||||||||||||||||||||||||||||||||
| 329 | 548 | for $word (split / /, $line ) { | |||||||||||||||||||||||||||||||||
| 330 | 966 | $word =~ s/^\d+//; | |||||||||||||||||||||||||||||||||
| 331 | 966 | ▶ | next unless length($word) > 2; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 332 | 680 | ▶ | if ($stemmer) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 333 | 680 | push @result, &$stemmer($word); | |||||||||||||||||||||||||||||||||
| 334 | } else { | ||||||||||||||||||||||||||||||||||
| 335 | 0 | push @result, $word; | |||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||
| 338 | 548 | @result; | |||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||
| 341 | 1 | ▶ | sub search { | ||||||||||||||||||||||||||||||||
|
Subroutine
search: called CC=27 SCAR=59.5
| |||||||||||||||||||||||||||||||||||
| 342 | 1 | my %score; | |||||||||||||||||||||||||||||||||
| 343 | 1 | my $maxhits = $opt_maxhits; | |||||||||||||||||||||||||||||||||
| 344 | 1 | my (@unknown, @stop); | |||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||
| 346 | 1 | ▶ | &initstop if $opt_verbose; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 347 | 1 | for $word (normalize(@_)) { | |||||||||||||||||||||||||||||||||
| 348 | 1 | ▶ | unless ($IF{$word}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | if ($stop{$word}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 350 | 0 | push @stop, $word; | |||||||||||||||||||||||||||||||||
| 351 | } else { | ||||||||||||||||||||||||||||||||||
| 352 | 0 | push @unknown, $word; | |||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||
| 354 | 0 | next; | |||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||
| 356 | 1 | my %post = unpack($p.'*',$IF{$word}); | |||||||||||||||||||||||||||||||||
| 357 | 1 | my $idf = log($FN{'last'}/$IDF{$word}); | |||||||||||||||||||||||||||||||||
| 358 | 1 | for $did (keys %post) { | |||||||||||||||||||||||||||||||||
| 359 | # skip deleted documents | ||||||||||||||||||||||||||||||||||
| 360 | 1 | ▶ | next unless exists $FN{$did}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 361 | 1 | my ($maxtf) = unpack($p, $FN{$did}); | |||||||||||||||||||||||||||||||||
| 362 | 1 | ▶ | $score{$did} = 0 unless defined $score{$did}; # perl -w | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 363 | 1 | $score{$did} += $post{$did} / $maxtf * $idf; | |||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||
| 366 | 1 | ▶ | if ($opt_verbose) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | print "Unkown: @unknown\n" if @unknown; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | print "Ingnore: @stop\n" if @stop; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||
| 370 | 1 | ▶ | if ($opt_menu) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 371 | 0 | my @menu; | |||||||||||||||||||||||||||||||||
| 372 | 0 | my $answer = ''; | |||||||||||||||||||||||||||||||||
| 373 | 0 | my $no = 0; | |||||||||||||||||||||||||||||||||
| 374 | 0 | my @s = ('1' .. '9', 'a' .. 'z'); | |||||||||||||||||||||||||||||||||
| 375 | 0 | my %s; | |||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||
| 377 | 0 | for $did (sort {$score{$b} <=> $score{$a}} keys %score) { | |||||||||||||||||||||||||||||||||
| 378 | 0 | my ($mtf, $path) = unpack($p.'a*', $FN{$did}); | |||||||||||||||||||||||||||||||||
| 379 | 0 | my $s = $s[$no]; | |||||||||||||||||||||||||||||||||
| 380 | 0 | push @menu, sprintf "%s %6.3f %s\n", $s, $score{$did}, $path; | |||||||||||||||||||||||||||||||||
| 381 | 0 | $s{$s} = ++$no; | |||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | last unless --$maxhits; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | &cbreak('on') if $opt_cbreak; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 385 | 0 | while (1) { | |||||||||||||||||||||||||||||||||
| 386 | 0 | print @menu; | |||||||||||||||||||||||||||||||||
| 387 | 0 | print "\nEnter Number or 'q'> "; | |||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | if ($opt_cbreak) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 389 | 0 | read(TTYIN,$answer,1); | |||||||||||||||||||||||||||||||||
| 390 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||
| 391 | } else { | ||||||||||||||||||||||||||||||||||
| 392 | 0 | $answer = <STDIN>; | |||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | last if $answer =~ /^q/i; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 395 | 0 | $answer = ($s{substr($answer,0,1)})-1; | |||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | if ($answer >= 0 and $answer <= $#menu) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$answer >= 0 and $answer <= $#menu
MC/DC0%0/2
$answer >= 0 and $answer <= $#menu
$answer >= 0
$answer <= $#menu
Truth table0%0/3
A and B
A= $answer >= 0B= $answer <= $#menu
| |||||||||||||||||||||||||||||||||||
| 397 | 0 | my $selection = $menu[$answer]; chomp($selection); | |||||||||||||||||||||||||||||||||
| 398 | 0 | my ($no, $score, $path) = split ' ', $selection, 3; | |||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | $path = $prefix.'/'.$path unless $path =~ m:^/:; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||
| 401 | 0 | ▶ | if ($path =~ /\.txt$/) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 402 | 0 | my $pdf = $path; $pdf =~ s:pages/(\S+)_(\d+)\.txt$:$1.pdf:; | |||||||||||||||||||||||||||||||||
| 403 | 0 | my $page = $2+0; | |||||||||||||||||||||||||||||||||
| 404 | 0 | my $endp = $page+2; | |||||||||||||||||||||||||||||||||
| 405 | 0 | my $tmp = "/tmp/perlinde$$.pdf"; | |||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | if (-f $pdf) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 408 | 0 | print "pdftk A=$pdf cat $page-$endp output $tmp\n"; | |||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | system "pdftk", "A=".$pdf, 'cat', "$page-$endp", 'output', $tmp and | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 410 | system "pdftk", "A=".$pdf, 'cat', "$page-end", 'output', $tmp; | ||||||||||||||||||||||||||||||||||
| 411 | 0 | system "acroread", $tmp; | |||||||||||||||||||||||||||||||||
| 412 | 0 | unlink $tmp; | |||||||||||||||||||||||||||||||||
| 413 | } else { | ||||||||||||||||||||||||||||||||||
| 414 | 0 | print STDERR "$pager '$path'\n"; | |||||||||||||||||||||||||||||||||
| 415 | 0 | system $pager, $path; | |||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||
| 417 | } elsif ($selection =~ m:/man:) { | ||||||||||||||||||||||||||||||||||
| 418 | 0 | my ($page, $sect) = | |||||||||||||||||||||||||||||||||
| 419 | ($selection =~ m:([^/]*)\.(.{1,3})$:); | ||||||||||||||||||||||||||||||||||
| 420 | 0 | print STDERR "Running man $sect $page\n"; | |||||||||||||||||||||||||||||||||
| 421 | 0 | system 'man', $sect, $page; | |||||||||||||||||||||||||||||||||
| 422 | } else { | ||||||||||||||||||||||||||||||||||
| 423 | 0 | print STDERR "Running pod2man $path\n"; | |||||||||||||||||||||||||||||||||
| 424 | 0 | system "pod2man --official $path | $nroff -man | $pager"; | |||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||
| 426 | } else { | ||||||||||||||||||||||||||||||||||
| 427 | 0 | my $path = $prefix."/bin/perlindex"; | |||||||||||||||||||||||||||||||||
| 428 | 0 | system "pod2man --official $path | $nroff -man | $pager"; | |||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||
| 431 | 0 | ▶ | &cbreak('off') if $opt_cbreak; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 432 | } else { | ||||||||||||||||||||||||||||||||||
| 433 | 0 | for $did (sort {$score{$b} <=> $score{$a}} keys %score) { | |||||||||||||||||||||||||||||||||
| 434 | printf("%6.3f %s\n", $score{$did}, | ||||||||||||||||||||||||||||||||||
| 435 | 1 | (unpack($p.'a*', $FN{$did}))[1]); | |||||||||||||||||||||||||||||||||
| 436 | 1 | ▶ | last unless --$maxhits; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | sub cbreak { | ||||||||||||||||||||||||||||||||
|
Subroutine
cbreak: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||
| 442 | 0 | my $mode = shift; | |||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | if ($mode eq 'on') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | open(TTYIN, "</dev/tty") || die "can't read /dev/tty: $!"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | open(TTYOUT, ">/dev/tty") || die "can't write /dev/tty: $!"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 446 | 0 | select(TTYOUT); | |||||||||||||||||||||||||||||||||
| 447 | 0 | $| = 1; | |||||||||||||||||||||||||||||||||
| 448 | 0 | select(STDOUT); | |||||||||||||||||||||||||||||||||
| 449 | 0 | $SIG{'QUIT'} = $SIG{'INT'} = 'cbreak'; | |||||||||||||||||||||||||||||||||
| 450 | 0 | system "stty", '-icanon', 'eol', "\001"; | |||||||||||||||||||||||||||||||||
| 451 | } else { | ||||||||||||||||||||||||||||||||||
| 452 | 0 | system "stty", 'icanon', 'eol', '^@'; # ascii null | |||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||
| 457 | 2 | $stopinited = 0; # perl -w | |||||||||||||||||||||||||||||||||
| 458 | 1 | ▶ | sub initstop { | ||||||||||||||||||||||||||||||||
|
Subroutine
initstop: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||
| 459 | 1 | ▶ | return if $stopinited++; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 460 | 1 | ▶ | while (<DATA>) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 461 | 461 | ▶ | next if /^\#/; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 462 | 459 | for (normalize($_)) { | |||||||||||||||||||||||||||||||||
| 463 | 393 | $stop{$_}++; | |||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||
| 468 | =head1 NAME | ||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||
| 470 | perlindex - index and query perl manual pages | ||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||
| 472 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||
| 474 | perlindex -index | ||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||
| 476 | perlindex tell me where the flowers are | ||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||
| 478 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||
| 480 | "C<perlindex -index>" generates an AnyDBM_File index which can be | ||||||||||||||||||||||||||||||||||
| 481 | searched with free text queries "C<perlindex> I<a verbose query>". | ||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||
| 483 | Each word of the query is searched in the index and a score is | ||||||||||||||||||||||||||||||||||
| 484 | generated for each document containing it. Scores for all words are | ||||||||||||||||||||||||||||||||||
| 485 | added and the documents with the highest score are printed. All words | ||||||||||||||||||||||||||||||||||
| 486 | are stemed with Porters algorithm (see L<Text::English>) before | ||||||||||||||||||||||||||||||||||
| 487 | indexing and searching happens. | ||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||
| 489 | The score is computed as: | ||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||
| 491 | $score{$document} += $tf{$word,$document}/$maxtf{$document} | ||||||||||||||||||||||||||||||||||
| 492 | * log ($N/$n{$word}); | ||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||
| 494 | where | ||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||
| 496 | =over 10 | ||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||
| 498 | =item C<$N> | ||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||
| 500 | is the number of documents in the index, | ||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||
| 502 | =item C<$n{$word}> | ||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||
| 504 | is the number of documents containing the I<word>, | ||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||
| 506 | =item C<$tf{$word,$document}> | ||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||
| 508 | is the number of occurances of I<word> in the I<document>, and | ||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||
| 510 | =item C<$maxtf{$document}> | ||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||
| 512 | is the maximum freqency of any word in I<document>. | ||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||
| 514 | =back | ||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||
| 516 | =head1 OPTIONS | ||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||
| 518 | All options may be abreviated. | ||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||
| 520 | =over 10 | ||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||
| 522 | =item B<-maxhits> maxhits | ||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||
| 524 | Maximum numer of hits to display. Default is 15. | ||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||
| 526 | =item B<-menu> | ||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||
| 528 | =item B<-nomenu> | ||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||
| 530 | Use the matches as menu for calling C<man>. Default is B<-menu>.q | ||||||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||||||
| 532 | =item B<-cbreak> | ||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||
| 534 | =item B<-nocbreak> | ||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||
| 536 | Switch to cbreak in menu mode or dont. B<-cbreak> is the default. | ||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||
| 538 | =item B<-verbose> | ||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||
| 540 | Generates additional information which query words have been not found | ||||||||||||||||||||||||||||||||||
| 541 | in the database and which words of the query are stopwords. | ||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||
| 543 | =back | ||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||
| 545 | =head1 EXAMPLE | ||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||
| 547 | perlindex foo bar | ||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||
| 549 | 1 3.735 lib/pod/perlbot.pod | ||||||||||||||||||||||||||||||||||
| 550 | 2 2.640 lib/pod/perlsec.pod | ||||||||||||||||||||||||||||||||||
| 551 | 3 2.153 lib/pod/perldata.pod | ||||||||||||||||||||||||||||||||||
| 552 | 4 1.920 lib/Symbol.pm | ||||||||||||||||||||||||||||||||||
| 553 | 5 1.802 lib/pod/perlsub.pod | ||||||||||||||||||||||||||||||||||
| 554 | 6 1.586 lib/Getopt/Long.pm | ||||||||||||||||||||||||||||||||||
| 555 | 7 1.190 lib/File/Path.pm | ||||||||||||||||||||||||||||||||||
| 556 | 8 1.042 lib/pod/perlop.pod | ||||||||||||||||||||||||||||||||||
| 557 | 9 0.857 lib/pod/perlre.pod | ||||||||||||||||||||||||||||||||||
| 558 | a 0.830 lib/Shell.pm | ||||||||||||||||||||||||||||||||||
| 559 | b 0.691 lib/strict.pm | ||||||||||||||||||||||||||||||||||
| 560 | c 0.691 lib/Carp.pm | ||||||||||||||||||||||||||||||||||
| 561 | d 0.680 lib/pod/perlpod.pod | ||||||||||||||||||||||||||||||||||
| 562 | e 0.680 lib/File/Find.pm | ||||||||||||||||||||||||||||||||||
| 563 | f 0.626 lib/pod/perlsyn.pod | ||||||||||||||||||||||||||||||||||
| 564 | Enter Number or 'q'> | ||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||
| 566 | Hitting the keys C<1> to C<f> will display the corresponding manual | ||||||||||||||||||||||||||||||||||
| 567 | page. Hitting C<q> quits. All other keys display this manual page. | ||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||
| 569 | =head1 FILES | ||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||
| 571 | The index will be generated in your man directory. Strictly speaking in | ||||||||||||||||||||||||||||||||||
| 572 | C<$Config{man1direxp}/..> | ||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||
| 574 | The following files will be generated: | ||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||
| 576 | index_fn # docid -> (max frequency, filename) | ||||||||||||||||||||||||||||||||||
| 577 | index_idf # term -> number of documents containing term | ||||||||||||||||||||||||||||||||||
| 578 | index_if # term -> (docid, frequency)* | ||||||||||||||||||||||||||||||||||
| 579 | index_seen # fn -> indexed? | ||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||
| 582 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||
| 584 | Ulrich Pfeifer E<lt>F<pfeifer@ls6.informatik.uni-dortmund.de>E<gt> | ||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||
| 586 | =cut | ||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||
| 588 | __END__ | ||||||||||||||||||||||||||||||||||