From: mab@dst17.wdl.loral.com (Mark A Biggar)
Subject: Re: A tool to count lines in Ada programs
Date: Tue, 28 Feb 1995 18:41:20 GMT
Date: 1995-02-28T18:41:20+00:00 [thread overview]
Message-ID: <1995Feb28.184120.14550@wdl.loral.com> (raw)
In-Reply-To: 1995Feb27.232339.9254@eisner
Attached is a perl script I wrote a while back to count Ada LOC
-----------cut here--------
#!/bin/sh
# shar style archive throw away everything above cut mark and run through sh
sed 's/^X//' >adaloc <<'EEEOOOFFF'
X#!/usr/local/bin/perl
X#
X# aloc Ada line of code counter
X#
X# Rules:
X#
X# total lines is newline count
X# comment lines are blank or just have comment text
X# physical lines have syntactic substance
X# logical lines correspond to Ada statements and declarations
X#
X# logical lines is the count of the number of semicolons
X# outside of strings or comments
X
X$file = $ARGV[0]; # save file name for reports
X($plines,$clines,$tlines,$llines) = (0,0,0,0);
X # zero out counters
X#physical lines
X# comment lines
X# total lines
X# logical lines
X
Xwhile (<>) { # read all input lines
X# print ">>$_<<\n"; # uncomment for debug printout
X s/^\s+//; # strip off leading white space
X $_ eq '' && next; # current line empty goto next
X /^--/ && next; # comment go do next line
X s/^("[^"]*")+// && do { # token is a " string
X $slines++; # line has substance
X redo; # go do next token
X };
X s/^(''''|'[^']')// && do { # token is a ' string
X $slines++; # line has substance
X redo; # go do next token
X };
X s/^;// && do { # token is a ;
X $slines++; # it has substance
X $llines++; # count logical line
X redo; # go do next token
X };
X s/^[^\s-"';]+// && do { # all other characters
X $slines++; # have substance
X redo; # go do next token
X };
X} continue { # next line processing
X $tlines++; # count line in total
X if ($slines) { # if line had substance
X $plines++; # count as physical
X } else {
X $clines++; # otherwise comment
X }
X $slines = 0; # reset substance flag
X if (eof) { # if we just processed the last
X # line of an input file
X &report($plines,$clines,$tlines,$llines);
X # generate report
X $pl += $plines; # add counts to grand totals
X $cl += $clines;
X $tl += $tlines;
X $ll += $llines;
X ($plines,$clines,$tlines,$llines) = (0,0,0,0);
X # zero counts for next file
X $file = $ARGV[0]; # save name of next file
X $nfiles++; # count next file
X }
X# printf "%d %d %d %d\n",$plines,$clines,$tlines,$llines;
X # uncomment for debug output
X}
Xif ($nfiles > 1) { # if more then one file
X print "Total for all files:\n"; # generate totals report
X write;
X}
X
Xsub report { # generate report
X local($pl,$cl,$tl,$ll) = @_;
X print "File: ",$file,"\n";
X write;
X}
X# report output format
Xformat STDOUT =
X Physical lines @>>>>>>>>
X $pl
X Comment lines @>>>>>>>>
X $cl
X Total lines @>>>>>>>>
X $tl
X Logical lines @>>>>>>>>
X $ll
X.
EEEOOOFFF
exit
next prev parent reply other threads:[~1995-02-28 18:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <3hnv6a$i96@vbohub.vbo.dec.com>
1995-02-24 22:21 ` A tool to count lines in Ada programs Elgar the Idiot aka Chris Warwick
[not found] ` <3hq8pb$ah7@Starbase.NeoSoft.COM>
[not found] ` <3i8gsl$npt@gnat.cs.nyu.edu>
1995-02-23 14:24 ` Larry Kilgallen, LJK Software
[not found] ` <1995Feb15.073335.29411@sei.cmu.edu>
[not found] ` <3i0pss$q14@gnat.cs.nyu.edu>
1995-02-24 14:58 ` DEAN RUNZEL
1995-02-26 23:32 ` Richard Crutchfield
[not found] ` <3iad84$meq@butch.lmsc.lockheed.com>
1995-02-28 4:23 ` Larry Kilgallen, LJK Software
1995-02-28 18:41 ` Mark A Biggar [this message]
[not found] <3hokkj$dsa@news.rain.org>
[not found] ` <3hqtue$ikb@newsbf02.news.aol.com>
1995-02-28 22:12 ` Ellis Hardin
1995-03-01 11:46 ` Richard Crutchfield
1995-03-01 16:08 ` Ellis Hardin
1995-03-02 4:59 ` Larry Kahn
1995-03-03 12:43 ` Michael A. Cico
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox