[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: Source code Statistics...

Well, this does not seem very difficult to implement. Most of these
requirements can be individually handled by standard unix utilities scripts or
small programs (divide & conquer). Here is my toss at the problem  -

Arvind Devarajan wrote (arvindd@xxxxxxxxxxxx):
> does anyone here know about a tool in linux which gives me statistics 
> about a development project:
> 1. No. of lines in a file (sorry, no cat file.c | wc -l and 
> the like please)
I think that you mean is the num of non-blank lines here (I don't know what
else you could mean by the above statement, it's self-contradictory!) try -
    awk 'NF>0 {count++} END {print count}' foo.c bar.c

> 3. No. of c files in the project
> 4. No. of header files in the project
Surely find(1L) with some decent query flags can fix this need. How about -
    find . -name \*.c | wc -l
or the likes.
Of course you could also poke around the Makefile (or whatever you use to
build your source).

> 2. No. of un-commented lines in the file
Have a look at "Lex and Yacc" 2nd Ed by John R Levine et al, Oriley. There is
a 20 line lex example in the book (end of chapter 1) which counts the number
of lines of code (however you define it). You can probably find the example
code somehwere on oriley's website.

A side note, counting the number of lines-of-code (LOC) is messy. There are
many ways to do it and you really have to know what you want.

> 5. No. of global variables in the project
You could use lex again and do it along with the previous item. But if you
have object files around, the easiest thing is just to use nm(1) and peek at
the symbols listed in the object files. "The Awk Programming Language" -
Kernighan Aho Weinberger, has a neat 3 line awk script that extracts such info
from nm output (and some pretty good reasons for doing so).

> 6. And host of other useful information...
Wishfull thinking! :)

- Raja

PS: If you want more info or want me to dig up those examples I keep
mentioning, email me off-line.