* Lines of code
@ 2001-03-13 6:14 dave.banham
2001-03-13 8:20 ` D-Man
0 siblings, 1 reply; 2+ messages in thread
From: dave.banham @ 2001-03-13 6:14 UTC (permalink / raw)
To: sourcenav
Does SN know how many lines of code it has scanned? If so, is it possible to
display this figure? (This would be a useful addition to the statistics window
in the project editor dialog.) Alternatively does any one know of a free tool
that will count the number of lines of code in a given set of files. SN reports
that my project has 950 (source) files (in many directories), so such a tool
must be easy to use.
Regards
Dave Banham
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Lines of code
2001-03-13 6:14 Lines of code dave.banham
@ 2001-03-13 8:20 ` D-Man
0 siblings, 0 replies; 2+ messages in thread
From: D-Man @ 2001-03-13 8:20 UTC (permalink / raw)
To: sourcenav
On Tue, Mar 13, 2001 at 02:17:56PM +0000, dave.banham@tde.alstom.com wrote:
|
| Does SN know how many lines of code it has scanned? If so, is it
| possible to display this figure? (This would be a useful addition to
| the statistics window in the project editor dialog.) Alternatively
| does any one know of a free tool that will count the number of lines
| of code in a given set of files. SN reports that my project has 950
| (source) files (in many directories), so such a tool must be easy to
| use.
|
What is a Line Of Code? Different people have different definitions
as to what should or should not be counted as a line. I wrote a very
simplistic counter in Python to count LOC for C++ code but it also
works for C and Java (anything that uses semicolons as a line
delimiter). It is simplistic since it uses a
number-of-semicolons-equals-LOC technique. It also doesn't ignore
comments. It you want it to report an astronomical LOC, put a lot of
semicolons in a comment, or just on any line.
If you are interested, here is the code :
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/usr/bin/env python
import string
import sys
from sys import argv
## define boolean values
true = 1
false = 0
#
# remove the name of the script from argv
argv.remove( argv[0] )
# look for command-line arguments
if ( argv.count( "-l" ) > 0 ) :
list_each = true
argv.remove( "-l" )
else :
list_each = false
if ( argv.count( "-d" ) > 0 ) :
# list all the files given as arguments and exit
argv.remove( "-d" )
for arg in argv :
print arg
sys.exit()
# check to see if any files were specified
if len(argv) == 0 :
print """You need to specify the names of the files to count as arguments on the command line.
Options:
-d display all the files being counted
-l display the loc count for each file
"""
sys.exit()
# now count
count = 0
for name in argv:
file = open( name, 'r' )
text = file.read()
file_count = string.count( text, ';' )
count = count + file_count
if ( list_each ) :
print name + ":\t", file_count
print
print "The count of lines (semicolons) is\t", count
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It is quite simple. Specify the files to count on the command line
and it will count them. It is ideal to run it from make since you
(probably) already have the list of files in the Makefile. (However
you will have to add the sums yourself if you use make recursively).
HTH,
-D
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-03-13 8:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-03-13 6:14 Lines of code dave.banham
2001-03-13 8:20 ` D-Man
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).