[Lxr-dev] Regular Expression search for identifiers
Brought to you by:
ajlittoz
From: Shree K. <sh...@pr...> - 2002-02-12 07:10:54
|
It would be nice to allow a user to search for an identifier by specifying a regular expression. Here are a few changes I made to the LXR 0.9 code to allow this. The solution given here is MySQL based but must be possible using other database backends as well. The patches are for LXR-0.9, though they might work for LXR-0.9.1 as well. ----------------------------------------------------------------------- First, add the following lines to the "new" function in mysql.pm : ---- # Current idea is to return names of all identifiers, and # let Perl regular expressions do the magic rather that # use the regular expressions in MySQL - this makes it trivial # to use this approach with other DBMSs and DB_File $self->{all_ident_select} = $self->{dbh}->prepare ("select distinct s.symname ". "from symbols s, indexes i, files f, releases r ". "where s.symid = i.symid and i.fileid = f.fileid ". "and f.fileid = r.fileid ". "and r.release = ?"); ---- And add a new function "getallident" to mysql.pm : ---- # Added for regular expression identifier search support sub getallident { my ($self, $symname, $release) = @_; my ($rows, @ret); $rows = $self->{all_ident_select}->execute("$release"); while ($rows-- > 0) { push(@ret,[$self->{all_ident_select}->fetchrow_array]); } $self->{all_ident_select}->finish(); map { $$_[3] &&= $self->symname($$_[3]) } @ret; return @ret; } -------------------------------------------------------------------------- Add a new function "regexp_search" to the "ident" script. -------------------------------------------------------------------------- sub regexp_search { if ($identifier eq "") { return } # get the list of all identifiers my @refs = $index->getallident($identifier, $release); my @ident=(); my $def; my $ident; my $temp; my $count=0; while ($def = shift(@refs)) { ($ident)=@$def; # filter using the regexp - ignore case if ($ident =~ /$identifier/i) { push(@ident,$ident); $count++; } } if(($count>1) || (($count == 1 ) and ($identifier ne $ident[0]))){ print("<h3>Regexp \"$identifier\" - ". ($count) ." matching identifiers found</h3>\n"); my $vallink; while(@ident) { $ident = shift(@ident); $vallink = &idref($ident, "varlink", $ident, "i=$ident"); print("$vallink<br>\n"); } } } And after the "printident" function call, add a call to "regexp_search" -------------------------------------------------------------------------- Now, search for identifiers using regular expressions - .* must give all the identifiers - Shree Kumar |