View previous topic :: View next topic |
Author |
Message |
correctclick n00b
Joined: 18 Jul 2002 Posts: 71
|
Posted: Tue Jan 21, 2003 9:32 pm Post subject: generic line counting tool for programming |
|
|
Hi. I have a directory structure with a whole bunch of php source files and I want to count the lines. I've fooled around with grep -crh "\n" website_directory, but I just get a long string of numbers. This could of course be fixed with relatively simple script, but I figured there must be some general purpose tool for doing this.
What do people use to count lines in various programming languages? |
|
Back to top |
|
|
Naan Yaar Bodhisattva
Joined: 27 Jun 2002 Posts: 1549
|
Posted: Tue Jan 21, 2003 9:40 pm Post subject: |
|
|
wc?
Code: |
wc -l `find -name '*.php'`
|
or
Code: |
find -name '*.php' -exec wc -l {} \; | sort +0n
|
if you want a sorted list without a total. |
|
Back to top |
|
|
Tarball Tux's lil' helper
Joined: 19 Jun 2002 Posts: 142 Location: Cheshire, UK
|
Posted: Tue Jan 21, 2003 9:42 pm Post subject: |
|
|
This task is very open to interpretation as to what you consider a line of code to be. The following is a lump of Perl code I wrote to give me a *rough* idea of the number of lines of C code I have. Basically, it filters out lines that are comments and looks for the usage of keywords. This was something I knocked together very quickly (5 mins) so it is only intended to give a ball-park figure.
Code: |
#!/usr/bin/perl -w
$lines_of_code = 0;
while(<ARGV>)
{
$in_comment = rindex($_, "/*") > rindex($_, "*/");
if( ! $in_comment )
{
if( /;/ ) { $lines_of_code++ ; next ; }
if( /if/ ) { $lines_of_code++ ; next ; }
if( /while/ ) { $lines_of_code++ ; next ; }
if( /include/ ) { $lines_of_code++ ; next ; }
if( /define/ ) { $lines_of_code++ ; next ; }
if( /switch/ ) { $lines_of_code++ ; next ; }
if( /case/ ) { $lines_of_code++ ; next ; }
if( /struct/ ) { $lines_of_code++ ; next ; }
if( /\(.*\)/ ) { $lines_of_code++ ; next ; }
if( /\[.*\]/ ) { $lines_of_code++ ; next ; }
if( /union/ ) { $lines_of_code++ ; next ; }
if( /do/ ) { $lines_of_code++ ; next ; }
}
}
print $lines_of_code . " lines of code\n";
|
|
|
Back to top |
|
|
correctclick n00b
Joined: 18 Jul 2002 Posts: 71
|
Posted: Tue Jan 21, 2003 9:49 pm Post subject: |
|
|
thanks for the quick replies. The wc thign worked great.
For anyone who knows:
what is a line of code defined as "in the industry"? A newline character? Semicolins? |
|
Back to top |
|
|
mmealman Guru
Joined: 02 Nov 2002 Posts: 348 Location: Florida
|
Posted: Tue Jan 21, 2003 9:53 pm Post subject: |
|
|
I'm
guessing
it's
any
line
with
a
\n
Wish
I
got
paid
by
the
line. |
|
Back to top |
|
|
|