Rework the init subroutine in Common.pm so glimpse doesn't go through the normal http_wash stuff so now you can do regexp searches and search->for pointers. Reworked the search form so that searching for literals is the default. Meta characters automatically escaped unless the regexp button is pushed. Changed the docs so it no longer says to use double backslashes to escape metachars. That's only needed from the shell.

This commit is contained in:
endico%mozilla.org 1999-09-10 19:03:39 +00:00
parent a44e9bf05f
commit 313ddc4e98
3 changed files with 80 additions and 27 deletions

View File

@ -1,4 +1,4 @@
# $Id: Common.pm,v 1.19 1999/08/07 09:28:37 mccabe%netscape.com Exp $
# $Id: Common.pm,v 1.20 1999/09/10 19:03:39 endico%mozilla.org Exp $
package LXR::Common;
@ -11,7 +11,7 @@ require Exporter;
@EXPORT = qw($Path &warning &fatal &abortall &fflush &urlargs
&fileref &idref &htmlquote &freetextmarkup &markupfile
&markspecials &htmlquote &freetextmarkup &markupstring
&init &makeheader &makefooter &expandtemplate);
&init &glimpse_init &makeheader &makefooter &expandtemplate);
$wwwdebug = 1;
@ -122,6 +122,7 @@ sub idref {
sub http_wash {
my $t = shift;
# $t =~ s/\+/%2B/g;
#endico: don't use plus signs to represent spaces as is the normal
#case. we need to use them in file names for gtk+
@ -133,6 +134,7 @@ sub http_wash {
# Should be sufficient to keep "open" from doing unexpected stuff.
if ($t =~ tr/<>|\"\'\`//) {
&abortall("Illegal characters in HTTP-parameters.");
}
return($t);
@ -396,25 +398,53 @@ sub fixpaths {
$Path->{'xref'} =~ s#/</a>#</a>/#gi;
}
sub glimpse_init {
($Conf, $HTTP, $Path) = &init_all;
$HTTP->{'this_url'} = join('', 'http://',
$ENV{'SERVER_NAME'},
':', $ENV{'SERVER_PORT'},
$ENV{'SCRIPT_NAME'},
$ENV{'PATH_INFO'},
'?', $ENV{'QUERY_STRING'});
my @a;
if ($ENV{'QUERY_STRING'} =~ s/&regexp=on//) {
$Conf->{'regexp'} = 'on';
} else {
$ENV{'QUERY_STRING'} =~ s/&regexp=off//;
$Conf->{'regexp'} = 'off';
}
foreach ($ENV{'QUERY_STRING'} =~ /([^;&=]+)(?:=([^;&]+)|)/g) {
push(@a, $_);
}
$HTTP->{'param'} = {@a};
return($Conf, $HTTP, $Path);
}
sub init {
my ($argv_0) = @_;
my @a;
$HTTP->{'path_info'} = &http_wash($ENV{'PATH_INFO'});
($Conf, $HTTP, $Path) = &init_all;
$HTTP->{'this_url'} = &http_wash(join('', 'http://',
$ENV{'SERVER_NAME'},
':', $ENV{'SERVER_PORT'},
$ENV{'SCRIPT_NAME'},
$ENV{'PATH_INFO'},
'?', $ENV{'QUERY_STRING'}));
foreach ($ENV{'QUERY_STRING'} =~ /([^;&=]+)(?:=([^;&]+)|)/g) {
push(@a, &http_wash($_));
}
}
$HTTP->{'param'} = {@a};
return($Conf, $HTTP, $Path);
}
sub init_all {
my ($argv_0) = @_;
$HTTP->{'path_info'} = &http_wash($ENV{'PATH_INFO'});
$HTTP->{'param'}->{'v'} ||= $HTTP->{'param'}->{'version'};
$HTTP->{'param'}->{'a'} ||= $HTTP->{'param'}->{'arch'};
$HTTP->{'param'}->{'i'} ||= $HTTP->{'param'}->{'identifier'};
@ -549,6 +579,13 @@ sub titleexpand {
} elsif ($who eq 'search') {
my $s = $HTTP->{'param'}->{'string'};
$s =~ tr/+/ /;
$s =~ s/%(\w\w)/chr(hex $1)/ge;
$s =~ s/&/&amp;/g;
$s =~ s/</&lt;/g;
$s =~ s/>/&gt;/g;
return($Conf->sourcerootname.' freetext search'.
($s ? " \"$s\"" : ''));

View File

@ -1,5 +1,5 @@
#!/usr/bonsaitools/bin/perl
# $Id: search,v 1.4 1998/06/12 21:58:38 jwz Exp $
# $Id: search,v 1.5 1999/09/10 19:03:37 endico%mozilla.org Exp $
# search -- Freetext search
#
@ -32,9 +32,11 @@ $maxhits = 1000;
sub search {
print("<P ALIGN=CENTER>\n",
"Free-text search through the source code, including comments.\n",
"<BR>(Need some <A HREF=\"search-help.html\">Hints</A> ",
"on performing searches?)\n");
"<BR>By default, this form treats all characters as literals. \n",
"<BR>Read the <A HREF=\"search-help.html\">documentation</A>",
" for help with glimpse's regular expression syntax,\n");
print("<TABLE><TR><TD>");
print("<form method=get action=\"search\">\n");
foreach ($Conf->allvariables) {
@ -44,21 +46,31 @@ sub search {
}
}
print("<B>Search for: </B><input type=text name=\"string\" ",
"value=\"",$searchtext,"\" size=50>\n",
"<input type=submit value=\"search\">\n",
# $Query->checkbox("case",0,0,"Case sensitive search"),
# $Query->checkbox("regexp",1,0,"Regular expression search"),
# $Query->popup_menu("fuzz",[0,1,2,3,4,5,6,7],0),
"</form>\n");
$s = $searchtext;
$s =~ s/"/\&quot;/g;
print("<B>Search for: </B></TD><TD><input type=text name=\"string\" ",
"value=\"",$s,"\" size=50>\n",
"<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");
$| = 1; print('');
if ($searchtext ne "") {
print("<hr>\n");
unless (open(GLIMPSE, "-|")) {
open(STDERR, ">&STDOUT");
$!='';
if ($Conf->{'regexp'} eq 'off') {
$searchtext =~ s/([;,#><\-\$.^*[^|()\!])/\\$1/g;
}
exec($Conf->glimpsebin,"-i","-H".$Conf->dbdir,'-y','-n',$searchtext);
print("Glimpse subprocess died unexpextedly: $!\n");
exit;
@ -88,6 +100,10 @@ sub search {
if ($numlines > $maxhits) {
print("<b> Too many hits, displaying first $maxhits</b><br>\n");
}
$searchtext =~ s/&/&amp;/g;
$searchtext =~ s/</&lt;/g;
$searchtext =~ s/>/&gt;/g;
print("<h1>$searchtext</h1>\n");
$sourceroot = $Conf->sourceroot;
foreach $glimpseline (@glimpselines) {
@ -115,11 +131,13 @@ sub search {
}
}
($Conf, $HTTP, $Path) = &init;
($Conf, $HTTP, $Path) = &glimpse_init;
$searchtext = $HTTP->{'param'}->{'string'};
$regexp = $HTTP->{'param'}->{'regexp'};
$searchtext =~ tr/+/ /;
$searchtext =~ s/%(\w\w)/chr(hex $1)/ge;
&makeheader('search');
&search;
&makefooter('search');

View File

@ -19,10 +19,8 @@ for the<br>
<P><BR>
<BLOCKQUOTE><BLOCKQUOTE>
<I>
This text is copied from the Glimpse manual page. I have tried to remove
things that do not apply to the lxr searcher, but beware, some things might
have slipped through. I'll try to put together something better when I get
the time. For more information on glimpse go to the
This text is derived from the Glimpse manual page.
For more information on glimpse, see the
<A HREF="http://glimpse.cs.arizona.edu">Glimpse homepage</A>.
</I>
</BLOCKQUOTE></BLOCKQUOTE>
@ -42,8 +40,8 @@ Strings are any sequence of characters, including the special symbols
special characters (`$', `^', `*', `[', `^', `|', `(', `)', `!', and
`\' ) as well as the following meta characters special to glimpse (and
agrep): `;', `,', `#', `&gt;', `&lt;', `-', and `.', should be preceded by
`\\' if they are to be matched as regular characters. For example,
\\^abc\\\\ corresponds to the string ^abc\\, whereas ^abc corresponds
`\' if they are to be matched as regular characters. For example,
\^abc\\\\ corresponds to the string ^abc\\, whereas ^abc corresponds
to the string abc at the beginning of a line.
</UL>