I don't have any quick solutions, but there are two problems with this one:
1)a comment ends with a semicolon is counted as a sloc
2)a semicolon does not necessarily have to be the last character of the line.  There could be anything else after it.
3)someone else mentioned that function specs use semicolon as the arg separator.  Do we consider this a sloc for every semicolon in the line?


Here is a perl script non-comment code line counter.  IT IS NOT A SLOC line counter, but it could be modified to make it so.

to use it:
# perl linecount.pl c:\whereyourcodesubdirsare c:\whereyouwanttheresultfile
$SourceDir = $ARGV[0];  #directory to count in
$fileResult = $ARGV[1]; #result file

#open the results file
open (RESULTFILE, ">$fileResult");

# create a list of files to open
system("dir /s/b $SourceDir\\*.adb >c:\\dir.txt");
system("dir /s/b $SourceDir\\*.ads >>c:\\dir.txt");

#open the file containing the list
open(FILELIST, "c:\\dir.txt");

#for every file in filelist
$totalCodeLineCount = 0;
$totalCommentLineCount = 0;
while( <FILELIST> )
{
    chop;
    $filename = $_;
    #open the file
    open(THEFILE , $filename);
    $CodeLineCounter = 0;
    $CommentLineCounter = 0;
    while(<THEFILE>)
    {
         if (/\s*--/)
         {
                 $CommentLineCounter = $CommentLineCounter + 1;
         }
         else
         {
                 $CodeLineCounter = $CodeLineCounter + 1;
         }
    }
    close(THEFILE);

    $totalModuleCount = $CodeLineCounter + $CommentLineCounter;
    print RESULTFILE "$filename:  $CodeLineCounter code: $CommentLineCounter comment: $totalModuleCount Module\n";

    $totalCodeLineCount = $totalCodeLineCount + $CodeLineCounter;
    $totalCommentLineCount = $totalCommentLineCount + $CommentLineCounter;
};

print RESULTFILE "\nTOTAL number of code lines: $totalCodeLineCount\n";
print RESULTFILE "\nTOTAL number of comment lines: $totalCommentLineCount\n";
$totalFinal = $totalCodeLineCount + $totalCommentLineCount;
print RESULTFILE "\nFinal TOTAL number lines: $totalFinal\n";

#close the filelist
close(RESULTFILE);

--
Santé bonheur!

David Marceau
Analyst/Programmer - Firepower Systems
Land Software Engineering Centre - DND Canada
[log in to unmask]
613.995.1126



-----Original Message-----
From: Greg Bek [mailto:[log in to unmask]]
Sent: Tuesday, October 12, 1999 1:07 PM
To: [log in to unmask]
Subject: Re: Location of Free SLOC Counter


My favourite is this awk script, typically driven from the C-shell
script that follows it:

#!/bin/awk  -f

BEGIN           { cmnt = 0; nblnk = 0; blnk = 0; semi = 0; }

/^[ \t]*--/     { cmnt++; next; }
/^[ \t]*$/      { blnk++; next; }
/;$/            { semi++; next; }
                { nblnk++; next; }

END             {
                  printf("Comment lines:   %5d\n", cmnt);
                  printf("Blank lines:     %5d\n", blnk);
                  printf("Semicolon lines: %5d\n", semi);
                  printf("Other lines:     %5d\n", nblnk);
                  printf("-----------------------\n");
                  printf("Total lines:     %5d\n", cmnt+blnk+semi+nblnk);
                }


#! /bin/csh -f
#
# Command file to count lines in: ada units and or views
#
set sloc_counter = "~/bin/sc"
set usage = "Usage: $0 [-v] <file_list>"
#
# Check for verbosity
#
if ( $1 == -v ) then
  shift
  set verbose
endif
#
# Check number of arguments
#
if ( $#argv < 1 ) then
  echo "$usage"
  exit 1
endif

# Loop for each arg
foreach file ( $* )

  if ( -e $file ) then

#only get here if the 'object' exists

    if ( -f $file && $file =~ *.ada ) then
      echo $file
      $sloc_counter $file
    else
       if ( -d $file ) then
           echo "Totals for directory $file"
#
# Don't iterate over all files, instead give a total
#          find $file -name '*.ada' -print -exec $sloc_counter {} \;
#
           $sloc_counter $file/*.ada
       else
          echo "$file is not an Ada unit or a directory name"
       endif
    endif
  else
    echo "$file doesn't exist"
  endif


end