User: sits    
  Date: 08/06/11 05:00:33

  Modified:    lib/Codestriker/Http DeltaRenderer.pm
               lib/Codestriker/Action ViewTopic.pm ViewTopicFile.pm
               html-docs index.html
  Added:       lib/Codestriker/Http LxrLineFilter.pm
  Log:
  Integration of the LXR text filter.  Untested, but should newer versions of 
LXR which use a different table name.  See 
https://sourceforge.net/tracker/index.php?func=detail&aid=1878650&group_id=41136&atid=429860
 for more information.
  
  
  
  Index: DeltaRenderer.pm
  ===================================================================
  RCS file: 
/cvsroot/codestriker/codestriker/lib/Codestriker/Http/DeltaRenderer.pm,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DeltaRenderer.pm  11 Jun 2008 07:52:04 -0000      1.4
  +++ DeltaRenderer.pm  11 Jun 2008 12:00:31 -0000      1.5
  @@ -14,11 +14,12 @@
   use Codestriker::Http::HtmlEntityLineFilter;
   use Codestriker::Http::TabToNbspLineFilter;
   use Codestriker::Http::LineBreakLineFilter;
  +use Codestriker::Http::LxrLineFilter;
   
   # Constructor.
   sub new {
       my ($type, $topic, $comments, $deltas, $query, $mode, $brmode,
  -     $tabwidth) = @_;
  +             $tabwidth, $repository) = @_;
   
       my $self = {};
       $self->{topic} = $topic;
  @@ -52,8 +53,14 @@
   
       # Record list of line filter objects to apply to each line of code.
       # Setup some default filters.
  +    my $lxr_config = defined $repository ?
  +             $Codestriker::lxr_map->{$repository->toString()} : undef;
  +    
       @{$self->{line_filters}} = ();
       push @{$self->{line_filters}}, 
Codestriker::Http::HtmlEntityLineFilter->new();
  +    if (defined $lxr_config) {
  +         push @{$self->{line_filters}}, 
Codestriker::Http::LxrLineFilter->new($lxr_config);
  +    }
       push @{$self->{line_filters}}, 
Codestriker::Http::TabToNbspLineFilter->new($tabwidth);
       push @{$self->{line_filters}}, 
Codestriker::Http::LineBreakLineFilter->new($brmode);
   
  @@ -126,8 +133,6 @@
   
        # Now process the text so that the display code has minimal work to do.
        # Also apply appropriate transformations to the line as required.
  -     # TODO: put this into a proper module/plugin framework to make it easier
  -     # to extend/modify.
        my @diff_lines = split /\n/, $delta->{text};
        my $old_linenumber = $delta->{old_linenumber};
        my $new_linenumber = $delta->{new_linenumber};
  
  
  
  
  
  Index: LxrLineFilter.pm
  ===================================================================
  RCS file: LxrLineFilter.pm
  diff -N LxrLineFilter.pm
  --- /dev/null 1 Jan 1970 00:00:00 -0000
  +++ LxrLineFilter.pm  11 Jun 2008 12:00:31 -0000      1.1
  @@ -0,0 +1,150 @@
  
+###############################################################################
  +# Codestriker: Copyright (c) 2001, 2002 David Sitsky.  All rights reserved.
  +# [EMAIL PROTECTED]
  +#
  +# This program is free software; you can redistribute it and modify it under
  +# the terms of the GPL.
  +
  +# Line filter for converting tabs to the appropriate number of  
  +# entities.
  +
  +package Codestriker::Http::LxrLineFilter;
  +
  +use strict;
  +
  +use Codestriker::Http::LineFilter;
  +
  [EMAIL PROTECTED]::Http::LxrLineFilter::ISA =
  +    ("Codestriker::Http::LineFilter");
  +
  +# Take the LXR configuration as a parameter and create a connection to the 
LXR database
  +# for symbol lookup.
  +sub new {
  +    my ($type, $lxr_config) = @_;
  +
  +    my $self = Codestriker::Http::LineFilter->new();
  +    
  +    # Store the LXR-specific configuration.
  +    $self->{url} = $lxr_config->{url};
  +
  +    # Create a connection to the LXR database.
  +    my $password = defined $lxr_config->{password} ?
  +     $lxr_config->{password} : $lxr_config->{passwd};
  +     $self->{dbh} = DBI->connect($lxr_config->{db}, $lxr_config->{user},
  +                                                             $password,
  +                                                             {AutoCommit=>0, 
RaiseError=>1})
  +             || die "Couldn't connect to LXR database: " . DBI->errstr;
  +
  +     # Create the appropriate prepared statement for retrieving LXR symbols.
  +     # Depending on the LXR deployment, the table name is either "symbols"
  +     # or "lxr_symbols".             
  +     eval
  +     {
  +         $self->{select_ids} =
  +                     $self->{dbh}->prepare_cached('SELECT count(symname) 
FROM symbols where symname = ?');
  +     };
  +    if ($@) {
  +         $self->{select_ids} =
  +                     $self->{dbh}->prepare_cached('SELECT count(symname) 
FROM lxr_symbols where symname = ?');
  +    }        
  +
  +     # Cache for storing which IDs have been found.
  +     $self->{idhash} = {};
  +
  +    return bless $self, $type;
  +}
  +
  +# Given an identifier, wrap it within the appropriate <a href> tag if it
  +# is a known identifier to LXR, otherwise just return the id.  To avoid
  +# excessive crap, only consider those identifiers which are at least 4
  +# characters long.
  +sub lxr_ident($$) {
  +    my ($self, $id) = @_;
  +
  +     my $count = 0;
  +    if (length($id) >= 4) {
  +             # Check if the id has not yet been found in lxr.
  +     if (! exists $self->{idhash}->{$id}) {
  +                     # Initialise this entry.
  +             $self->{idhash}->{$id} = 0;
  +
  +             # Fetch ids from lxr and store the result.
  +                 $self->{select_ids}->execute($id);
  +             ($count) = $self->{select_ids}->fetchrow_array();
  +             $self->{idhash}->{$id} = $count;
  +        } else {
  +             $count = $self->{idhash}->{$id};
  +        }
  +    }
  +
  +    # Check if the id has been found in lxr.
  +    if ($count > 0) {
  +             return '<a href=\"' . $self->{url} . $id . '\" class=\"fid\">' 
. $id . '</a>';
  +    } else {
  +             return $id;
  +    }
  +}
  +
  +# Parse the line and produce the appropriate hyperlinks to LXR.
  +# Currently, this is very Java/C/C++ centric, but it will do for now.
  +sub filter {
  +    my ($self, $text) = @_;
  +    
  +    # If the line is a comment, don't do any processing.  Note this code
  +    # isn't bullet-proof, but its good enough most of the time.
  +    $_ = $text;
  +    return $text if (/^(\s|&nbsp;)*\/\// || 
  +                              /^(\s|&nbsp;){0,10}\*/ ||
  +                          /^(\s|&nbsp;){0,10}\/\*/ ||
  +                          /^(\s|&nbsp;)*\*\/(\s|&nbsp;)*$/);
  +    
  +    # Handle package Java statements.
  +    if ($text =~ /^(package(\s|&nbsp;)+)([\w\.]+)(.*)$/) {
  +             return $1 . $self->lxr_ident($3) . $4;
  +    }
  +    
  +    # Handle Java import statements.
  +    if ($text =~ /^(import(\s|&nbsp;)+)([\w\.]+)\.(\w+)((\s|&nbsp;)*)(.*)$/) 
{
  +             return $1 . $self->lxr_ident($3) . "." . $self->lxr_ident($4) . 
"$5$7";
  +    }
  +    
  +    # Break the string into potential identifiers, and look them up to see
  +    # if they can be hyperlinked to an LXR lookup.
  +    my $idhash = $self->{idhash};
  +    my @data_tokens = split /([A-Za-z][\w]+)/, $text;
  +    my $newdata = "";
  +    my $in_comment = 0;
  +    my $eol_comment = 0;
  +    for (my $i = 0; $i <= $#data_tokens; $i++) {
  +             my $token = $data_tokens[$i];
  +             if ($token =~ /^[A-Za-z]/) {
  +             if ($eol_comment || $in_comment) {
  +                             # Currently in a comment, don't LXRify.
  +                             $newdata .= $token;
  +             } elsif ($token eq "nbsp" || $token eq "quot" || $token eq 
"amp" ||
  +                     $token eq "lt" || $token eq "gt") {
  +                             # HACK - ignore potential HTML entities.  This 
needs to be
  +                             # done in a smarter fashion later.
  +                             $newdata .= $token;
  +             } else {
  +                             $newdata .= $self->lxr_ident($token);
  +             }
  +             } else {
  +             $newdata .= $token;
  +             $token =~ s/(\s|&nbsp;)//g;
  +         
  +             # Check if we are entering or exiting a comment.
  +             if ($token =~ /\/\//) {
  +                             $eol_comment = 1;
  +             } elsif ($token =~ /\*+\//) {
  +                             $in_comment = 0;
  +             } elsif ($token =~ /\/\*/) {
  +                             $in_comment = 1;
  +             }
  +             }
  +    }
  +
  +    return $newdata;
  +}
  +
  +1;
  
  
  
  
  
  Index: ViewTopic.pm
  ===================================================================
  RCS file: 
/cvsroot/codestriker/codestriker/lib/Codestriker/Action/ViewTopic.pm,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- ViewTopic.pm      13 Mar 2008 22:39:07 -0000      1.59
  +++ ViewTopic.pm      11 Jun 2008 12:00:31 -0000      1.60
  @@ -239,7 +239,7 @@
   
       my $delta_renderer =
        Codestriker::Http::DeltaRenderer->new($topic, [EMAIL PROTECTED], [EMAIL 
PROTECTED], $query,
  -                                           $mode, $brmode, $tabwidth);
  +                                           $mode, $brmode, $tabwidth, 
$repository);
   
       # Set the add general comment URL.
       $vars->{'add_general_comment_element'} =
  
  
  
  
  
  Index: ViewTopicFile.pm
  ===================================================================
  RCS file: 
/cvsroot/codestriker/codestriker/lib/Codestriker/Action/ViewTopicFile.pm,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- ViewTopicFile.pm  14 Mar 2008 01:30:52 -0000      1.14
  +++ ViewTopicFile.pm  11 Jun 2008 12:00:31 -0000      1.15
  @@ -137,7 +137,7 @@
       my $delta_renderer =
        Codestriker::Http::DeltaRenderer->new($topic, [EMAIL PROTECTED],
                                              [EMAIL PROTECTED], $query,
  -                                           $mode, $brmode, $tabwidth);
  +                                           $mode, $brmode, $tabwidth, 
$repository);
       $delta_renderer->annotate_deltas();
   
       my $vars = {};
  
  
  
  
  
  Index: index.html
  ===================================================================
  RCS file: /cvsroot/codestriker/codestriker/html-docs/index.html,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- index.html        7 Aug 2006 01:52:32 -0000       1.36
  +++ index.html        11 Jun 2008 12:00:32 -0000      1.37
  @@ -67,7 +67,7 @@
                     under the GPL.
                   </p>
                <p>
  -              <a 
href="http://codestriker.sourceforge.net/cgi-bin/codestriker.pl?topic=7063366&amp;action=view";>View</a>
  +              <a 
href="http://codestriker.sourceforge.net/cgi-bin/codestriker.pl?topic=7759043&amp;action=view";>View</a>
                 an example code review, <a 
href="http://codestriker.sourceforge.net/cgi-bin/codestriker.pl";>list</a>
                    open topics, 
                 read the <a href="codestriker.html">manual</a>,
  
  
  

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Codestriker-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/codestriker-commits

Reply via email to