swonk@ccicpg.UUCP (Glen Swonk) (08/10/89)
Does anyone have a program or a method of determing the number of C source lines in a source file? My assumption is that comments don't count as source lines unless the comment is on a line with code. Are there any other tools to measure the complexity of a source file? thanks -- Glenn L. Swonk CCI Computers (714)458-7282 9801 Muirlands Boulevard Irvine, CA 92718 uunet!ccicpg!swonk
carver@trsvax.UUCP (08/12/89)
> Does anyone have a program or a method of determing > the number of C source lines in a source file? > My assumption is that comments don't count as source > lines unless the comment is on a line with code. Try using the friendly UNIX 'awk' program and do a search for ';' and '}'. This seemed to work very well for a project I had in school. In addition, you can search for comments, blank lines, declarations of variables, ect, and come up with a few good measurements of complexity like percentages of statements vs. total lines and the like. Of course, all of this is for naught if you aren't in a UNIX envirnment. Hope this helps. David "carver" Forney --------------------------------------------------------------------- DISCLAIMER: All of the views expressed are my own and do not necessarily reflect those of my employer.
decot@hpisod2.HP.COM (Dave Decot) (08/14/89)
# cloc - count lines of code for i in $* do blanklines=`grep "^[ ]*$" $i | wc -l` loc=`sed -e "s/^#.*/k/" $i | /lib/cpp | sed -e "/^[ ]*$/d" -e 1d | wc -l` alllines=`cat $i | wc -l` commentlines=`echo $alllines - $blanklines - $loc | bc` echo $i \ CODE $loc \ COMMENTS $commentlines \ TOTAL $alllines done
kazua-u@ascii.JUNET (Kazuaki Ueno) (08/14/89)
In article <35120@ccicpg.UUCP> swonk@ccicpg.UUCP (Glen Swonk) writes: |Does anyone have a program or a method of determing |the number of C source lines in a source file? |My assumption is that comments don't count as source |lines unless the comment is on a line with code. | How about trying this: grep -v '^#[ ]*include' <filename> | /lib/cpp -P | grep -v '^[ ]*$' | wc -l ( Inside []'s are a SPACE and a TAB. ) You will get the number of 'effective' C source lines with this list of commands. Of course I do not care what you do with it. :-) -- Kazuaki Uyeno ASCII Corporation, Tokyo, Japan also a student of Univ. of Tokyo kazua-u@ascii.JUNET
jeffa@hpmwtd.HP.COM (Jeff Aguilera) (08/16/89)
Here's my offering: #!/bin/sh # # ncss: non commented source statements # { for file in $* do grep -v '^#' $file | /lib/cpp -P | rmnl | wc wc $file echo '' done } | awk ' NF == 3 { l1 += $1 w1 += $2 c1 += $3 } NF == 4 { l2 += $1 w2 += $2 c2 += $3 } { print } END { printf "%7d %6d %6d\tNoncommented\n", l1, w1, c1 printf "%7d %6d %6d\tCommented\n", l2, w2, c2 }' -