Menu

#9 Help with lang filter definition

v1.61
pending
nobody
None
1
2014-03-31
2014-03-28
Anonymous
No

I have a source code as following:

const SWORD table[10] =
{
/* cmt */ A=B;
/* cmt */ X=Y;
/* cmt1,
cmt2 */
} /*
cmt1,
cmt2 */;

When I use cloc to count, it shows 5 LOCs.However, it should be 3 LOCs only (which are:const SWORD table[10] =, A=B;, and X=Y;)
Are there any ways to solve this problem?Can it be solved by using lang filter?Thank you.

Discussion

  • Al Danial

    Al Danial - 2014-03-28

    cloc counts any non-commented, non-blank line as being a line of code. Therefore your lines of { and } are counted as code. The following language definitions for C, C#, C++, and C header files will count lines of just { or } as comments rather than code (there is not a way to simply ignore { or } ):

    C
        filter remove_matches ^\s*//
        filter call_regexp_common C
        filter remove_inline //.*$
        filter remove_matches ^\s*[{}]\s*$
        extension c
        extension ec
        extension pgc
        3rd_gen_scale 0.77
        end_of_line_continuation \\$
    C#
        filter remove_matches ^\s*//
        filter call_regexp_common C
        filter remove_inline //.*$
        filter remove_matches ^\s*[{}]\s*$
        extension cs
        3rd_gen_scale 1.36
        end_of_line_continuation \\$
    C++
        filter remove_matches ^\s*//
        filter remove_inline //.*$
        filter call_regexp_common C
        filter remove_matches ^\s*[{}]\s*$
        extension C
        extension cc
        extension cpp
        extension cxx
        extension pcc
        3rd_gen_scale 1.51
        end_of_line_continuation \\$
    C/C++ Header
        filter remove_matches ^\s*//
        filter call_regexp_common C
        filter remove_inline //.*$
        filter remove_matches ^\s*[{}]\s*$
        extension H
        extension h
        extension hh
        extension hpp
        3rd_gen_scale 1.00
        end_of_line_continuation \\$
    
     
    • Anonymous

      Anonymous - 2014-03-31

      With this filter, I see that the ELOC is still 4 instead of 3. I think that it is caused by the semicolon in last line. Is there anyway to solve it?

       
  • Al Danial

    Al Danial - 2014-03-28
    • status: open --> pending
     
  • Anonymous

    Anonymous - 2014-03-31

    With this language definition, I see that the LOC is still 4 instead of 3. I think it is caused by semicolon (;) in the last line of source code. Is there any way to solve it? Thank you

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.