Recently, tonyg asked on comp.lang.ada for a code counter. There were a couple of recommendations, including gnat metric; however, my favourite is this shell script:
#!/bin/bash -f t=0 for f in $*; do n=`sed -e "s/\".*\"//" -e "s/--.*//" <$f | tr -Cd \; | wc -c` t=`expr $t + $n` echo "$f$n" done echo "total loc $t"
Quite close to line noise sense 3.
gnat metric does a whole lot more, which isn't surprising; on my current project,
$ gnat metric -P ../tools/tools.gpr ../tools/normalize_xmi*.ad?
results in
Line metrics summed over 37 units all lines : 4210 code lines : 2866 comment lines : 822 end-of-line comments : 1 comment percentage : 22.31 blank lines : 522 Average lines in body: 23.73 Element metrics summed over 37 units all statements : 830 all declarations : 811 logical SLOC : 1641 23 type declarations in 17 units 2 public subprograms in 2 units 101 subprogram bodies in 18 units Average cyclomatic complexity: 2.61
For comparison, the shell script above says the total [source] lines of code is 1587; close enough to gnat metric's "logical SLOC" for government work, I think.
I should add, I've no particular interest in measuring lines of code! who's counting, after all!
No comments:
Post a Comment