Xref: utzoo alt.sources.wanted:1067 comp.sources.wanted:15739 comp.software-eng:5051 comp.lang.c:37065 Path: utzoo!utgpu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!mp.cs.niu.edu!ux1.cso.uiuc.edu!bradley.bradley.edu!pallas!dlee From: dlee@pallas.athenanet.com (Doug Lee) Newsgroups: alt.sources.wanted,comp.sources.wanted,comp.software-eng,comp.lang.c Subject: Re: WANTED: "C" code line counter program Summary: Two more ideas, but what is a "line" here? Message-ID: <1031@pallas.athenanet.com> Date: 14 Mar 91 06:37:21 GMT References: <1991Mar6.214157.18633@ntpal.uucp> <1991Mar11.182848.26693@comm.wang.com> Lines: 29 In article cpm00@DUTS.ccc.amdahl.com (PUT YOUR NAME HERE) writes: >What about counting newlines, but ignoring those >that immediately follow another newline (ie, skip blank lines)? My first thought was to skip all comments (single- and multi-line) and then count only lines containing characters other than whitespace. This should be close, though it will still overcount on constructs like if (( ) || ( ) || ... ) Then again, maybe a line that long *should* count as more than one line. We also run into the somewhat common declaration syntax char * foo() which, by my method, counts as two lines. Unfortunately, I see no quick way to give a consistent line count regardless of program syntax. Counting lines ending in '{' or ';' (after removing comments and trailing whitespace) would catch most loops and function definitions without counting them more than once, but constructs like while (line = get_next_line(file)) (void) process_line(line); would still count only once unless the braces were included (not a bad idea, imho). We need a more precise definition of "line" for this, I fear. Does this remind anyone else of _The Mythical Man Month_? :-) -- Doug Lee (dlee@athenanet.com or {bradley,uunet}!pallas!dlee)