Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How To Count Number of Executable Lines

93 views
Skip to first unread message

Raymond Chui

unread,
Aug 4, 1994, 3:55:08 PM8/4/94
to
Hey, dudes:
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!

--
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 (__/ / /_(_/_(_
/
/

Miguel Carrasquer

unread,
Aug 4, 1994, 7:08:47 PM8/4/94
to
In article <1994Aug4.1...@relay.nswc.navy.mil>,

Raymond Chui <rc...@tethys.nswc.navy.mil> wrote:
>Hey, dudes:
> 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.

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

The Hummingbird

unread,
Aug 7, 1994, 1:47:05 AM8/7/94
to

>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

James Kanze US/ESC 60/3/164 #71425

unread,
Aug 8, 1994, 1:51:31 PM8/8/94
to

|> 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

David W. Tamkin

unread,
Aug 8, 1994, 4:16:35 PM8/8/94
to
ka...@us-es.sel.de (James Kanze US/ESC 60/3/164 #71425) wrote in
<KANZE.94A...@slsvhdt.us-es.sel.de>:

| 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.

0 new messages