Menu

#241 Line number offset while browsing perl code

None
closed-invalid
nobody
None
5
2020-01-29
2009-03-27
farouk
No

Hi everybody

While browsing perl code (for example "apvsys" which is a sourceforge project) using Cscope, line numbers indicated in the cscope output does not match line numbers in the editor.

For perl it is systematic, but this can happen also while browsing C++ code.

Has any body already encountered this issue and has it already been solved.

Regards
Farouk

Discussion

  • farouk

    farouk - 2009-03-27

    Hi again

    I have investigated about the reason of this line number offset.

    It seems that when Cscope encounters the character sequence: "#<EOL>" , The line index is reduced by one.

    In examples below we are searching for SymLink reference
    ______________________________
    #
    #
    sub SymLink {
    my ( $from, $to ) = @_;
    print "Linking $to -> $from\n";
    symlink $from, $to;
    }

    ====> Cscope output : no result.
    _______________________________
    #
    #

    sub SymLink {
    my ( $from, $to ) = @_;
    print "Linking $to -> $from\n";
    symlink $from, $to;
    }

    ====> Cscope output : line 2.
    ________________________
    # Subroutine comments
    # over two lines
    sub SymLink {
    my ( $from, $to ) = @_;
    print "Linking $to -> $from\n";
    symlink $from, $to;
    }

    ====> Cscope output : line 3.
    __________________________
    # Subroutine comments #
    # over two lines
    sub SymLink {
    my ( $from, $to ) = @_;
    print "Linking $to -> $from\n";
    symlink $from, $to;
    }

    ====> Cscope output : line 2.

    Farouk

     
  • farouk

    farouk - 2009-03-27

    Hi again

    I have investigated about the reason of this line number offset.

    It seems that when Cscope encounters the character sequence: "#<EOL>" , The line index is reduced by one.

    In examples below we are searching for SymLink reference
    ______________________________
    #
    #
    sub SymLink {
    my ( $from, $to ) = @_;
    print "Linking $to -> $from\n";
    symlink $from, $to;
    }

    ====> Cscope output : no result.
    _______________________________
    #
    #

    sub SymLink {
    my ( $from, $to ) = @_;
    print "Linking $to -> $from\n";
    symlink $from, $to;
    }

    ====> Cscope output : line 2.
    ________________________
    # Subroutine comments
    # over two lines
    sub SymLink {
    my ( $from, $to ) = @_;
    print "Linking $to -> $from\n";
    symlink $from, $to;
    }

    ====> Cscope output : line 3.
    __________________________
    # Subroutine comments #
    # over two lines
    sub SymLink {
    my ( $from, $to ) = @_;
    print "Linking $to -> $from\n";
    symlink $from, $to;
    }

    ====> Cscope output : line 2.

     
  • Hans-Bernhard Broeker

    • labels: 388881 -->
     
  • Hans-Bernhard Broeker

    First, a reminder: please be aware that this program is cscope. It's not Perlscope, nor anylanguagescope. Using it on anything else but C source is not meant, nor particularly likely, to do anything useful.

    > In examples below we are searching for SymLink reference

    Search for it how, exactly? How did you build the database, and what were the options at query time?

    Is there any chance the linebreaks in the input files were the wrong ones for cscope?

     
  • farouk

    farouk - 2009-03-30

    Many thanks for your answer.

    Fist I had observed the issue on perl code projects. But we had also a ticket from a user working on a C++ project. As C projects are extra larges, and this issue seemed to happen randomly, I preferred first to investigate using perl code where the issue was almost assured.

    I made tests using a unique file project (see previous posts), and launched cscope-15.6 like follows:

    cscope -qu -i cscope.files

    And once more time like this

    cscope -i cscope.files

    Then, the command line interface was displayed. I searched for SymLink using "Find this C symbol" option. It gives the same results.

    I doubted first about linebreaks for files that are imported from windows. But applying the dos2unix tool does not improve things as long as the ‘#’ remained at end of line. File created within UNIX system are not excluded also.

    Regards.

     
  • farouk

    farouk - 2009-03-31

    Hi,

    I have investigated about our C code, and there may be like:

    //#########################################################

    They are used to separate or make visible parts of code. When they are not ended by a double slash ‘//’ this activate the bug.

    Such lines are used also to frame the license header in sources files.

    Thanks.

     
  • Hans-Bernhard Broeker

    > //#########################################################

    > They are used to separate or make visible parts of code. When they are not
    > ended by a double slash ‘//’ this activate the bug.

    Ahem, you mean it _begins_ with a double slash.

    The reason is still the same: cscope is neither meant to parse Perl, nor is it likely to be any good at it. The issue you're stumbling over is just one of many possible pitfalls: one language's

    #comment

    is the other's

    #preprocessor statement

    Putting random garbage in a C pre-processor instruction causes your troubles.

     
  • Hans-Bernhard Broeker

    • status: open --> closed-invalid
    • Group: -->
     

Log in to post a comment.