]+href=([^>]+)>([\000-\377]+?)<\/a>([\000-\377]*)$/i) {
$grv = $4;
local ($url = $2, $desc = $3);
$url =~ s/^"(.*)".*$/$1/;
$url =~ s/^'(.*)'.*$/$1/;
$desc =~ s/<\/?b>//g;
local $matches = 0;
foreach $f (@for) {
$matches++ if ($desc =~ /\Q$f\E/i);
}
next if ($url =~ /^\/search/); # More results
next if ($url =~ /^\/imgres/); # Image
if ($url =~ /^\/url\?(.*)/) {
# Extract real URL
local $qs = $1;
if ($qs =~ /q=([^&]+)/) {
$url = &un_urlize("$1");
}
}
next if ($doneurl{$url}++);
$msg = $host ? $text{'search_doxfer'}
: $text{'search_google'};
if (!$in{'exact'} ||
($in{'and'} && $matches == @for) ||
(!$in{'and'} && $matches)) {
push(@rv, [ $msg, $url, length($url) > 60 ? substr($url, 0, 60)."..." : $url, $desc, $host ? 10 : 0.5 ]);
}
}
}
}
}
if (@rv == 1 && !$in{'check'}) {
# redirect to the exact page
&redirect($in{'exact'} ? $rv[0]->[1]
: "$rv[0]->[1]&for=".&urlize($in{'for'}));
exit;
}
# Display search results
$for = join($in{'and'} ? " and " : " or ",
map { "".&html_escape($_)."" } @for);
&ui_print_header(&text('search_for', $for), $text{'search_title'}, "");
if (@rv) {
#@rv = sort { $b->[4] <=> $a->[4] } @rv;
@rv = sort { &ranking($b) <=> &ranking($a) } @rv;
print &ui_columns_start([ $text{'search_file'},
$text{'search_type'},
$text{'search_desc'} ], 100);
foreach $r (@rv) {
local @cols;
if ($r->[1] =~ /^(http|ftp|https):/) {
push(@cols, &ui_link($r->[1], &html_escape($r->[2]), undef, "target=_blank") );
}
else {
push(@cols, &ui_link($r->[1]."&for=".&urlize($in{'for'}), &html_escape($r->[2]) ) );
}
push(@cols, $r->[0]);
push(@cols, $r->[3]);
print &ui_columns_row(\@cols, [ undef, "nowrap", undef ]);
}
print &ui_columns_end();
}
else {
print "",&text('search_none', "".&html_escape($in{'for'}).""),"
\n";
}
&ui_print_footer("", $text{'index_return'});
# find_contents(directory, &strings, [exclude], [descend], [nameonly])
# Find some string in a directory of files
sub find_contents
{
opendir(DIR, $_[0]);
local @f = readdir(DIR);
closedir(DIR);
local @rv;
foreach $f (@f) {
next if ($f =~ /^\./);
local $p = "$_[0]/$f";
next if ($p eq $_[2]);
if (-d $p) {
# go into subdirectory
push(@rv, &find_contents($p, $_[1], $_[2], $_[3], $_[4]))
if ($_[3]);
}
else {
# Skip non-text or HTML files
local $ff = $f;
$ff =~ s/\.(gz|bz|bz2)$//i;
next if ($ff !~ /\.(txt|htm|html|doc)$/ &&
$ff =~ /\.[A-Za-z0-9]+$/);
next if ($ff =~ /(^makefile$)|(^core$)/i);
local $matches = 0;
foreach $s (@{$_[1]}) {
$matches++ if ($p =~ /\Q$s\E/i);
}
if ($_[4]) {
# just compare filename
if ($in{'and'} && $matches == @{$_[1]} ||
!$in{'and'} && $matches) {
local ($desc, $data) = &read_doc_file($p);
if ($desc !~ /^#!/ && $desc !~ /^#\%/) {
push(@rv, [ $p, $desc, $f,
&html_escape($matches) ]);
}
}
}
else {
# compare file contents
local ($desc, $data) = &read_doc_file($p);
local $dmatches = 0;
foreach $s (@{$_[1]}) {
$dmatches++ if ($data =~ /\Q$s\E/i);
}
if (($in{'and'} && $dmatches == @{$_[1]} ||
!$in{'and'} && $dmatches) &&
$desc !~ /^#!/ && $desc !~ /^#\%/) {
push(@rv, [ $p, $desc, $f,
&html_escape($matches) ]);
}
}
}
}
return @rv;
}
# read_doc_file(filename)
# Returns desc, data
sub read_doc_file
{
local ($two, $first, $title, $data);
open(FILE, "<$_[0]");
read(FILE, $two, 2);
local $qm = quotemeta($_[0]);
if ($two eq "\037\213") {
close(FILE);
&open_execute_command(FILE, "gunzip -c $qm", 1, 1);
}
elsif ($two eq "BZ") {
close(FILE);
&open_execute_command(FILE, "bunzip2 -c $qm", 1, 1);
}
seek(FILE, 0, 0);
while() {
$data .= $_;
if (/[A-Za-z0-9]/ && !/\$\S+:/ && !$first) {
chop($first = $_);
$first =~ s/.\010//g;
}
}
close(FILE);
if ($data =~ /<\s*title\s*>([\000-\177]{0,200})<\s*\/\s*title\s*>/i) {
$title = $1;
}
return ($title ? $title : $first =~ /<.*>/ ? undef : $first, $data);
}
# parse_perl_module(file)
sub parse_perl_module
{
local (%doc, $inside);
open(MOD, "<$_[0]");
while() {
if (/^\s*package\s+(\S+)\s*;/ && !$doc{'package'}) {
$doc{'package'} = $1;
}
elsif (/^=head1\s+(\S+)/i) {
$inside = $1;
}
elsif (/^=cut/i) {
undef($inside);
}
elsif ($inside) {
$doc{lc($inside)} .= $_;
}
}
close(MOD);
return \%doc;
}
# inchelp(path, module)
sub inchelp
{
local $inc;
local $ipath = &help_file($_[1], $_[0]);
open(INC, "<$ipath") || return "".&text('search_einclude', $_[0])."
\n";
local @st = stat(INC);
read(INC, $inc, $st[7]);
close(INC);
return $inc;
}
sub ranking
{
local ($name = 0, $desc = 0);
foreach $f (@for) {
$desc++ if ($_[0]->[3] =~ /$f/i);
$name++ if ($_[0]->[1] =~ /$f/i);
}
return $name ? $_[0]->[4] * 10 :
$desc ? $_[0]->[4] :
$_[0]->[4] / 10;
}