1998-06-12 03:56:23 +04:00
|
|
|
#!/usr/bonsaitools/bin/perl
|
1999-09-17 05:07:34 +04:00
|
|
|
# $Id: search,v 1.7 1999-09-17 01:07:34 endico%mozilla.org Exp $
|
1998-06-12 03:56:23 +04:00
|
|
|
|
|
|
|
# search -- Freetext search
|
|
|
|
#
|
|
|
|
# Arne Georg Gleditsch <argggh@ifi.uio.no>
|
|
|
|
# Per Kristian Gjermshus <pergj@ifi.uio.no>
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
use lib 'lib/';
|
|
|
|
use LXR::Common;
|
|
|
|
use LXR::Config;
|
|
|
|
|
|
|
|
$maxhits = 1000;
|
|
|
|
|
|
|
|
sub search {
|
1998-06-13 01:58:38 +04:00
|
|
|
print("<P ALIGN=CENTER>\n",
|
|
|
|
"Free-text search through the source code, including comments.\n",
|
1999-09-10 23:03:39 +04:00
|
|
|
"<BR>By default, this form treats all characters as literals. \n",
|
1999-09-17 05:07:34 +04:00
|
|
|
"<BR>Search strings can have a maximum of 29 characters.\n",
|
1999-09-10 23:03:39 +04:00
|
|
|
"<BR>Read the <A HREF=\"search-help.html\">documentation</A>",
|
|
|
|
" for help with glimpse's regular expression syntax,\n");
|
1998-06-12 03:56:23 +04:00
|
|
|
|
1999-09-10 23:03:39 +04:00
|
|
|
print("<TABLE><TR><TD>");
|
1998-06-12 03:56:23 +04:00
|
|
|
print("<form method=get action=\"search\">\n");
|
|
|
|
|
|
|
|
foreach ($Conf->allvariables) {
|
|
|
|
if ($Conf->variable($_) ne $Conf->vardefault($_)) {
|
|
|
|
print("<input type=hidden name=\"",$_, "\" ",
|
|
|
|
"value=\"", $Conf->variable($_), "\">\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-10 23:03:39 +04:00
|
|
|
$s = $searchtext;
|
|
|
|
$s =~ s/"/\"/g;
|
|
|
|
print("<B>Search for: </B></TD><TD><input type=text name=\"string\" ",
|
1999-09-17 05:07:34 +04:00
|
|
|
"value=\"",$s,"\" maxlength=29 size=30>\n",
|
1999-09-10 23:03:39 +04:00
|
|
|
"<input type=submit value=\"search\"><BR>\n",
|
|
|
|
"</TD></TR><TR><TD></TD><TD>\n",
|
|
|
|
"<input type=\"checkbox\" name=\"regexp\"");
|
|
|
|
if ($Conf->{'regexp'} eq 'on') {
|
|
|
|
print (" CHECKED");
|
|
|
|
print (" value=\"on\">Regular Expression Search\n");
|
|
|
|
} else {
|
|
|
|
print (">Regular Expression Search\n");
|
|
|
|
}
|
|
|
|
print ("</TD></TR>\n</form>\n </TABLE>\n");
|
1998-06-12 03:56:23 +04:00
|
|
|
|
|
|
|
$| = 1; print('');
|
1999-09-10 23:03:39 +04:00
|
|
|
|
1998-06-12 03:56:23 +04:00
|
|
|
if ($searchtext ne "") {
|
|
|
|
print("<hr>\n");
|
|
|
|
unless (open(GLIMPSE, "-|")) {
|
|
|
|
open(STDERR, ">&STDOUT");
|
|
|
|
$!='';
|
1999-09-10 23:03:39 +04:00
|
|
|
if ($Conf->{'regexp'} eq 'off') {
|
|
|
|
$searchtext =~ s/([;,#><\-\$.^*[^|()\!])/\\$1/g;
|
|
|
|
}
|
1998-06-13 01:42:37 +04:00
|
|
|
exec($Conf->glimpsebin,"-i","-H".$Conf->dbdir,'-y','-n',$searchtext);
|
1998-06-12 03:56:23 +04:00
|
|
|
print("Glimpse subprocess died unexpextedly: $!\n");
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$numlines = 0;
|
|
|
|
while (<GLIMPSE>) {
|
|
|
|
$numlines++;
|
|
|
|
push(@glimpselines,$_);
|
|
|
|
if ($numlines > $maxhits) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(GLIMPSE);
|
|
|
|
|
|
|
|
$retval = $? >> 8;
|
|
|
|
|
|
|
|
# The manpage for glimpse says that it returns 2 on syntax errors or
|
|
|
|
# inaccessible files. It seems this is not the case.
|
|
|
|
# We will have to work around it for the time being.
|
|
|
|
|
|
|
|
if ($retval == 0) {
|
|
|
|
if (@glimpselines == 0) {
|
|
|
|
print("No matching files<br>\n");
|
1999-09-17 04:43:31 +04:00
|
|
|
} elsif (@glimpselines[0] =~ /pattern too long/) {
|
1999-09-17 05:07:34 +04:00
|
|
|
print ("Pattern too long. Use a maximum 29 characters.\n");
|
1998-06-12 03:56:23 +04:00
|
|
|
} else {
|
|
|
|
if ($numlines > $maxhits) {
|
|
|
|
print("<b> Too many hits, displaying first $maxhits</b><br>\n");
|
|
|
|
}
|
1999-09-10 23:03:39 +04:00
|
|
|
$searchtext =~ s/&/&/g;
|
|
|
|
$searchtext =~ s/</</g;
|
|
|
|
$searchtext =~ s/>/>/g;
|
|
|
|
|
1998-06-12 03:56:23 +04:00
|
|
|
print("<h1>$searchtext</h1>\n");
|
|
|
|
$sourceroot = $Conf->sourceroot;
|
|
|
|
foreach $glimpseline (@glimpselines) {
|
|
|
|
|
|
|
|
$glimpseline =~ s/$sourceroot//;
|
|
|
|
($file, $line, $text) =
|
|
|
|
$glimpseline =~ /(.*?):\s*(\d+)\s*:(.*)/;
|
|
|
|
$text =~ s/&/&/g;
|
|
|
|
$text =~ s/</</g;
|
|
|
|
$text =~ s/>/>/g;
|
|
|
|
|
|
|
|
print(&fileref("$file, line $line", "$file", $line),
|
|
|
|
" -- $text<br>\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elsif ($retval == 1) {
|
|
|
|
$glimpsebin = $Conf->glimpsebin;
|
|
|
|
$glimpseresponse = join("<br>",@glimpselines);
|
|
|
|
$glimpseresponse =~ s/$glimpsebin/Reason/;
|
|
|
|
$glimpseresponse =~ s/glimpse: error in searching index//;
|
|
|
|
print("<b>Search failed</b><br>\n$glimpseresponse");
|
|
|
|
} else {
|
|
|
|
print("Unexpected returnvalue $retval from Glimpse\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-10 23:03:39 +04:00
|
|
|
($Conf, $HTTP, $Path) = &glimpse_init;
|
1998-06-12 03:56:23 +04:00
|
|
|
$searchtext = $HTTP->{'param'}->{'string'};
|
1999-09-10 23:03:39 +04:00
|
|
|
$regexp = $HTTP->{'param'}->{'regexp'};
|
|
|
|
$searchtext =~ tr/+/ /;
|
|
|
|
$searchtext =~ s/%(\w\w)/chr(hex $1)/ge;
|
|
|
|
|
1998-06-12 03:56:23 +04:00
|
|
|
|
|
|
|
&makeheader('search');
|
|
|
|
&search;
|
|
|
|
&makefooter('search');
|