Re: REQ: Non-commented lines of code (John Hagerman)
Tue, 9 May 1995 04:29:15 GMT

          From comp.compilers

Related articles
REQ: Non-commented lines of code (1995-04-28)
Re: REQ: Non-commented lines of code (1995-05-09)
| List of all articles for this month |

Newsgroups: comp.compilers
From: (John Hagerman)
In-Reply-To:'s message of Fri, 28 Apr 1995 15:59:46 GMT
Keywords: C
Organization: Carnegie Mellon University
References: 95-04-198
Date: Tue, 9 May 1995 04:29:15 GMT (Brian Edginton) writes:
> Looking for a tool (preferably PD) that will count lines of code.
> I would prefer a tool that is part of a set of tools or generates
> some sort of uniform output.
> ...
> [Great theological arguments are possible about what's a line of code,
> particularly in languages like C and Pascal where statement boundaries and
> line boundaries are unrelated. If you're satsified with a naive definition,
> e.g. a C statement is something that starts with a keyword and/or ends with
> a semicolon, you can whip up a comment-ignoring statement counter in about
> a dozen lines of flex. -John]

Here's something trivial. Replace ... with a comma-separated list of
sub-directories to look in. I use .x and .y for lex and yacc files.
The first output is just the line (word, character) count output from
wc. The second output is the wc output from "blank or comment" lines.

#!/bin/csh -f
set dirs='{...}'
set files="$dirs/*.[chxy]"
wc $files
echo "blank-or-comment lines:"
grep -h '\(^$\)\|\(^ \*\)\|\(^[ ]*/\*\)' $files | wc

~ John


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.