Counting Ada SLOC, Comments, and Blank Lines
There are probably as many different ways to generate these measures as
there are programmers. However, if it is useful, feel free to use the
following quick & dirty Perl script that generates these measures. It
produces comma delimited data that is easily imported into a spreadsheet.
The downside is that it requires the a Perl interpreter available(for
free) from http://www.activestate.com/ or http://www.cpan.org/
Hope it is helpful
#--------------------------------------------------------------------
# adasloc.pl Christopher Moore csmoore@acm.org
#
# a script for counting Ada SLOC, Comment, & Blank Lines
#
# usage: perl adasloc.pl > sloc.csv
#
# once the comma delimited output is captured to a file, it can then be
# used in a spreadsheet program like Excel
#
#--------------------------------------------------------------------
@file_list = <*.ada *.adb *.ads>; #match the normal ada file extensions
print "#, FILENAME, Total, SLOC, CLOC, Blank, Subroutines\n";
$count = 0; # count the number of source files read
foreach $file (@file_list)
{
# for every ada source file in the current directory
open(MYINPUTFILE, $file);
$comment_lines = 0;
$sloc_lines = 0;
$blank_lines = 0;
$subroutine_count = 0;
while(<MYINPUTFILE>)
{
$line = $_;
if ($line =~ /^\s*--/)
{
$comment_lines++;
} # end if
elsif ($line =~ /^\s$/)
{
$blank_lines++;
}
else
{
$sloc_lines++;
if ($line =~ /^\s*procedure/i) # ignore case look for "procedure"
{
$subroutine_count++;
}
elsif ($line =~ /^\s*function/i) # ignore case look for "function"
{
$subroutine_count++;
}
} # end if/else
} # end while
$count++;
$total = $sloc_lines + $comment_lines + $blank_lines;
print "$count, $file, $total, $sloc_lines, $comment_lines,
$blank_lines, $subroutine_count\n";
close(MYINPUTFILE);
}
Contributed by: Christopher Moore
Contributed on: May 26, 1999
License: Public Domain
Back