c_count - C-language line counter
c_count [options] [file-specifications]
C_count counts lines and statements in C-language source files. It provides related statistics on the amount of whitespace, comments and code. C_count also shows the presence of unbalanced (or nested) comments, unbalanced quotation marks and illegal characters.
C_count reads one or more C-language source files and displays simple statistics about them. It counts statements (i.e., sequences of tokens terminated with semicolon) and measures the relative amount of commentary. C_count ignores semicolons where they appear in comments or in quoted literals.
A count of semicolons is a reasonable way of counting C statements. Note, however, that it does not count preprocessor definitions as C statements.
The statistics summary shows you the relative amount of commentary. This is the ratio of the alphanumeric characters in comments to the total of characters in the code (ignoring tabs and other whitespace which are not inside quotes). C_count only counts alphanumeric characters, thus ignoring punctuation used as fillers. It also suppresses RCS and DEC/CMS history comments from this ratio.
C_count counts the number of tokens (names and constants) in the source files and gives this total, as well as their average length.
C_count provides you not only with measurements, but also diagnostics in the form of a set of flags shown next to each file name:
Unbalanced quotes may be legal. The C preprocessor permits you to define symbols which contain an unbalanced quote mark, for example:
#define WARN (void)printf("** warning: ... WARN item
Rather than duplicate all of the complexity of the C preprocessor, c_count permits you to specify symbols which contain unbalanced quote marks.
-q WARN
tells c_count that the token "WARN" contains a quote mark.
C_count reads one or more C language source files and writes its statistics to standard output. If you do not give any file names, c_count reads a list of file names from standard input.
The special filename "-" directs c_count to read the file itself from the standard input.
Following is an example of the use of c_count, showing the detailed types of information which it reports.
bsd(5) c_count */*.[ch] 927 352 |src/c_count.c 5 0?" |test/test1.c 6 2? |test/test2.c 20 1 |test/test3.c ---------------- 958 355?" total lines/statements 121 lines had comments 12.6 % 48 lines had history 5.0 % 36 comments are inline -3.8 % 73 lines were blank 7.6 % 22 lines for preprocessor 2.3 % 730 lines containing code 76.2 % 958 total lines 100.0 % 3475 comment-chars 15.7 % 1021 history-chars 4.6 % 1003 nontext-comment-chars 4.5 % 4731 whitespace-chars 21.3 % 322 preprocessor-chars 1.5 % 11644 statement-chars 52.5 % 22196 total characters 100.0 % 1541 tokens, average length 4.91 0.29 ratio of comment:code 3 ?:illegal characters found 2 ":lines with unterminated quotes
If you use the "-p" option, c_count prints the detailed information for each file, as well as for all files together.
C_count runs in a portable UNIX® environment. Execute it on VAX/VMS by defining it as a foreign command.
C_count is a single binary module, that uses no auxiliary files (e.g., C_COUNT.EXE on VAX/VMS).
Thomas Dickey (dickey@clark.net).
wc (1)