Menu

#125 Support for additional option

v1.65
open
nobody
None
1
2019-10-31
2016-10-13
Anonymous
No

Hello,
Thanks you developing this cloc tool.
As many would agree, it's very useful and surprisingly simple to use.

I would like to request support for additional option even though it has many options.
The option I suggest and its example are as below.

  • Excluding the brace('{', '}') from cloc, loc when it is used alone in common with a blank.

example)
If a new function is added as below, the cloc is 4 in current cloc tool.
void new_function()
{
int a;
}
But, if it is applied by new option, the value is 2. Because two braces are excluded.
For another example, If the brace is not used alone, it is included in cloc.
So cloc for the below code becomes 3.
void new_function()
{ int b;
int a;
}

If possible to support this feature, please let me know how long it will take.
Thank you.

Best regard,
Eungju Lee.

Discussion

  • Al Danial

    Al Danial - 2016-10-14

    (Note: cloc is now developed at https://github.com/AlDanial/cloc; in the future please open issues there)

    This is an interesting request because I understand your motivation--lines with just braces don't contribute a lot of "code"--but at the same time I'm not really keen to implement an option to ignore them. For starters I'd have to implement a new counter for "ignored" lines in addition to the current counts for "blank", "code", and "comment". That's a big undertaking.

    Nonetheless, to answer "how long will it take", the answer is actually just a few minutes--for you. You can make cloc treat { and } lines as comments by adding your own language filter. First, dump the existing language definitions using the --write-lang-def switch as explained at https://github.com/AlDanial/cloc#custom_lang

    Next, edit the file that was written (eg my_definitions.txt or lang.txt or whatever you chose) and add this line
    filter remove_matches ^s[{}]\s$
    below the languages you want this applied to (eg C, C++, C#, Java, JavaScript, etc).

    Last, invoke cloc with the switch
    --force-lang-def lang.txt
    to have it read your custom definition. With this, lines with only { and } are counted as comment lines.

     
  • Anonymous

    Anonymous - 2019-10-31
    Post awaiting moderation.

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.