Kodama's home / tips.

Line Of Code(LOC) for Sather.

GNU/Sather の loc カウンタ. コメント, 空行 等を除いたコ−ド行数を数え, ファイル名, テキストの行数, loc数 を表示する. 規模測定用に, 大まかにコ−ディングの統計をとるために作った.

単純な shell スクリプトなので, ソ−スの改行の入り方が変わると多少計数が変わってしまうが, もともと loc の定義次第で, 数値が大幅に変わるので あまり細かく気にしても無意味なのだ.

同じ理由で, 他人のloc 数や, 他言語の loc 数との直接の比較はあまり役に立たない. 同じ言語, 同じ分野の課題, 同じコ−ディング標準, 同じ測定ツ−ルで計数するように状況をそろえるなら, ほぼそのまま比較できるが, それ以外の状況では定性的な比較や考察に使うのが良いだろう.

使用例:

$ loc-sather.sh local_lib/*sa
local_lib/bitset.sa 32 23
local_lib/bitset_int.sa 38 18
local_lib/braid.sa 416 266
.....略
local_lib/test_polys.sa 203 151
local_lib/word.sa 233 112
total 7581 4408

shell スクリプト.

#! /bin/sh 
# count text line and LOC(Line Of Code) for Sather.

total_loc=0
total_l=0

for a in $@ ; do

num_l=`wc $a|gawk '{print $1}'`

num_loc=`
cat $a|gawk '
{
gsub(/--.*/,""); # comment
gsub(/\".*\"/,"string"); # string
gsub(/;/,";\n")
print
}
'|gawk '
{
gsub(/end;/,"");
gsub(/then/,"");
gsub(/else/,"");
gsub(/elsif/,"");
gsub(/[ \t]+/," ");
}
/^[;\t ]*$/{next} # empty line is excluded 
/;/{print }
' |wc|gawk '{print $1}'`

echo $a $num_l $num_loc

total_l=`expr $total_l + $num_l`
total_loc=`expr $total_loc + $num_loc`

done
echo "total "$total_l" "$total_loc

# end #

Kodama's home / tips.