From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bd391ba8c7361d92 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-02-28 10:41:20 PST Newsgroups: comp.lang.ada Path: nntp.gmd.de!stern.fokus.gmd.de!ceres.fokus.gmd.de!zib-berlin.de!fu-berlin.de!zrz.TU-Berlin.DE!netmbx.de!unlisys!news.maz.net!news.ppp.de!xlink.net!howland.reston.ans.net!cs.utexas.edu!uwm.edu!news.alpha.net!news.mathworks.com!newshost.marcam.com!charnel.ecst.csuchico.edu!olivea!hal.COM!decwrl!enews.sgi.com!wdl1!dst17!mab From: mab@dst17.wdl.loral.com (Mark A Biggar) Subject: Re: A tool to count lines in Ada programs Message-ID: <1995Feb28.184120.14550@wdl.loral.com> Sender: news@wdl.loral.com Organization: Loral Western Development Labs References: <3hq8pb$ah7@Starbase.NeoSoft.COM> <3iad84$meq@butch.lmsc.lockheed.com> <1995Feb27.232339.9254@eisner> Date: Tue, 28 Feb 1995 18:41:20 GMT Date: 1995-02-28T18:41:20+00:00 List-Id: 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