COUNTNB ... copyright (c) 1997 Allegro Consultants, Inc. Author: Stan Sieler (sieler@allegrosupport.com) This program reads from $STDINX or a file (specified via INFO=), and counts the distribution of code/comment/blank lines. (See INFO options below) For the first line of input, if any of the characters are not printable ASCII, COUNTNB will exit with a count of 0. If an input line is 80 characters long, and the last 8 characters are digits, then it is assumed to be a line number, and is stripped off before examining the rest of the line. Sample run: run countnb; stdin = foo #Lines: 7230, #Code: 5109, #Blank: 1706, #Comments: 415(3) (In the above, the "(3)" means: 3 comments weren't closed on the same line they started on (see #1 below for notes).) A comment is any line whose first non-blank character(s) is(are) (and what language we thought the comment is from): << SPL ! SPL /* C { Pascal (* Old-style Pascal, shouldn't be used :) comment SPL (mixed case allowed) Also, any line with the following in column 1 are considered to be comment lines: C FORTRAN ... and column 2 must be a non-letter, non-digit (see #2 below) c FORTRAN ... ditto. (see #2 below) Also, any line beginning with six digits, with an asterisk immediately followin is considered to be a COBOL comment: ######* COBOL So...what about multi-line comments, like: {this is a three := 3 line comment} Note #1: multiple-line comments ------------------------------- By default, COUNTNB will try to find the closing comment ("}"), and count all of the lines as comment lines. You can disable this by running COUNTNB with a PARM=1 ... which would cause the above example to be counted as 1 comment line (and 1 unclosed comment), and 2 code lines. Ok...what about a source code line like: {hi there} a := b Yep...you guesssed it ... COUNTNB counts it like a comment. After all....and this is *IMPORTANT*...the casual reader will probably also see it as a comment, missing the assignment! What about blank lines in the middle of a multi-line comment? They're counted as blank, not as comment lines. Note #2: FORTRAN comments ------------------------- By default, COUNTNB tries to detect FORTRAN comments ("C" or "c" in column 1). Unfortunately, a simple minded approach of just checking the first column for "C" or "c" would count many valid non-FORTRAN code lines as comments. As a compromise, COUNTNB defaults to requiring a non-letter, non-digit in column 2 after a "C" or "c", otherwise it won't think the line is a FORTRAN comment. This behaviour can be changed via the PARM parameter. Note #3: PARM bits ------------------ The PARM parameter can influence COUNTNB. The PARM values/bits are shown below. PARM PARM # bit # Meaning ------ ----- ------------------------------------------ 1 15 Don't try to find close of multi-line comments. 2 14 Don't look at all for FORTRAN comments. 4 13 Any line starting with "C" or "c" in column 1 is a FORTRAN comment. (Overrides bit 14) 8 12 Don't look at all for COBOL comments. 16 11 Don't want ADDVAR (see INFO options) 32 10 Want SHOWVAR The PARM bits are additive, so PARM=3 means: PARM bit 15 and PARM bit 14. INFO options ------------ If the first non-blank token in the INFO string starts with a letter or / or ./, it is assumed to be a filename to read from. Any other tokens on the INFO line are assumed to be options: ADDVAR Tells COUNTNB to add the totals for the current file to four session variables: CNB_LINES, CNB_CODE, CNB_BLANKS, and CNB_COMMENTS. [NO]ANYFORtran CLEARVAR Tells COUNTNB to initially zero the four session variables: CNB_LINES, CNB_CODE, CNB_BLANKS, and CNB_COMMENTS. [NO]COBOL [NO]MULTI [NO]SHOWVAR SHOWVAR tells COUNTNB to show the sum of the current file and the four session variables (see ADDVAR). This sum line starts with the text "Tot". [NO]SKIPBINARY SKIPBINARY tells COUNTNB to quietly ignore a binary file. "binary" is defined as: the first line has non-printable characters other than and VERSION VERSION tells COUNTNB to display the version number and then terminate. want'clearvar = flags.(09:01) #; COUNTNB 20140821