--
Raymond H. Chui | Democracy is not a way of getting better
NSWC N55 | solutions.
10901 New Hampshire Ave. |
Silver Spring, MD 20903-5640 | It's just a way to spread the blame.
U.S.A. |
Voice:1-301-394-3807 Ext. 45 |
Fax:1-301-394-4483 |
E-Mail:rchui%tet...@relay.nswc.navy.mil
Or rc...@tethys.nswc.navy.mil
_ __ _ , __
' ) ) / ' ) / / ) /
/--' __. , , ____ ______ __/ /--/ / /_ . . o
/ \_(_(_(_/_/) ) )_(_) /) )_(_(_ / ( o (__/ / /_(_/_(_
/
/
I thought we had agreed that counting Lines of Code was stupid (see
the L.O.C. thread).
If you really want to do this (disregard empty lines and wordy
comments) why not simply do "ls -l file.o"?
--
Miguel Carrasquer ____________________ ~~~
Amsterdam [ ||]~
m...@inter.NL.net ce .sig n'est pas une .cig
>Hey, dudes:
> Does anybody out there knows how to count the number of
>executable lines in a C/C++ program.
Do CPP on the file first, then count the number of lines with the filename
before the first colon, and something after it. (Works on a PC). CPP strips
out all the comments and #defines, etc, and leaves the raw code + header files.
Bob
|> Does anybody out there knows how to count the number of
|> executable lines in a C/C++ program. Is there any public domain
|> software program or commercial software program does this job?
|> Because the Unix "wc -l filename" command only give me the number
|> of lines. I want to count number of executable lines, ignore all
|> the comment lines, empty lines. But some programmer written more
|> than two executale lines in one line separated by semicolon.
|> One question is will be the "{" and "}" also counting for one line?
|> I guess not.
|> Please do not just do the follow-up, also reply by email because
|> I don't have too much time to read the USEnet newsgroups.
|> Thank you in advance!
I've used different variants of egrep and/or tr piped to wc at
different times. The simplest:
egrep '[;}' $* | wc - l
This counts any line containing a `;' or an '}'. It gives a (very)
rough estimation of the number of statements. Alternatively:
tr -cd '[;}]' | wc -c
counts the actual number of `;' and `}' (under System V, check your
manual for the exact syntax of tr).
With just a little more effort, you can write a lex script which not
only counts statements, but also comments, empty lines, etc. and
outputs various program statistics (per cent comments, average no. of
lines in function, etc.). I find this a lot more useful than just
counting lines.
--
James Kanze email: ka...@lts.sel.alcatel.de
GABI Software, Sarl., 8 rue des Francs Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung
| I've used different variants of egrep and/or tr piped to wc at
| different times. The simplest:
|
| egrep '[;}' $* | wc - l
There's no need to pipe to wc. Use egrep's -c option:
egrep -c '[;}' $*
though I think James must have meant '[;}]' with a closing bracket.