| 1 |
#!/usr/local/bin/perl |
| 2 |
|
| 3 |
use Config; |
| 4 |
use File::Basename qw(&basename &dirname); |
| 5 |
|
| 6 |
# List explicitly here the variables you want Configure to |
| 7 |
# generate. Metaconfig only looks for shell variables, so you |
| 8 |
# have to mention them as if they were shell variables, not |
| 9 |
# %Config entries. Thus you write |
| 10 |
# $startperl |
| 11 |
# to ensure Configure will look for $Config{startperl}. |
| 12 |
|
| 13 |
# This forces PL files to create target in same directory as PL file. |
| 14 |
# This is so that make depend always knows where to find PL derivatives. |
| 15 |
chdir(dirname($0)); |
| 16 |
($file = basename($0)) =~ s/\.PL$//; |
| 17 |
$file =~ s/\.pl$// |
| 18 |
if ($Config{'osname'} eq 'VMS' or |
| 19 |
$Config{'osname'} eq 'OS2'); # "case-forgiving" |
| 20 |
open OUT,">$file" or die "Can't create $file: $!"; |
| 21 |
|
| 22 |
print "Extracting $file (with variable substitutions)\n"; |
| 23 |
chmod 0775, $file; |
| 24 |
|
| 25 |
# In this section, perl variables will be expanded during extraction. |
| 26 |
# You can use $Config{...} to use Configure variables. |
| 27 |
|
| 28 |
print OUT <<"!GROK!THIS!"; |
| 29 |
$Config{'startperl'} |
| 30 |
eval 'exec perl -S \$0 "\$@"' |
| 31 |
if 0; |
| 32 |
!GROK!THIS! |
| 33 |
print OUT <<'!NO!SUBS!'; |
| 34 |
# -*- Mode: Perl -*- |
| 35 |
# Author : Ulrich Pfeifer |
| 36 |
# Created On : Mon Jan 22 13:00:41 1996 |
| 37 |
# Last Modified On: Sun Jan 6 22:26:28 2013 |
| 38 |
# Language : Perl |
| 39 |
# Update Count : 399 |
| 40 |
# Status : Unknown, Use with caution! |
| 41 |
# |
| 42 |
# (C) Copyright 1996-2005, Ulrich Pfeifer, all rights reserved. |
| 43 |
# This file is free software; you can redistribute it and/or modify it |
| 44 |
# under the same terms as Perl itself. |
| 45 |
# |
| 46 |
# |
| 47 |
# %SEEN is used to store the mtime and absolute pathes to |
| 48 |
# files which have been indexed. |
| 49 |
# |
| 50 |
# %FN $FN{'last'} greatest documentid |
| 51 |
# $FN{$did} a pair of $mtf and $filename where $mtf is the |
| •52 |
# number of occurrences of the most frequent word in |
| 53 |
# the document with number $did. |
| 54 |
# |
| 55 |
# %IDF $IDF{'*all*'} number of documents (essentially the same as |
| 56 |
# $FN{'last'}) |
| 57 |
# $IDF{$word} number of documents containing $word |
| 58 |
# |
| 59 |
# %IF $IF{$word} list of pairs ($docid,$tf) where $docid is |
| 60 |
# the number of a document containing $word $tf |
| 61 |
# |
| 62 |
use Fcntl; |
| 63 |
use less 'time'; |
| 64 |
use Getopt::Long; |
| 65 |
use File::Basename; |
| 66 |
use Text::English; |
| 67 |
use Config; |
| 68 |
|
| 69 |
# NDBM_File as LAST resort |
| 70 |
BEGIN { @AnyDBM_File::ISA = qw(DB_File GDBM_File SDBM_File ODBM_File NDBM_File) } |
| 71 |
use AnyDBM_File; |
| 72 |
|
| 73 |
!NO!SUBS! |
| 74 |
|
| 75 |
eval "\$x = pack 'w', 1;"; |
| 76 |
if ($x eq "\001") { |
| 77 |
print OUT "\$p = 'w'; # compressed int patch available\n"; |
| 78 |
} else { |
| 79 |
print OUT "\$p = 'S'; # change to 'I' for large collections\n"; |
| 80 |
} |
| 81 |
|
| 82 |
$index_dir = $Config{'man1direxp'}; |
| 83 |
$index_dir =~ s:/[^/]*$::; |
| 84 |
$index_dir = $ENV{'INDEXDIR'} if $ENV{'INDEXDIR'}; |
| •85 |
$conffile = $ENV{'CONFFILE'} || '/etc/perlindex/config'; |
| 86 |
|
| 87 |
print OUT <<"EOC"; |
| 88 |
\$nroff = \'$Config{'nroff'}\' || \'nroff\'; |
| 89 |
\$man1direxp = \'$Config{'man1direxp'}\'; |
| 90 |
\$man3direxp = \'$Config{'man3direxp'}\'; |
| 91 |
\$IDIR = \'$index_dir\'; |
| 92 |
\$prefix = \'$Config{'prefix'}\'; |
| •93 |
\$conffile = \'$conffile\'; |
| 94 |
EOC |
| 95 |
; |
| 96 |
|
| 97 |
# Use Term::ReadKey for character-at-a-time input if available. |
| 98 |
# Else use "stty cbreak" if BSD, "stty icanon" if non-BSD. |
| 99 |
if (eval 'require Term::ReadKey') { |
| 100 |
print OUT "use Term::ReadKey;\n"; |
| 101 |
$BSD_STYLE= -1; |
| 102 |
} elsif ($Config{'d_bsd'}) { |
| 103 |
$BSD_STYLE= 1; |
| 104 |
} else { |
| 105 |
$BSD_STYLE= 0; |
| 106 |
} |
| 107 |
|
| 108 |
# # Let's look for a stemmer |
| 109 |
# eval "use Text::English;"; |
| 110 |
# unless ($@) { |
| 111 |
# $stemmer = \&Text::English::stem; |
| 112 |
# } else { |
| 113 |
# eval "require 'Stem.pl';"; |
| 114 |
# unless ($@) { |
| 115 |
# $stemmer = \&stem; |
| 116 |
# } |
| 117 |
# } |
| 118 |
|
| 119 |
# In the following, perl variables are not expanded during extraction. |
| 120 |
|
| 121 |
print OUT <<'!NO!SUBS!'; |
| 122 |
|
| 123 |
$pager= $Config{'pager'}; |
| 124 |
if ($Config{'osname'} eq 'hpux') { |
| 125 |
$pager= "col | $pager"; |
| 126 |
} |
| 127 |
if (exists $ENV{PAGER}) { |
| 128 |
$pager=$ENV{PAGER} |
| 129 |
} |
| 130 |
$stemmer = \&Text::English::stem; |
| 131 |
$debug = 0; |
| 132 |
$opt_index = ''; # make perl -w happy |
| 133 |
$opt_menu = 1; |
| 134 |
$opt_maxhits = 20; |
| 135 |
$opt_cbreak = 1; |
| 136 |
&GetOptions( |
| 137 |
'index', |
| 138 |
'cbreak!', |
| 139 |
'maxhits=i', |
| 140 |
'menu!', |
| 141 |
'verbose', |
| 142 |
'dict:i', |
| 143 |
'idir=s', |
| •144 |
'conf=s', |
| 145 |
) || die "Usage: $0 [-index] [words ...]\n"; |
| 146 |
|
| •147 |
if (defined $opt_conf) { |
| 148 |
$conffile = $opt_conf; |
| 149 |
} |
| 150 |
|
| 151 |
if (defined $opt_idir) { |
| 152 |
$IDIR = $opt_idir; # avoid to many changes below. |
| 153 |
} |
| 154 |
|
| 155 |
if (defined $opt_dict) { |
| 156 |
$opt_dict ||= 100; |
| 157 |
} |
| 158 |
|
| 159 |
my $GC_REQUIRED = 0; # garbage collect required? Global variable. |
| 160 |
|
| 161 |
if ($opt_index) { |
| 162 |
|
| 163 |
# check whether we can use Pod::Text to extract POD |
| 164 |
$PodText = 0; |
| 165 |
eval { |
| 166 |
require Pod::Text; |
| 167 |
print "Using Pod::Text\n"; |
| 168 |
$PodText = 1; |
| 169 |
}; |
| 170 |
|
| 171 |
|
| 172 |
$IoScalar = 0; |
| 173 |
eval { |
| 174 |
require IO::Scalar; |
| 175 |
print "Using IO::Scalar\n"; |
| 176 |
$IoScalar = 1; |
| 177 |
}; |
| 178 |
|
| 179 |
&initstop; |
| 180 |
|
| 181 |
tie (%IF, AnyDBM_File, "$IDIR/index_if", O_CREAT|O_RDWR, 0644) |
| 182 |
or die "Could not tie $IDIR/index_if: $!\n"; |
| 183 |
tie (%IDF, AnyDBM_File, "$IDIR/index_idf", O_CREAT|O_RDWR, 0644) |
| 184 |
or die "Could not tie $IDIR/index_idf: $!\n"; |
| 185 |
tie (%SEEN, AnyDBM_File, "$IDIR/index_seen", O_CREAT|O_RDWR, 0644) |
| 186 |
or die "Could not tie $IDIR/index_seen: $!\n"; |
| 187 |
tie (%FN, AnyDBM_File, "$IDIR/index_fn", O_CREAT|O_RDWR, 0644) |
| 188 |
or die "Could not tie $IDIR/index_fn: $!\n"; |
| 189 |
|
| 190 |
require File::Find; |
| 191 |
|
| •192 |
open (CONFIG, "<$conffile") || die "Can't open config file $conffile: $!"; |
| 193 |
my @config_perllib = <CONFIG>; |
| 194 |
chomp @config_perllib; |
| 195 |
|
| 196 |
unless (@ARGV) { # breaks compatibility :-( |
| 197 |
my %seen; |
| 198 |
my @perllib = grep(length && -d && !$seen{$_}++, |
| 199 |
@Config{qw(installprivlib installarchlib installsitelib installvendorlib installscript installsitearch)}); |
| •200 |
push @perllib, @config_perllib; |
| 201 |
|
| 202 |
for $dir (@perllib) { |
| 203 |
print "Scanning $dir ... \n"; |
| 204 |
if (-l $dir) { # debian symlinks installarchlib but we do not want to follow links in general |
| 205 |
my $target = readlink $dir; |
| 206 |
$dir =~ s:[^/]+$:$target:; |
| 207 |
} |
| 208 |
File::Find::find( \&wanted, $dir ); |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
for $name (@ARGV) { |
| 213 |
add_to_index($name); |
| 214 |
} |
| 215 |
# Check if all (previuosly) indexed files are still available |
| 216 |
# This may take some time. |
| 217 |
warn "Validating index ...\n"; |
| 218 |
while (my ($fns, $value) = each %SEEN) { |
| 219 |
my $path = $fns; $path = $prefix.'/'.$path unless $path =~ m:^/:; |
| 220 |
unless (-f $path) { |
| 221 |
my ($mtime, $did) = unpack "$p$p", $value; |
| 222 |
# mark document as deleted |
| 223 |
warn "Marking document $did ($fns) as deleted\n"; |
| 224 |
delete $FN{$did}; |
| 225 |
delete $SEEN{$fns}; |
| 226 |
$GC_REQUIRED++; |
| 227 |
} |
| 228 |
} |
| 229 |
if ($GC_REQUIRED) { |
| 230 |
print STDERR "Garbage collecting\r"; |
| 231 |
# garbage collection, this is awfully slow |
| 232 |
my $progress = 0; |
| 233 |
my $words = keys %IF; |
| 234 |
my %if_new; |
| 235 |
tie (%if_new, AnyDBM_File, "$IDIR/index_if.new", O_CREAT|O_RDWR, 0644) |
| 236 |
or die "Could not tie $IDIR/index_if: $!\n"; |
| 237 |
while (my ($word,$list) = each %IF) { |
| 238 |
print STDERR "Garbage collecting ".(++$progress)."/".$words."\r"; |
| 239 |
my %post = unpack($p.'*',$list); |
| 240 |
|
| 241 |
#delete $IF{$word}; |
| 242 |
$IDF{$word} = 0; |
| 243 |
while (my ($did,$tf) = each %post) { |
| 244 |
if (exists $FN{$did}) { |
| 245 |
$if_new{$word} = '' unless defined $if{$word}; # perl -w |
| 246 |
$if_new{$word} .= pack($p.$p, $did, $tf); |
| 247 |
$IDF{$word}++; |
| 248 |
} |
| 249 |
} |
| 250 |
} |
| 251 |
untie %if_new; |
| 252 |
untie %IF; |
| 253 |
opendir(IDX, $IDIR) or die "Could not read dir '$IDIR': $!"; |
| 254 |
for $file (readdir DIR) { |
| 255 |
my $old = $file; |
| 256 |
if ($file =~ s/^index_if\.new/index_if/) { |
| 257 |
rename "$IDIR/$old", "$IDIR/$file"; |
| 258 |
} |
| 259 |
} |
| 260 |
print STDERR "\rGarbage collecting ... done"; |
| 261 |
} |
| 262 |
untie %IF unless $GC_REQUIRED; |
| 263 |
untie %IDF; |
| 264 |
untie %FN; |
| 265 |
untie %SEEN; |
| 266 |
} elsif ($opt_dict) { |
| 267 |
tie (%IDF, AnyDBM_File, "$IDIR/index_idf", O_RDONLY, 0644) |
| 268 |
or die "Could not tie $IDIR/index_idf: $!\n". |
| 269 |
"Did you run '$0 -index'?\n"; |
| 270 |
while (($key,$val) = each %IDF) { |
| 271 |
printf "%-20s %d\n", $key, $val if $val >= $opt_dict; |
| 272 |
} |
| 273 |
untie %IDF; |
| 274 |
} else { |
| 275 |
tie (%IF, AnyDBM_File, "$IDIR/index_if", O_RDONLY, 0644) |
| 276 |
or die "Could not tie $IDIR/index_if: $!\n". |
| 277 |
"Did you run '$0 -index'?\n"; |
| 278 |
tie (%IDF, AnyDBM_File, "$IDIR/index_idf", O_RDONLY, 0644) |
| 279 |
or die "Could not tie $IDIR/index_idf: $!\n"; |
| 280 |
tie (%FN, AnyDBM_File, "$IDIR/index_fn", O_RDONLY, 0644) |
| 281 |
or die "Could not tie $IDIR/index_fn: $!\n"; |
| 282 |
&search(@ARGV); |
| 283 |
untie %IF; |
| 284 |
untie %IDF; |
| 285 |
untie %FN; |
| 286 |
untie %SEEN; |
| 287 |
} |
| 288 |
|
| 289 |
sub wanted { |
| 290 |
my $fns = $File::Find::name; |
| 291 |
|
| 292 |
if ($File::Find::name eq $man3direxp) { |
| 293 |
$File::Find::prune = 1; |
| 294 |
} |
| 295 |
if (-f $_ and $File::Find::name =~ /man|bin|\.(pod|pm|txt)$/) { |
| 296 |
add_to_index($File::Find::name); |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
sub index { |
| 301 |
my $fn = shift; |
| 302 |
my $fns = shift; |
| 303 |
my $did = shift; |
| 304 |
my %tf; |
| 305 |
my $maxtf = 0; |
| 306 |
|
| 307 |
if ($fn =~ /\.txt$/) { |
| 308 |
open (IN, "<$fn") || warn "Could not open $fn: $!\n", return (0); |
| 309 |
while ($line = <IN>) { |
| 310 |
warn "=> $line\n" if $debug; |
| 311 |
for $word (&normalize($line)) { |
| 312 |
next if $stop{$word}; |
| 313 |
$tf{$word}++; |
| 314 |
} |
| 315 |
} |
| 316 |
close IN; |
| 317 |
} elsif($PodText and -T $fn) { |
| 318 |
my $result; |
| 319 |
my $parser = Pod::Text->new(sentence => 0, width => 78); |
| 320 |
if ($IoScalar) { |
| 321 |
my $tmpfile = new IO::Scalar; |
| 322 |
open(IN,"<$fn"); |
| 323 |
$parser->parse_from_filehandle(*IN, $tmpfile); |
| 324 |
warn "===> $fn, $tmpfile" if $debug; |
| 325 |
#for my $line (split /\n/, $tmpfile) { |
| 326 |
while ($tmpfile =~ s/^(.*\n)//) { |
| 327 |
warn "=> $1\n" if $debug; |
| 328 |
for $word (&normalize($1)) { |
| 329 |
next if $stop{$word}; |
| 330 |
$tf{$word}++; |
| 331 |
} |
| 332 |
} |
| 333 |
close IN; |
| 334 |
} else { |
| 335 |
my $tmpfile = "$IDIR/tmppod.txt"; |
| 336 |
$parser->parse_from_file($fn, $tmpfile); |
| 337 |
open (IN, "<$tmpfile") || warn "Could not open $fn: $!\n", return (0); |
| 338 |
while ($line = <IN>) { |
| 339 |
warn "=> $line\n" if $debug; |
| 340 |
for $word (&normalize($line)) { |
| 341 |
next if $stop{$word}; |
| 342 |
$tf{$word}++; |
| 343 |
} |
| 344 |
} |
| 345 |
close IN; |
| 346 |
unlink $tmpfile; |
| 347 |
} |
| 348 |
} else { |
| 349 |
# no Pod::Text found |
| 350 |
open(IN, "<$fn") || warn "Could not open $fn: $!\n", return (0); |
| 351 |
while ($line = <IN>) { |
| 352 |
warn "=> $line\n" if $debug; |
| 353 |
if ($line =~ /^=head/) { |
| 354 |
$pod = 1; |
| 355 |
} elsif ($line =~ /^=cut/){ |
| 356 |
$pod = 0; |
| 357 |
} else { |
| 358 |
next unless $pod; |
| 359 |
} |
| 360 |
for $word (&normalize($line)) { |
| 361 |
next if $stop{$word}; |
| 362 |
$tf{$word}++; |
| 363 |
} |
| 364 |
} |
| 365 |
close(IN); |
| 366 |
} |
| 367 |
for $tf (values %tf) { |
| 368 |
$maxtf = $tf if $tf > $maxtf; |
| 369 |
} |
| 370 |
for $word (keys %tf) { |
| 371 |
$IDF{$word}++; |
| 372 |
$IF{$word} = '' unless defined $IF{$word}; # perl -w |
| 373 |
$IF{$word} .= pack($p.$p, $did, $tf{$word}); |
| 374 |
} |
| 375 |
$FN{$did} = pack($p, $maxtf).$fns; |
| 376 |
print STDERR "$fns\n"; |
| 377 |
1; |
| 378 |
} |
| 379 |
|
| 380 |
sub add_to_index { |
| 381 |
my ($name) = @_; |
| 382 |
my $fns = $name; $fns =~ s:\Q$prefix/::; |
| 383 |
|
| 384 |
if (exists $SEEN{$fns}) { |
| 385 |
my ($mtime, $did) = unpack "$p$p", $SEEN{$fns}; |
| 386 |
if ((stat $name)[9] > $mtime) { |
| 387 |
# mark document as deleted |
| 388 |
delete $FN{$did}; |
| 389 |
warn "Marking document $did ($name) as deleted\n"; |
| 390 |
$GC_REQUIRED++; |
| 391 |
} else { |
| 392 |
# index up to date |
| 393 |
next; |
| 394 |
} |
| 395 |
} |
| 396 |
next unless -f $name; |
| 397 |
if ($name !~ /(~|,v)$/) { |
| 398 |
$did = $FN{'last'}++; |
| 399 |
if (&index($name, $fns, $did)) { |
| 400 |
my ($mtime) = (stat $name)[9]; |
| 401 |
$SEEN{$fns} = pack "$p$p", (stat $name)[9], $did; |
| 402 |
} |
| 403 |
} |
| 404 |
} |
| 405 |
|
| 406 |
sub normalize { |
| 407 |
my $line = join ' ', @_; |
| 408 |
my @result; |
| 409 |
|
| 410 |
$line =~ tr/A-Z/a-z/; |
| 411 |
$line =~ tr/a-z0-9_/ /cs; |
| 412 |
for $word (split / /, $line ) { |
| 413 |
$word =~ s/^\d+//; |
| 414 |
next unless length($word) > 2; |
| 415 |
if ($stemmer) { |
| 416 |
push @result, &$stemmer($word); |
| 417 |
} else { |
| 418 |
push @result, $word; |
| 419 |
} |
| 420 |
} |
| 421 |
@result; |
| 422 |
} |
| 423 |
|
| 424 |
sub search { |
| 425 |
my %score; |
| 426 |
my $maxhits = $opt_maxhits; |
| 427 |
my (@unknown, @stop); |
| 428 |
|
| 429 |
&initstop if $opt_verbose; |
| 430 |
for $word (normalize(@_)) { |
| 431 |
unless ($IF{$word}) { |
| 432 |
if ($stop{$word}) { |
| 433 |
push @stop, $word; |
| 434 |
} else { |
| 435 |
push @unknown, $word; |
| 436 |
} |
| 437 |
next; |
| 438 |
} |
| 439 |
my %post = unpack($p.'*',$IF{$word}); |
| 440 |
my $idf = log($FN{'last'}/$IDF{$word}); |
| 441 |
for $did (keys %post) { |
| 442 |
# skip deleted documents |
| 443 |
next unless exists $FN{$did}; |
| 444 |
my ($maxtf) = unpack($p, $FN{$did}); |
| 445 |
$score{$did} = 0 unless defined $score{$did}; # perl -w |
| 446 |
$score{$did} += $post{$did} / $maxtf * $idf; |
| 447 |
} |
| 448 |
} |
| 449 |
if ($opt_verbose) { |
| 450 |
print "Unkown: @unknown\n" if @unknown; |
| 451 |
print "Ingnore: @stop\n" if @stop; |
| 452 |
} |
| 453 |
if ($opt_menu) { |
| 454 |
my @menu; |
| 455 |
my $answer = ''; |
| 456 |
my $no = 0; |
| 457 |
my @s = ('1' .. '9', 'a' .. 'z'); |
| 458 |
my %s; |
| 459 |
|
| 460 |
for $did (sort {$score{$b} <=> $score{$a}} keys %score) { |
| 461 |
my ($mtf, $path) = unpack($p.'a*', $FN{$did}); |
| 462 |
my $s = $s[$no]; |
| 463 |
push @menu, sprintf "%s %6.3f %s\n", $s, $score{$did}, $path; |
| 464 |
$s{$s} = ++$no; |
| 465 |
last unless --$maxhits; |
| 466 |
} |
| 467 |
&cbreak('on') if $opt_cbreak; |
| 468 |
while (1) { |
| 469 |
print @menu; |
| 470 |
print "\nEnter Number or 'q'> "; |
| 471 |
if ($opt_cbreak) { |
| 472 |
read(TTYIN,$answer,1); |
| 473 |
print "\n"; |
| 474 |
} else { |
| 475 |
$answer = <STDIN>; |
| 476 |
} |
| 477 |
last if $answer =~ /^q/i; |
| 478 |
$answer = ($s{substr($answer,0,1)})-1; |
| 479 |
if ($answer >= 0 and $answer <= $#menu) { |
| 480 |
my $selection = $menu[$answer]; chomp($selection); |
| 481 |
my ($no, $score, $path) = split ' ', $selection, 3; |
| 482 |
$path = $prefix.'/'.$path unless $path =~ m:^/:; |
| 483 |
|
| 484 |
if ($path =~ /\.txt$/) { |
| 485 |
my $pdf = $path; $pdf =~ s:pages/(\S+)_(\d+)\.txt$:$1.pdf:; |
| 486 |
my $page = $2+0; |
| 487 |
my $endp = $page+2; |
| 488 |
my $tmp = "/tmp/perlinde$$.pdf"; |
| 489 |
|
| 490 |
if (-f $pdf) { |
| 491 |
print "pdftk A=$pdf cat $page-$endp output $tmp\n"; |
| 492 |
system "pdftk", "A=".$pdf, 'cat', "$page-$endp", 'output', $tmp and |
| 493 |
system "pdftk", "A=".$pdf, 'cat', "$page-end", 'output', $tmp; |
| 494 |
system "acroread", $tmp; |
| 495 |
unlink $tmp; |
| 496 |
} else { |
| 497 |
print STDERR "$pager '$path'\n"; |
| 498 |
system $pager, $path; |
| 499 |
} |
| 500 |
} elsif ($selection =~ m:/man:) { |
| 501 |
my ($page, $sect) = |
| 502 |
($selection =~ m:([^/]*)\.(.{1,3})$:); |
| 503 |
print STDERR "Running man $sect $page\n"; |
| 504 |
system 'man', $sect, $page; |
| 505 |
} else { |
| 506 |
print STDERR "Running pod2man $path\n"; |
| 507 |
system "pod2man --official $path | $nroff -man | $pager"; |
| 508 |
} |
| 509 |
} else { |
| 510 |
my $path = $prefix."/bin/perlindex"; |
| 511 |
system "pod2man --official $path | $nroff -man | $pager"; |
| 512 |
} |
| 513 |
} |
| 514 |
&cbreak('off') if $opt_cbreak; |
| 515 |
} else { |
| 516 |
for $did (sort {$score{$b} <=> $score{$a}} keys %score) { |
| 517 |
printf("%6.3f %s\n", $score{$did}, |
| 518 |
(unpack($p.'a*', $FN{$did}))[1]); |
| 519 |
last unless --$maxhits; |
| 520 |
} |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
sub cbreak { |
| 525 |
my $mode = shift; |
| 526 |
if ($mode eq 'on') { |
| 527 |
open(TTYIN, "</dev/tty") || die "can't read /dev/tty: $!"; |
| 528 |
open(TTYOUT, ">/dev/tty") || die "can't write /dev/tty: $!"; |
| 529 |
select(TTYOUT); |
| 530 |
$| = 1; |
| 531 |
select(STDOUT); |
| 532 |
$SIG{'QUIT'} = $SIG{'INT'} = 'cbreak'; |
| 533 |
!NO!SUBS! |
| 534 |
; |
| 535 |
|
| 536 |
if ($BSD_STYLE == -1) { |
| 537 |
print OUT "\tReadMode 3; # Set cbreak mode\n"; |
| 538 |
} elsif ($BSD_STYLE) { |
| 539 |
print OUT "\tsystem \"stty cbreak </dev/tty >/dev/tty 2>&1\";\n"; |
| 540 |
#print OUT "\tsystem \"stty cbreak echo </dev/tty >/dev/tty 2>&1\";\n"; |
| 541 |
} else { |
| 542 |
print OUT "\tsystem \"stty\", '-icanon', 'eol', \"\\001\";\n"; |
| 543 |
} |
| 544 |
print OUT " } else {\n"; |
| 545 |
if ($BSD_STYLE == -1) { |
| 546 |
print OUT "\tReadMode 0; # Restore non-cbreak mode\n"; |
| 547 |
} elsif ($BSD_STYLE) { |
| 548 |
print OUT "\tsystem \"stty -cbreak </dev/tty >/dev/tty 2>&1\";\n"; |
| 549 |
#print OUT "\tsystem \"stty -cbreak echo </dev/tty >/dev/tty 2>&1\";\n"; |
| 550 |
} else { |
| 551 |
print OUT "\tsystem \"stty\", 'icanon', 'eol', '^\@'; # ascii null\n"; |
| 552 |
} |
| 553 |
|
| 554 |
print OUT <<'!NO!SUBS!'; |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
$stopinited = 0; # perl -w |
| 560 |
sub initstop { |
| 561 |
return if $stopinited++; |
| 562 |
while (<DATA>) { |
| 563 |
next if /^\#/; |
| 564 |
for (normalize($_)) { |
| 565 |
$stop{$_}++; |
| 566 |
} |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
=head1 NAME |
| 571 |
|
| 572 |
perlindex - index and query perl manual pages |
| 573 |
|
| 574 |
=head1 SYNOPSIS |
| 575 |
|
| 576 |
perlindex -index |
| 577 |
|
| 578 |
perlindex tell me where the flowers are |
| 579 |
|
| 580 |
=head1 DESCRIPTION |
| 581 |
|
| 582 |
"C<perlindex -index>" generates an AnyDBM_File index which can be |
| 583 |
searched with free text queries "C<perlindex> I<a verbose query>". |
| 584 |
|
| 585 |
Each word of the query is searched in the index and a score is |
| 586 |
generated for each document containing it. Scores for all words are |
| 587 |
added and the documents with the highest score are printed. All words |
| 588 |
are stemed with Porters algorithm (see L<Text::English>) before |
| 589 |
indexing and searching happens. |
| 590 |
|
| 591 |
The score is computed as: |
| 592 |
|
| 593 |
$score{$document} += $tf{$word,$document}/$maxtf{$document} |
| 594 |
* log ($N/$n{$word}); |
| 595 |
|
| 596 |
where |
| 597 |
|
| 598 |
=over 10 |
| 599 |
|
| 600 |
=item C<$N> |
| 601 |
|
| 602 |
is the number of documents in the index, |
| 603 |
|
| 604 |
=item C<$n{$word}> |
| 605 |
|
| 606 |
is the number of documents containing the I<word>, |
| 607 |
|
| 608 |
=item C<$tf{$word,$document}> |
| 609 |
|
| •610 |
is the number of occurrences of I<word> in the I<document>, and |
| 611 |
|
| 612 |
=item C<$maxtf{$document}> |
| 613 |
|
| •614 |
is the maximum frequency of any word in I<document>. |
| 615 |
|
| 616 |
=back |
| 617 |
|
| 618 |
=head1 OPTIONS |
| 619 |
|
| •620 |
All options may be abbreviated. |
| 621 |
|
| 622 |
=over 10 |
| 623 |
|
| 624 |
=item B<-maxhits> maxhits |
| 625 |
|
| 626 |
Maximum numer of hits to display. Default is 15. |
| 627 |
|
| 628 |
=item B<-menu> |
| 629 |
|
| 630 |
=item B<-nomenu> |
| 631 |
|
| 632 |
Use the matches as menu for calling C<man>. Default is B<-menu>.q |
| 633 |
|
| 634 |
=item B<-cbreak> |
| 635 |
|
| 636 |
=item B<-nocbreak> |
| 637 |
|
| •638 |
Switch to cbreak in menu mode or don't. B<-cbreak> is the default. |
| 639 |
|
| 640 |
=item B<-verbose> |
| 641 |
|
| 642 |
Generates additional information which query words have been not found |
| 643 |
in the database and which words of the query are stopwords. |
| 644 |
|
| •645 |
=item B<-conf> |
| 646 |
|
| 647 |
!NO!SUBS! |
| 648 |
|
| 649 |
print OUT "Use another config than the default config ($conffile).\n"; |
| 650 |
|
| 651 |
print OUT <<'!NO!SUBS!'; |
| 652 |
|
| 653 |
=back |
| 654 |
|
| 655 |
=head1 EXAMPLE |
| 656 |
|
| 657 |
perlindex foo bar |
| 658 |
|
| 659 |
1 3.735 lib/pod/perlbot.pod |
| 660 |
2 2.640 lib/pod/perlsec.pod |
| 661 |
3 2.153 lib/pod/perldata.pod |
| 662 |
4 1.920 lib/Symbol.pm |
| 663 |
5 1.802 lib/pod/perlsub.pod |
| 664 |
6 1.586 lib/Getopt/Long.pm |
| 665 |
7 1.190 lib/File/Path.pm |
| 666 |
8 1.042 lib/pod/perlop.pod |
| 667 |
9 0.857 lib/pod/perlre.pod |
| 668 |
a 0.830 lib/Shell.pm |
| 669 |
b 0.691 lib/strict.pm |
| 670 |
c 0.691 lib/Carp.pm |
| 671 |
d 0.680 lib/pod/perlpod.pod |
| 672 |
e 0.680 lib/File/Find.pm |
| 673 |
f 0.626 lib/pod/perlsyn.pod |
| 674 |
Enter Number or 'q'> |
| 675 |
|
| 676 |
Hitting the keys C<1> to C<f> will display the corresponding manual |
| 677 |
page. Hitting C<q> quits. All other keys display this manual page. |
| 678 |
|
| 679 |
=head1 FILES |
| 680 |
|
| 681 |
The index will be generated in your man directory. Strictly speaking in |
| 682 |
C<$Config{man1direxp}/..> |
| 683 |
|
| 684 |
The following files will be generated: |
| 685 |
|
| 686 |
index_fn # docid -> (max frequency, filename) |
| 687 |
index_idf # term -> number of documents containing term |
| 688 |
index_if # term -> (docid, frequency)* |
| 689 |
index_seen # fn -> indexed? |
| 690 |
|
| 691 |
|
| 692 |
=head1 AUTHOR |
| 693 |
|
| 694 |
Ulrich Pfeifer E<lt>F<[email protected]>E<gt> |
| 695 |
|
| 696 |
=cut |
| 697 |
|
| 698 |
__END__ |
| 699 |
# freeWAIS-sf stopwords |
| 700 |
a |
| 701 |
about |
| 702 |
above |
| 703 |
according |
| 704 |
across |
| 705 |
actually |
| 706 |
adj |
| 707 |
after |
| 708 |
afterwards |
| 709 |
again |
| 710 |
against |
| 711 |
all |
| 712 |
almost |
| 713 |
alone |
| 714 |
along |
| 715 |
already |
| 716 |
also |
| 717 |
although |
| 718 |
always |
| 719 |
among |
| 720 |
amongst |
| 721 |
an |
| 722 |
and |
| 723 |
another |
| 724 |
any |
| 725 |
anyhow |
| 726 |
anyone |
| 727 |
anything |
| 728 |
anywhere |
| 729 |
are |
| 730 |
aren't |
| 731 |
around |
| 732 |
as |
| 733 |
at |
| 734 |
b |
| 735 |
be |
| 736 |
became |
| 737 |
because |
| 738 |
become |
| 739 |
becomes |
| 740 |
becoming |
| 741 |
been |
| 742 |
before |
| 743 |
beforehand |
| 744 |
begin |
| 745 |
beginning |
| 746 |
behind |
| 747 |
being |
| 748 |
below |
| 749 |
beside |
| 750 |
besides |
| 751 |
between |
| 752 |
beyond |
| 753 |
billion |
| 754 |
both |
| 755 |
but |
| 756 |
by |
| 757 |
c |
| 758 |
can |
| 759 |
can't |
| 760 |
cannot |
| 761 |
caption |
| 762 |
co |
| 763 |
co. |
| 764 |
could |
| 765 |
couldn't |
| 766 |
d |
| 767 |
did |
| 768 |
didn't |
| 769 |
do |
| 770 |
does |
| 771 |
doesn't |
| 772 |
don't |
| 773 |
down |
| 774 |
during |
| 775 |
e |
| 776 |
each |
| 777 |
eg |
| 778 |
eight |
| 779 |
eighty |
| 780 |
either |
| 781 |
else |
| 782 |
elsewhere |
| 783 |
end |
| 784 |
ending |
| 785 |
enough |
| 786 |
etc |
| 787 |
even |
| 788 |
ever |
| 789 |
every |
| 790 |
everyone |
| 791 |
everything |
| 792 |
everywhere |
| 793 |
except |
| 794 |
f |
| 795 |
few |
| 796 |
fifty |
| 797 |
first |
| 798 |
five |
| 799 |
vfor |
| 800 |
former |
| 801 |
formerly |
| 802 |
forty |
| 803 |
found " |
| 804 |
four |
| 805 |
from |
| 806 |
further |
| 807 |
g |
| 808 |
h |
| 809 |
had |
| 810 |
has |
| 811 |
hasn't |
| 812 |
have |
| 813 |
haven't |
| 814 |
he |
| 815 |
he'd |
| 816 |
he'll |
| 817 |
he's |
| 818 |
hence |
| 819 |
her |
| 820 |
here |
| 821 |
here's |
| 822 |
hereafter |
| 823 |
hereby |
| 824 |
herein |
| 825 |
hereupon |
| 826 |
hers |
| 827 |
herself |
| 828 |
him |
| 829 |
himself |
| 830 |
his |
| 831 |
how |
| 832 |
however |
| 833 |
hundred |
| 834 |
i |
| 835 |
i'd |
| 836 |
i'll |
| 837 |
i'm |
| 838 |
i've |
| 839 |
ie |
| 840 |
if |
| 841 |
in |
| 842 |
inc. |
| 843 |
indeed |
| 844 |
instead |
| 845 |
into |
| 846 |
is |
| 847 |
isn't |
| 848 |
it |
| 849 |
it's |
| 850 |
its |
| 851 |
itself |
| 852 |
j |
| 853 |
k |
| 854 |
l |
| 855 |
last |
| 856 |
later |
| 857 |
latter |
| 858 |
latterly |
| 859 |
least |
| 860 |
less |
| 861 |
let |
| 862 |
let's |
| 863 |
like |
| 864 |
likely |
| 865 |
ltd |
| 866 |
m |
| 867 |
made |
| 868 |
make |
| 869 |
makes |
| 870 |
many |
| 871 |
maybe |
| 872 |
me |
| 873 |
meantime |
| 874 |
meanwhile |
| 875 |
might |
| 876 |
million |
| 877 |
miss |
| 878 |
more |
| 879 |
moreover |
| 880 |
most |
| 881 |
mostly |
| 882 |
mr |
| 883 |
mrs |
| 884 |
much |
| 885 |
must |
| 886 |
my |
| 887 |
myself |
| 888 |
n |
| 889 |
namely |
| 890 |
neither |
| 891 |
never |
| 892 |
nevertheless |
| 893 |
next |
| 894 |
nine |
| 895 |
ninety |
| 896 |
no |
| 897 |
nobody |
| 898 |
none |
| 899 |
nonetheless |
| 900 |
noone |
| 901 |
nor |
| 902 |
not |
| 903 |
nothing |
| 904 |
now |
| 905 |
nowhere |
| 906 |
o |
| 907 |
of |
| 908 |
off |
| 909 |
often |
| 910 |
on |
| 911 |
once |
| 912 |
one |
| 913 |
one's |
| 914 |
only |
| 915 |
onto |
| 916 |
or |
| 917 |
other |
| 918 |
others |
| 919 |
otherwise |
| 920 |
our |
| 921 |
ours |
| 922 |
ourselves |
| 923 |
out |
| 924 |
over |
| 925 |
overall |
| 926 |
own |
| 927 |
p |
| 928 |
per |
| 929 |
perhaps |
| 930 |
q |
| 931 |
r |
| 932 |
rather |
| 933 |
recent |
| 934 |
recently |
| 935 |
s |
| 936 |
same |
| 937 |
seem |
| 938 |
seemed |
| 939 |
seeming |
| 940 |
seems |
| 941 |
seven |
| 942 |
seventy |
| 943 |
several |
| 944 |
she |
| 945 |
she'd |
| 946 |
she'll |
| 947 |
she's |
| 948 |
should |
| 949 |
shouldn't |
| 950 |
since |
| 951 |
six |
| 952 |
sixty |
| 953 |
so |
| 954 |
some |
| 955 |
somehow |
| 956 |
someone |
| 957 |
something |
| 958 |
sometime |
| 959 |
sometimes |
| 960 |
somewhere |
| 961 |
still |
| 962 |
stop |
| 963 |
such |
| 964 |
t |
| 965 |
taking |
| 966 |
ten |
| 967 |
than |
| 968 |
that |
| 969 |
that'll |
| 970 |
that's |
| 971 |
that've |
| 972 |
the |
| 973 |
their |
| 974 |
them |
| 975 |
themselves |
| 976 |
then |
| 977 |
thence |
| 978 |
there |
| 979 |
there'd |
| 980 |
there'll |
| 981 |
there're |
| 982 |
there's |
| 983 |
there've |
| 984 |
thereafter |
| 985 |
thereby |
| 986 |
therefore |
| 987 |
therein |
| 988 |
thereupon |
| 989 |
these |
| 990 |
they |
| 991 |
they'd |
| 992 |
they'll |
| 993 |
they're |
| 994 |
they've |
| 995 |
thirty |
| 996 |
this |
| 997 |
those |
| 998 |
though |
| 999 |
thousand |
| 1000 |
three |
| 1001 |
through |
| 1002 |
throughout |
| 1003 |
thru |
| 1004 |
thus |
| 1005 |
to |
| 1006 |
together |
| 1007 |
too |
| 1008 |
toward |
| 1009 |
towards |
| 1010 |
trillion |
| 1011 |
twenty |
| 1012 |
two |
| 1013 |
u |
| 1014 |
under |
| 1015 |
unless |
| 1016 |
unlike |
| 1017 |
unlikely |
| 1018 |
until |
| 1019 |
up |
| 1020 |
upon |
| 1021 |
us |
| 1022 |
used |
| 1023 |
using |
| 1024 |
v |
| 1025 |
very |
| 1026 |
via |
| 1027 |
w |
| 1028 |
was |
| 1029 |
wasn't |
| 1030 |
we |
| 1031 |
we'd |
| 1032 |
we'll |
| 1033 |
we're |
| 1034 |
we've |
| 1035 |
well |
| 1036 |
were |
| 1037 |
weren't |
| 1038 |
what |
| 1039 |
what'll |
| 1040 |
what's |
| 1041 |
what've |
| 1042 |
whatever |
| 1043 |
when |
| 1044 |
whence |
| 1045 |
whenever |
| 1046 |
where |
| 1047 |
where's |
| 1048 |
whereafter |
| 1049 |
whereas |
| 1050 |
whereby |
| 1051 |
wherein |
| 1052 |
whereupon |
| 1053 |
wherever |
| 1054 |
whether |
| 1055 |
which |
| 1056 |
while |
| 1057 |
whither |
| 1058 |
who |
| 1059 |
who'd |
| 1060 |
who'll |
| 1061 |
who's |
| 1062 |
whoever |
| 1063 |
whole |
| 1064 |
whom |
| 1065 |
whomever |
| 1066 |
whose |
| 1067 |
why |
| 1068 |
will |
| 1069 |
with |
| 1070 |
within |
| 1071 |
without |
| 1072 |
won't |
| 1073 |
would |
| 1074 |
wouldn't |
| 1075 |
x |
| 1076 |
y |
| 1077 |
yes |
| 1078 |
yet |
| 1079 |
you |
| 1080 |
you'd |
| 1081 |
you'll |
| 1082 |
you're |
| 1083 |
you've |
| 1084 |
your |
| 1085 |
yours |
| 1086 |
yourself |
| 1087 |
yourselves |
| 1088 |
z |
| 1089 |
# occuring in more than 100 files |
| 1090 |
acc |
| 1091 |
accent |
| 1092 |
accents |
| 1093 |
and |
| 1094 |
are |
| 1095 |
bell |
| 1096 |
can |
| 1097 |
character |
| 1098 |
corrections |
| 1099 |
crt |
| 1100 |
daisy |
| 1101 |
dash |
| 1102 |
date |
| 1103 |
defined |
| 1104 |
definitions |
| 1105 |
description |
| 1106 |
devices |
| 1107 |
diablo |
| 1108 |
dummy |
| 1109 |
factors |
| 1110 |
following |
| 1111 |
font |
| 1112 |
for |
| 1113 |
from |
| 1114 |
fudge |
| 1115 |
give |
| 1116 |
have |
| 1117 |
header |
| 1118 |
holds |
| 1119 |
log |
| 1120 |
logo |
| 1121 |
low |
| 1122 |
lpr |
| 1123 |
mark |
| 1124 |
name |
| 1125 |
nroff |
| 1126 |
out |
| 1127 |
output |
| 1128 |
perl |
| 1129 |
pitch |
| 1130 |
put |
| 1131 |
rcsfile |
| 1132 |
reference |
| 1133 |
resolution |
| 1134 |
revision |
| 1135 |
see |
| 1136 |
set |
| 1137 |
simple |
| 1138 |
smi |
| 1139 |
some |
| 1140 |
string |
| 1141 |
synopsis |
| 1142 |
system |
| 1143 |
that |
| 1144 |
the |
| 1145 |
this |
| 1146 |
translation |
| 1147 |
troff |
| 1148 |
typewriter |
| 1149 |
ucb |
| 1150 |
unbreakable |
| 1151 |
use |
| 1152 |
used |
| 1153 |
user |
| 1154 |
vroff |
| 1155 |
wheel |
| 1156 |
will |
| 1157 |
with |
| 1158 |
you |
| 1159 |
|
| 1160 |
!NO!SUBS! |