Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[dsdp-pmc] How to count lines of code

Hello,

some time ago we had an E-Mail conversation how to count lines of code.
We didn't quite come up with a good solution - taking sloccount for now.

But sloccount by DWheeler has the disadvantage that it does not count comments, XML files, build driver files, property files etc. - all of which are result of creative work and should thus be counted in the spirit of Eclipse, if we want to get an indication for how much IP is in some contribution.

I think that I have recently come up with something useful. It works fine on Linux and Cygwin:

# Count lines of code in a contribution supplied as archive:
# First extract it, then cd to the toplevel directory, then:
# Cat all non-binary files, suppress empty lines, then count lines
find . -type f | egrep -iv '\.(gif|png|jpg|exe|dll|so|a|o|obj|tar|gz|jar|zip)$' | xargs cat | egrep -v '^[^a-zA-Z0-9_/*;,.:#<>(){}=+-]*$' | wc -l

# Count lines of code in a contribution that is submitted as a patch
# Cat all lines that were added inthe patch, suppress filename specifiers and empty lines grep '^[+]' patch.txt | grep -v '^[+][+]' | egrep -v '^\+[^a-zA-Z0-9_/*;,.:#<>(){}=+-]*$' | wc -l

HTH,
Martin



Back to the top