easysloc

by Martin Monperrus

easysloc is a C/C++ logical lines of code counter (LLOC). It uses an intuitive and clear definition of a logical line of code for C/C++ :
the number of instructions with the semantic delimiter ";" (see Fenton 1991, p246-253)

Additionnally easysloc gives you the number of comments.
// is one comment
/* *foo* */ is one logical and physical comment
/* this is
another comment */ is one logical comment and two physical comments

Download the source code of easysloc


Related tools

CodeCount / CCCC / LOCC / SLOCCount

Compared to these tools, easysloc satisfies all the following conditions:
* easysloc gives the number of _logical lines of code_;
* easysloc provides the definition used for a logical line of code;
* easysloc's source code can be easily reviewed;
* easysloc is designed to be integrated via command line interface, see below.

easysloc is able to measure the linux kernel:
* linux kernel 2.0.27 : 206531 logical lines of code (http://www.kernel.org/pub/linux/kernel/v2.0/linux-2.0.27.tar.bz2)
* linux kernel 2.6.19 : 1987933 logical lines of code (x 9.6 !)

Usage


Compilation :
$ gcc -o easysloc easysloc.c

$ cat myfile.c | easysloc

$ cat myfile.cpp | easysloc

$ cat myfile1.c myfile2.c myfile3.c| easysloc

$ for i in *.cpp; do echo -n "$i "; cat $i | easysloc ; done

$ for i in `find . -iname "*.c"`; do echo -n "$i "; cat $i | easysloc ; done

Warning: you should not use these two below because a syntactic error in one file could have hard consequences on others, please use the command line above instead.
$ cat *.cpp | easysloc
$ cat `find . -iname "*c"` | easysloc

= A powerful usage =

# this prints the result for each file and computes the total
$ for i in `find . -iname "*.c"`;
do
echo -n "$i ";
cat $i | easysloc ;
done \
| awk 'BEGIN{n1=0;n2=0;} {print $0;n1=n1+$2; n2=n2+$3; } END{print "Total",n1,n2;}' \
| sort -n -k 2

Tailed output for coreutils-6.7:

./src/stty.c 464 151
./src/csplit.c 511 221
./lib/fts.c 516 420
./src/tail.c 530 262
./src/tr.c 621 375
./src/od.c 667 273
./src/ptx.c 670 594
./lib/regex_internal.c 671 181
./src/pr.c 835 850
./src/sort.c 929 432
./lib/getdate.c 973 568
./src/ls.c 1346 723
./lib/regcomp.c 1378 511
./lib/regexec.c 1580 541
Total 31822 21301

Coreutils-6.7 has 31822 logical lines of code and 21301 comments.

(C) 2006-2007 Martin Monperrus
Don't hesitate to contact me
Tagged as: