[Lxr-commits] CVS: lxr ident,1.37,1.38 search,1.50,1.51
Brought to you by:
ajlittoz
|
From: Andre-Littoz <ajl...@us...> - 2013-09-24 08:43:09
|
Update of /cvsroot/lxr/lxr In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv6383 Modified Files: ident search Log Message: ident, search: provide more substitution markers for templates Also, better comments and various Perl syntax optimisations Index: ident =================================================================== RCS file: /cvsroot/lxr/lxr/ident,v retrieving revision 1.37 retrieving revision 1.38 diff -u -d -r1.37 -r1.38 --- ident 8 Apr 2013 16:05:04 -0000 1.37 +++ ident 24 Sep 2013 08:43:06 -0000 1.38 @@ -1,4 +1,6 @@ #!/usr/bin/perl -T +###################################################################### +# # $Id$ # # ident -- Look up identifiers @@ -28,7 +30,7 @@ use strict; use lib do { $0 =~ m{(.*)/} ? "$1/lib" : "lib" }; # if LXR modules are in ./lib -=head1 indent script +=head1 ident script This script manages the HTTP requests for identifier search. @@ -53,7 +55,7 @@ Function C<varinputs> is a "$variable" substitution function. It returns a string which is a concatenation of tags -C<<E<lt>input type="hidden" name=">>I<variable_name>C<" value=">I<variable_value>C<<"E<gt> >> +C<E<lt>input type="hidden" name=">I<variable_name>C<" value=">I<variable_value>C<"E<gt>> one for each variable defined in configuration parameter C<'variables'>. @@ -65,7 +67,12 @@ my $ret = ''; foreach ($config->allvariables) { if ($config->variable($_) ne $config->vardefault($_)) { - $ret .= "<input type=\"hidden\" name=\"$_\" value=\"" . $config->variable($_) . "\">\n"; + $ret .= '<input type="hidden" name="' + . $_ + . '" value="' + . $config->variable($_) + . '">' + . "\n"; } } return $ret; @@ -125,7 +132,7 @@ sub checkvalidref { my ($file) = @_; - if ( !$index->filetimestamp + if (!$index->filetimestamp ( $file , $files->filerev($file, $releaseid) ) @@ -137,8 +144,11 @@ # need it # && LXR::Lang::parseable($file) ) { - $bad_refs++; 'identinvalid' - } else {''} + $bad_refs++; + 'identinvalid' + } else { + '' + } } @@ -208,7 +218,7 @@ my ($desc, $css, $path, $line) = @_; if ($line < 0) { - return fileref($desc, $css." identapprox", $path, -$line); + return fileref($desc, $css.' identapprox', $path, -$line); } else { return fileref($desc, $css, $path, $line); } @@ -247,6 +257,8 @@ =over +=item + I<The element of the references array is a list. This list does not contain the same number of items for definitions and usages. In case of modification (notably @@ -265,7 +277,7 @@ countfiles ($refs); # Select usage layout on the presence of a specific marker - if ($templ =~ m/\$lines\b/) { + if (0 <= index($templ, '$lines')) { # We are in "many refs per line" layout my @lines; $last_file = @$refs[0]; @@ -278,24 +290,24 @@ } LAST_EXPAND: ++$i; - if ( $last_file ne $file - || $i >= scalar (@$refs) + if ( $last_file ne $file + || $i >= scalar (@$refs) ) { $ret .= expandtemplate ( $templ , ( 'file' => - sub { ref_in_file($last_file, "identfile", $last_file) } + sub { ref_in_file($last_file, 'identfile', $last_file) } , 'fileonce'=> - sub { ref_in_file($last_file, "identfile", $last_file) } + sub { ref_in_file($last_file, 'identfile', $last_file) } , 'lines' => sub { join ( ' ' - , map { ref_in_file( abs($_), "identline", $last_file, $_) + , map { ref_in_file( abs($_), 'identline', $last_file, $_) } @lines ) } , 'type' => sub { $type } - , 'rel' => sub { if ($rel) { idref($rel, "identrel", $rel) } } + , 'rel' => sub { if ($rel) { idref($rel, 'identrel', $rel) } } , 'fileref' => sub { - ref_in_file("$last_file, line ".abs($line), "identline", $last_file, $line); + ref_in_file("$last_file, line ".abs($line), 'identline', $last_file, $line); } , 'refinvalid' => sub { checkvalidref($last_file) } ) @@ -318,15 +330,15 @@ $ret .= expandtemplate ( $templ , ( 'file' => - sub { ref_in_file($file, "identfile", $file) } + sub { ref_in_file($file, 'identfile', $file) } , 'fileonce'=> - sub { if ($fileonce) { ref_in_file($fileonce, "identfile", $file) } } + sub { if ($fileonce) { ref_in_file($fileonce, 'identfile', $file) } } , 'line' => - sub { ref_in_file( abs($line), "identline", $file, $line) } + sub { ref_in_file( abs($line), 'identline', $file, $line) } , 'type' => sub { $type } - , 'rel' => sub { if ($rel) { idref($rel, "identrel", $rel) } } + , 'rel' => sub { if ($rel) { idref($rel, 'identrel', $rel) } } , 'fileref' => sub { - ref_in_file("$file, line ".abs($line), "identline", $file, $line); + ref_in_file("$file, line ".abs($line), 'identline', $file, $line); } , 'refinvalid' => sub { checkvalidref($file) } ) @@ -359,9 +371,13 @@ =over +=item + For usages, the last two element do no exist. The comparison stops after the first two steps. +=back + =cut sub cmprefs { @@ -450,9 +466,9 @@ } -=head2 C<usessexpand ($templ)> +=head2 C<usesexpand ($templ)> -Function C<usessexpand> is a "$function" substitution function. +Function C<usesexpand> is a "$function" substitution function. It returns an HTML string which is the concatenation of its expanded argument applied to every usage. @@ -467,6 +483,13 @@ The function queries the database for usages, then hands over definition layout to C<refsexpand>. +Since some languages are case-insensitive, the database is also +queried for the case-insensitive version of the identifier. +The returned definitions are flagged with their line numbers set +negative. +The two lists are merged, removing duplicates and sorted as if a +single query was made. + =cut sub usesexpand { @@ -515,7 +538,10 @@ =head2 C<printident ()> -Sub C<printident> is the main driver for identifier search. +Procedure C<printident> is the main driver for identifier search. + +It retrieves template C<'htmldir'> and expands it using the dedicated +functions defined in this file. =cut @@ -537,7 +563,9 @@ , ( 'variables' => \&varinputs , 'identifier' => sub { $_ = $identifier; s/</</g; s/>/>/g; return $_; } , 'identifier_escaped'=> sub { $_ = $identifier; s/\"/"/g; s/</</g; s/>/>/g; return $_; } - , 'checked' => sub { $defonly ? 'checked="checked"' : "" } + , 'checked' => sub { $defonly ? 'checked="checked"' : '' } + , 'varbtnaction' => sub { varbtnaction(@_, 'ident') } + , 'urlargs' => sub { urlexpand('-', 'ident') } , 'defs' => \&defsexpand , 'uses' => \&usesexpand ) @@ -545,6 +573,14 @@ ); } + +=head2 Script entry point + +Builds the header and footer and launches C<printident> +for the real job. + +=cut + httpinit; makeheader('ident'); $defonly = 1 if ($HTTP->{'param'}{'_identdefonly'} Index: search =================================================================== RCS file: /cvsroot/lxr/lxr/search,v retrieving revision 1.50 retrieving revision 1.51 diff -u -d -r1.50 -r1.51 --- search 24 Jan 2013 15:09:52 -0000 1.50 +++ search 24 Sep 2013 08:43:06 -0000 1.51 @@ -1,6 +1,8 @@ #!/usr/bin/perl -T +###################################################################### # $Id$ -# +## + # search -- Freetext search # # Arne Georg Gleditsch <ar...@if...> @@ -26,9 +28,9 @@ $CVSID = '$Id$ '; use strict; -use lib do { $0 =~ m{(.*)/} ? "$1/lib" : "lib" }; # if LXR modules are in ./lib +use lib do { $0 =~ m{(.*)/} ? "$1/lib" : 'lib' }; # if LXR modules are in ./lib -=head1 indent script +=head1 search script This script manages the HTTP requests for free-text search. @@ -49,7 +51,7 @@ Function C<varinputs> is a "$function" substitution function. It returns a string which is a concatenation of tags -C<<E<lt>input type="hidden" name=">>I<variable_name>C<" value=">I<variable_value>C<<"E<gt> >> +C<E<lt>input type="hidden" name=">I<variable_name>C<" value=">I<variable_value>C<"E<gt>> one for each variable defined in configuration parameter C<'variables'>. @@ -124,10 +126,10 @@ my ($filetext, $advanced, $casesensitive, $file) = @_; if ($advanced) { if ($casesensitive) { - if ($file =~ /$filetext/) { + if ($file =~ m/$filetext/) { return 1; } - } elsif ($file =~ /$filetext/i) { + } elsif ($file =~ m/$filetext/i) { return 1; } } else { @@ -184,10 +186,10 @@ # Don't scan files ending in ,v or ~ ." -F '-v (\\,v\|\\~)\$' " # Should we match casesensitive ? - . ($casesensitive ? "" : "-i") + . ($casesensitive ? '' : '-i') # Location of index datadbase - . " -H " - .$config->{'glimpsedir'}."/".$releaseid + . ' -H ' + . $config->{'glimpsedir'}.'/'.$releaseid # The pattern to search for ." -y -n '$searchtext' 2>&1 |" ) @@ -198,7 +200,7 @@ my @glimpsemsgs = (); while (<GLIMPSE>) { if (s/^$sourceroot//) { - my ($file) = $_ =~ /(.*?):\s*/; + my ($file) = $_ =~ m/(.*?):\s*/; # Keep only occurrences matching file name if given next if $filetext && !filename_matches($filetext, $advanced, $casesensitive, $file); $numlines++; @@ -225,11 +227,11 @@ if ($retval == 0) { my @ret; - my $i = 0; + my $i = 0; foreach my $glimpseline (@glimpselines) { last if ($i > $maxhits); - my ($file, $line, $text) = $glimpseline =~ /(.*?):\s*(\d+)\s*:(.*)/; + my ($file, $line, $text) = $glimpseline =~ m/(.*?):\s*(\d+)\s*:(.*)/; $text =~ s/&/&/g; $text =~ s/</</g; @@ -243,7 +245,7 @@ return sort {$$a[0] cmp $$b[0]} @ret; } elsif ($retval == 1) { my $glimpsebin = $config->{'glimpsebin'}; - my $glimpseresponse = join("<br>", @glimpselines); + my $glimpseresponse = join('<br>', @glimpselines); my $glimpseresponse =~ s/$glimpsebin/Reason/; my $glimpseresponse =~ s/glimpse: error in searching index//; print("<p class='error'>Search failed</p>\n<p>$glimpseresponse</p>\n"); @@ -294,16 +296,19 @@ sub swishsearch { my ($searchtext, $filetext, $advanced, $casesensitive) = @_; - my $swishIndex = $config->{'swishdir'} . "/" . $releaseid . ".index"; + my $swishIndex = $config->{'swishdir'} . '/' . $releaseid . '.index'; if (!-e $swishIndex) { - print "<p class='error'>"; + print '<p class="error">'; print "Version '$releaseid' has not been indexed and is unavailable for searching."; - print "</p>"; + print '</p>'; return; } $ENV{'PATH'} = '/bin:/usr/local/bin:/usr/bin:/usr/sbin'; - my $swishCommand = join(' ', $config->{'swishbin'}, "-f", $swishIndex, "-w", "'(" . $searchtext . ")'"); + my $swishCommand = $config->{'swishbin'} + . ' -f ' . $swishIndex + . ' -w \'(' . $searchtext . ')\'' + ; my $ret = `$swishCommand`; my @result = grep { not /^[\#\.]/ } split(/\n/, $ret); @@ -313,9 +318,9 @@ my $numlines = 0; foreach my $hit (@result) { print $hit, "<br>\n" if $hit =~ /No such file or directory/; # feeble attempt to print possible errors (e.g. incomplete LD_LIBRARY_PATH causes linking errors) - next if $hit =~ /^err:/; # skip; only 'no results' errors happen with return value 0 + next if substr($hit, 0, 4) eq 'err:'; # skip; only 'no results' errors happen with return value 0 - my ($score, $file) = $hit =~ /^(\d+) \/(.+) "(.+)" \d+/; + my ($score, $file) = $hit =~ m/^(\d+) \/(.+) "(.+)" \d+/; next if $filetext && !filename_matches($filetext, $advanced, $casesensitive, $file); push @ret, [ $file, $score ]; $numlines++; @@ -325,7 +330,7 @@ return @ret; } else { print( "<p class='error'>Search failed: internal error</p><br>\n<p>" - . join("<br>", @result) + . join('<br>', @result) . "<\p>\n"); return; } @@ -364,7 +369,9 @@ && LXR::Lang::parseable($file) ) { 'searchinvalid' - } else {''} + } else { + '' + } } @@ -399,6 +406,8 @@ =over +=item + I<Both search engines start by looking into their private "index" files before accessing the source-tree files. A first consequence is any file added after genxref indexing cannot @@ -437,19 +446,19 @@ $ret .= expandtemplate ( $templ , ( 'text' => sub { return "<pre class='searchtext'>$text</pre>" } - , 'file' => sub { fileref($file, "searchfile", "/$file") } + , 'file' => sub { fileref($file, 'searchfile', "/$file") } , 'fileonce'=> sub { if ($fileonce) { - return fileref($fileonce, "searchfile", "/$file") + return fileref($fileonce, 'searchfile', "/$file") } else { - return " " + return ' ' } } - , 'line' => sub { fileref($line, "searchline", "/$file", $line) } - , 'fileref' => sub { fileref("$file, line $line", "searchfile", "/$file", $line) } + , 'line' => sub { fileref($line, 'searchline', "/$file", $line) } + , 'fileref' => sub { fileref("$file, line $line", 'searchfile', "/$file", $line) } , 'tdfile' => sub { if ($fileonce) { - return "searchfile" + return 'searchfile' } else { - return "searchfilevoid" + return 'searchfilevoid' } } , 'searchinvalid' => sub { checkvalidref($file) } @@ -463,19 +472,19 @@ $ret .= expandtemplate ( $templ , ( 'text' => sub { return $score } - , 'file' => sub { fileref($file, "searchfile", "/$file") } + , 'file' => sub { fileref($file, 'searchfile', "/$file") } , 'fileonce'=> sub { if ($fileonce) { - return fileref($fileonce, "searchfile", "/$file") + return fileref($fileonce, 'searchfile', "/$file") } else { - return " " + return ' ' } } , 'line' => sub { return '' } - , 'fileref' => sub { fileref($file, "searchfile", "/$file") } + , 'fileref' => sub { fileref($file, 'searchfile', "/$file") } , 'tdfile' => sub { if ($fileonce) { - return "searchfile" + return 'searchfile' } else { - return "searchfilevoid" + return 'searchfilevoid' } } , 'searchinvalid' => sub { checkvalidref($file) } @@ -499,8 +508,10 @@ =over +=item + Filename search may give inaccurate results if source-tree has -been modified since last genxref indexation because search is +been modified since last F<genxref> indexation because search is done against an internal list captured at indexing time. =back @@ -527,15 +538,15 @@ $searchtext =~ s/\+/ /g; # Reverse <form> space encoding my @results; - if ($searchtext ne "") { + if ($searchtext ne '') { if ($config->{'glimpsebin'}) { @results = glimpsesearch($searchtext, $filetext, $advanced, $casesensitive); } elsif ($config->{'swishbin'} && $config->{'swishdir'}) { @results = swishsearch($searchtext, $filetext, $advanced, $casesensitive); } else { - warning("No freetext search engine configured."); + warning('No freetext search engine configured.'); } - } elsif ($filetext ne "") { + } elsif ($filetext ne '') { my $FILELISTING; if ($config->{'swishdir'} && $config->{'swishbin'}) { unless ($FILELISTING = IO::File->new($config->{'swishdir'} . "/$releaseid.filenames")) { @@ -547,7 +558,7 @@ } } elsif ($config->{'glimpsedir'} && $config->{'glimpsebin'}) { unless ($FILELISTING = - IO::File->new($config->{'glimpsedir'} . "/" . $releaseid . "/.glimpse_filenames")) + IO::File->new($config->{'glimpsedir'} . '/' . $releaseid . "/.glimpse_filenames")) { &warning( "Version '$releaseid' has not been indexed and is unavailable for searching<br>Could not open " @@ -557,7 +568,7 @@ } } else { warning( - "Freetext search engine required for file search, and no freetext search engine is configured" + 'Freetext search engine required for file search, and no freetext search engine is configured' ); return; } @@ -572,16 +583,18 @@ print expandtemplate ( $templ - , ( 'variables' => sub { varinputs( @_) } - , 'searchtext' => sub { $_ = $searchtext; s/&/&/g; s/</</g; s/>/>/g; return $_; } - , 'searchtext_escaped' => sub { $_ = $searchtext; s/\"/"/g; s/&/&/g; s/</</g; s/>/>/g; return $_; } - , 'filetext_escaped' => sub { $_ = $filetext; s/\"/"/g; return $_; } - , 'advancedchecked' => sub { return $advanced ? "checked" : "" } - , 'casesensitivechecked' => sub { return $casesensitive ? "checked" : "" } - , 'maxhits_message' => sub { + , ( 'variables' => \&varinputs + , 'searchtext' => sub { $_ = $searchtext; s/&/&/g; s/</</g; s/>/>/g; return $_; } + , 'searchtext_escaped' => sub { $_ = $searchtext; s/\"/"/g; s/&/&/g; s/</</g; s/>/>/g; return $_; } + , 'filetext_escaped' => sub { $_ = $filetext; s/\"/"/g; return $_; } + , 'advancedchecked' => sub { $advanced ? 'checked' : '' } + , 'casesensitivechecked'=> sub { $casesensitive ? 'checked' : '' } + , 'varbtnaction' => sub { varbtnaction(@_, 'search') } + , 'urlargs' => sub { urlexpand('-', 'search') } + , 'maxhits_message' => sub { return @results == $maxhits ? "<b>Too many hits, displaying first $maxhits</b><br>" - : ""; + : ''; } , 'results' => sub { printresults(@_, $searchtext, @results) } @@ -590,9 +603,17 @@ ); } + +=head2 Script entry point + +Builds the header and footer and launches C<search> +for the real job. + +=cut + httpinit; makeheader('search'); -if ($files->isa("LXR::Files::Plain")) { +if ($files->isa('LXR::Files::Plain')) { if ( $config->{'glimpsebin'} && $config->{'glimpsebin'} =~ m!^(.*/)?true$! || $config->{'swishbin'} |