* program to count LOC
@ 1993-02-19 19:09 cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uwm.edu!cs.utexas.edu
0 siblings, 0 replies; 4+ messages in thread
From: cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uwm.edu!cs.utexas.edu @ 1993-02-19 19:09 UTC (permalink / raw)
I would like to know where I can get a program to Ada lines of code.
--
.- - - - - - - - - - - - - - - - - - - - - -.
| |
| Donna Oliver |
| Naval Surface Warfare Center |
| Dahlgren, VA 22448 |
| Phone: 703-663-4350 |
| |
| email: doliver@apssgi.nswc.navy.mil |
| |
`- - - - - - - - - - - - - - - - - - - - - -'
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: program to count LOC
@ 1993-02-20 1:15 Dave Bashford
0 siblings, 0 replies; 4+ messages in thread
From: Dave Bashford @ 1993-02-20 1:15 UTC (permalink / raw)
In article <1993Feb19.190953.12876@relay.nswc.navy.mil> doliver@apssgi.nswc.nav
y.mil (Donna Oliver) writes:
>I would like to know where I can get a program to Ada lines of code.
>
if you are running on Unix, the following command will count uncommented
semi-colons:
cat file | sed 's/--.*$//' | tr -cd ';' | wc -c
I'd be interested if anyone has a better definition of LSS (new
spelling of SLOC).
--
db
bashford@srs.loral.com (Dave Bashford, Sunnyvale, CA)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: program to count LOC
@ 1993-02-20 15:23 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!menudo.uh.edu!cl2.cl.uh.edu!
0 siblings, 0 replies; 4+ messages in thread
From: cis.ohio-state.edu!zaphod.mps.ohio-state.edu!menudo.uh.edu!cl2.cl.uh.edu! @ 1993-02-20 15:23 UTC (permalink / raw)
In article <1993Feb20.011537.16182@scf.loral.com>, bashford@srs.loral.com (Dave
Bashford) writes...
>In article <1993Feb19.190953.12876@relay.nswc.navy.mil> doliver@apssgi.nswc.na
vy.mil (Donna Oliver) writes:
>>I would like to know where I can get a program to Ada lines of code.
>>
>if you are running on Unix, the following command will count uncommented
>semi-colons:
> cat file | sed 's/--.*$//' | tr -cd ';' | wc -c
>
>I'd be interested if anyone has a better definition of LSS (new
>spelling of SLOC).
Be warned:
A_String_Declaration : String (1 .. 9) := "1 ; 2 ; 3";
will count as 3 non-literal semicolons using the above unix command.
Bill Fay --------------------------
University of Houston/Clear Lake --
-----------------------------------
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: program to count LOC
@ 1993-02-22 15:11 David Emery
0 siblings, 0 replies; 4+ messages in thread
From: David Emery @ 1993-02-22 15:11 UTC (permalink / raw)
As far as I am concerned, the "standard" way to count Ada lines of
code is with Bill Whitaker's classic "CAS" program, available from
SIMTEL-20 and other fine repositories near you.
Here is a version that's been modified to accept command-line parameters,
using the Verdix COMMAND_LINE package.
dave
---------------
package Lines_Of_Code is
type Lines is
record
AS : Natural; -- Ada statements
Cmnts : Natural; -- Comments
end record;
function LOC (FILE_NAME : STRING) return Lines;
--| Description
--| This function calculates the Ada statements and comments of a valid
--| Ada fragment specified by a FILE_NAME string parameter.
--| It need not be a complete compilation unit but it must have closed
--| all open parentheses and string delimiters.
--| The Ada statement is defined by a semicolon terminator
--| outside of comments, parentheses, or string or character literals
--| This definition is insensitive to formatting or layout of the source
--| William A. Whitaker WIS JPMO 3 March 1984
--| Modified rh 17 May 1986
--| emery 18 MAR 87
end Lines_Of_Code;
with text_io;
package natural_IO is new text_io.integer_io (natural);
with Lines_Of_Code; use Lines_Of_Code;
with Command_Line; use Command_Line;
with Text_IO; use Text_IO;
with Natural_IO; use Natural_IO;
procedure Count_Ada_Statements is
stmts_posn : Text_IO.positive_count := 35;
cmts_posn : Text_IO.positive_count := 50;
ls_posn : Text_IO.positive_count := 65;
line_len : positive := 79;
dashes : string(1..line_len) := (others => '_');
Usage : constant String := "Usage: cas file1 .. filen ";
type str_ptr is access string;
totals : Lines_Of_Code.lines := (0,0,0);
this_file : str_ptr;
this_count : Lines_Of_Code.lines;
procedure print_entry (s : string; l : Lines_of_Code.lines);
procedure print_header;
procedure print_entry (s : string; l : Lines_of_Code.lines)
is separate;
procedure print_header
is separate;
begin
if argc <= 1 then
Put_line (Usage);
else
print_header;
for I in 1..argc - 1 loop
if (i mod 52 = 0) then
print_header;
Text_IO.new_page;
end if;
this_file := new string'(argv.all(i).all.s);
this_count := loc (this_file.all);
totals.AS := totals.AS + this_count.AS;
totals.Cmnts := totals.Cmnts + this_count.Cmnts;
print_entry (s => this_file.all, l => this_count);
end loop;
Text_IO.put_line (dashes);
Text_IO.new_line;
print_entry (s => "***TOTALS***", l => totals);
end if;
end Count_Ada_Statements;
with Text_IO;
package body Lines_Of_Code is
use Text_IO;
function Loc (File_Name : String) return Lines is
Input : File_Type;
C : Character := ' ';
Line_Count : Natural := 0;
Comment_Count : Natural := 0;
Level : Natural := 0;
-- hack
New_Lines : Natural := 0;
-- end of hack
begin
Open (Input, In_File, File_Name);
loop
Get (Input, C);
-- Check for comment on the line
if C = '-' then
Get (Input, C);
-- Which is signaled by the '-' following a '-'
if C = '-' then
Comment_Count := Comment_Count + 1;
-- and then just skip the rest of the line and go to the next
Skip_Line (Input);
end if;
end if;
-- Check for one of the characters which introduce code constructs
-- like string or character literal or formal parameter list
-- within which a ';' does not terminate a statement
if C = '(' or C = '"' or C = '%' or C = ''' then
-- Check for opening parentheses
-- Every ';' within is in a formal parameter list
if C = '(' then
-- Count the number of levels of parentheses
Level := Level + 1;
-- Read ahead until the whole construct is closed, LEVEL = 0
while Level > 0 loop
Get (Input, C);
if C = '(' then
-- Increase the level if another '(' is found
Level := Level + 1;
elsif C = ')' then
-- Decrease the level if a ')' is found
Level := Level - 1;
end if;
end loop;
-- Now check for string brackets of either kind, " or %
elsif C = '"' or C = '%' then
-- Treat them in parallel, one must lead off
if C = '"' then
loop
Get (Input, C);
-- Loop until the close comes
-- If there is a doubled character it just starts again
exit when C = '"';
end loop;
-- The '%' is handled exactly the same way as '"'
elsif C = '%' then
loop
get (Input, C);
exit when C = '%';
end loop;
end if;
-- Character literals are just three characters long including '
elsif C = ''' then
Get (Input, C);
Get (Input, C);
end if;
-- Any ';' that can be found at this point after all exclusions
-- must be a valid "line of code" terminator
elsif C = ';' then
Line_Count := Line_Count + 1;
end if;
end loop;
exception
-- Return through exception since the end of file may be encountered
-- at several levels in the function and in any case it stops and returns
-- Otherwise one would use END_OF_FILE but here it would have to appear
-- in a number of places to no advantage
-- and would cause multiple exits or returns
-- This is much cleaner
when End_Error =>
--hacked
new_lines := integer(Text_IO.line (Input));
Text_IO.close (Input);
return (Line_Count, Comment_Count, new_lines );
-- end of hacking
end Loc;
-- There has been a certain amount of discussion of how to quantify the
-- number of lines of code in an ada program indeed this is a subject of some
-- discussion for most languages as ada becomes the dod standard for
-- implementations the question takes on more than a philosophical importance
-- whether you like it or not there are lots of pieces of paper generated in
-- which "lines of code" are quoted some of these are contracts and formal
-- costing estimates and can not easily be dismissed nor should there be any
-- ambiguity about their meaning money, at least, rides on the definition
-- there have been a number of stabs at this definition and i have faced
-- estimates within the past couple of weeks based on:
-- the number of physical lines (measured by counting ascii.cr)
-- the number of physical lines that are not comments or blank
-- the number of semicolons
-- the number of lines containing at least one semicolon
-- as a physicist i have a difficulty accepting measurements that will change
-- depending on formatting of the program or introduction of strings or
-- comments that do not change the execution therefore i would like to propose
-- a modification of the suggested methods that i believe is invarient, at
-- least to pretyprinting
-- the lines of code would be measured by counting the semicolon statement
-- terminators, after excluding:
--
-- comments
-- separators in formal parameter lists (by excluding parenthesized items)
-- string literals (set off by " or %)
-- character literals (i.e. ';')
-- i think this covers matters and makes a consistant and useful definition
-- as useful as any such quantification can be
-- i would very much like comments on this matter if i have fouled up let me
-- know right away or you may find this in a contract and your paycheck may
-- someday depend on it
-- in order to assure an unambiguous operational definition i am attaching a
-- ada function that describes the measure i believe that this does the
-- job without oversimplification or excessive complication
-- BILL WHITAKER
end Lines_Of_Code;
separate (Count_Ada_Statements)
procedure print_entry (s : string; l : Lines_of_Code.lines)
is
next_col : positive;
begin
Text_IO.put (s);
next_col := s'length + 1;
Text_IO.set_col (stmts_posn);
natural_IO.put (l.AS);
Text_IO.set_col (cmts_posn);
natural_IO.put (l.Cmnts);
Text_IO.new_line;
end print_entry;
separate (Count_Ada_Statements)
procedure print_header
is
begin
text_io.put ("file name");
Text_IO.set_col (stmts_posn + 2);
Text_IO.put ("Ada Stmts");
Text_IO.set_col (cmts_posn + 2);
text_io.put ("Comments");
Text_IO.new_line;
text_IO.put_line (dashes);
end print_header;
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1993-02-22 15:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-02-19 19:09 program to count LOC cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uwm.edu!cs.utexas.edu
-- strict thread matches above, loose matches on Subject: below --
1993-02-20 1:15 Dave Bashford
1993-02-20 15:23 cis.ohio-state.edu!zaphod.mps.ohio-state.edu!menudo.uh.edu!cl2.cl.uh.edu!
1993-02-22 15:11 David Emery
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox