AdaPower Logged in as Guest
Ada Tools and Resources

Ada 95 Reference Manual
Ada Source Code Treasury
Bindings and Packages
Ada FAQ


Join >
Articles >
Ada FAQ >
Getting Started >
Home >
Books & Tutorials >
Source Treasury >
Packages for Reuse >
Latest Additions >
Ada Projects >
Press Releases >
Ada Audio / Video >
Home Pages >
Links >
Contact >
About >
Login >
Back
Ada Utilities - adasloc.pl
Utilities for Ada Programming

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

}


(c) 1998-2004 All Rights Reserved David Botton