slocnt.exe - Source Lines Of Code Counter
Download – Source Lines Of Code Counter.
SloCnt 7.12, 14-Nov-2020
SloCnt is a source lines of code (SLOC) counter program.
For each file it generates six different counts, a ratio of two of
the counts and supports subtotals and a final total in a formatted
report written to standard output.
Format : slocnt [options] [Files] [Files]
Files : Indicates files to process, wildcards supported.
Files may be omitted in which case list of files to process
is read from stdin.
Options:
?, -h : Brief help.
-help : Full help.
-llang : Language: Auto (default), Ada, C, Pascal, SloCnt, ...
-snn : Subtotal if any of 1..nn characters of filename changes.
-sdir : Subtotal when directory changes, exclusive with -snn.
-pnd : Specify ratio columns. Default: pl
-r[+-] : Recursive directory search
-fopts : Output format options, multiple allowed.
opts: p (pretty print), f (full file names).
-ml.e : Additional language-to-extension mapping, multiple allowed.
Example usage:
ls slo*.a | slocnt -ptl -lada -s6 > slo.cnt
slocnt -r *.cpp *.h > slo.cnt
slocnt -help | more
Written by: Robin Miller, Joe Nord
----------------------------------------------------------------------
How SloCnt Works
----------------------------------------------------------------------
Slocnt can be executed with the files to process specified via
command line parameters, or it can execute as a filter program
where it reads a list of files from standard input.
In both cases, a formatted report is written to standard output.
SloCnt processing and output format are controlled by command
line options.
These options have the following format:
-xopt, where x is the identifier and opt the value selected.
SloCnt can either process all files using the same language or apply a
'best guess' method for determining the language based on the file
extension (see the '-l' command line option below). SloCnt writes its
formatted report to standard output. It outputs a line of counts
for each file it processes. SloCnt provides two levels of totals
(a re-settable subtotal and a final total) in a report generated on
a single run. SloCnt also provides a powerful, recursive totaling
capability by allowing the reports from previous SloCnt runs to be
entered as input files on subsequent runs (see the '-l' command line
option below). In this case SloCnt uses the final total from the
input report as a single count line in the current report.
----------------------------------------------------------------------
SloCnt Command Line Options
----------------------------------------------------------------------
SloCnt supports command line options to control the processing and
output format of the program. Each of the main control options
is described in detail below.
Option: ?, -h, -help
Purpose: Help options.
Provides two levels of instructions on how to use SloCnt.
Option: -llang
Purpose: Language option.
Specifies the method SloCnt uses to determine the language
used to count the contents of each input file. If all
files are to be counted using the same language then this
option specifes the language explicitly. If the language
is specified as 'auto' SloCnt uses the file name to
make a 'best guess' as to the language the file contains.
The supported languages and associated file extensions are
listed below. Using the 'auto' option allows multiple
languages to be counted on a single execution while the
explicit language option guarantees that code can be
counted even if the 'best guess' file naming conventions
are not followed. File extensions are case insensitive.
Finally, when the language specified is 'slocnt' (or the
associated extension) SloCnt parses files that are
reports from previous runs as input to the current run.
This provides a powerful, recursive totaling capability.
Language Default file extensions
--------
----------------------------------------
C C H
RC CPP HPP CS
Masm MASM ASM INC
Ada ADA ADS
ADB A
A86 A86 CPY AMC
Basic BASIC BAS
Bat BAT
Cmd CMD
Cobol COBOL COB
Fortran FORTRAN FOR
PLI PLIOPT PLI
PLS P26 P6I P6M
Pascal PASCAL PAS
Rexx REXX REX
ScriptX ScriptX CLS
SloCnt SLOCNT SLO
CNT
Text TXT TEXT
ASC ASCII
PowerShell POWERSHELL PS1
Option: -snn, -sdir
Purpose: Subtotal options.
Specifies when to generate subtotals. If the 'nn' option
is chosen then a subtotal is generated whenever the first
one or more characters in the first 1..nn characters of
the file name change. If 'dir' is specified a subtotal
is generated whenever the directory changes. The 'dir'
option takes precedence over the 'nn' option. The default
is to do no subtotals at all (neither option in effect).
Option: -pnd
Purpose: Ratio option.
Calculates the ratio of any two of the six output counts.
The numerator and denominator (represented by n and d) are
single characters that specify the first character of the
output count column names (see output description below).
Default is pl.
Option: -fopt
Purpose: Output formatting options.
If '-fp' is specified SloCnt provides 'pretty printing'
with page headers, footers and numbering (80 column,
60 lines/page format). Normally Slocnt forces each output
count line to fit on a single 80 column line by left
truncating the file name, if necessary. If '-ff' is
specified SloCnt will print file names that exceed the
space allowed on a separate line from the counts, thus
maintaining full file names at some expense to report
readability.
Option: -ml.e
Purpose: Additional language to extension mapping.
The mapping is specified in dot notation.
The language is specified first and must be one of the
supported languages, spelled exactly as listed by help.
The new extension is specified after the dot and can
be any desired string. The new mappings are added to the
front of the existing list so they have precedence over
the default set. This allows the default set to be either
extended or overridden. Also note that by specifying
-munknown.ext it is possible to exclude extensions that
are predefined.
Examples: -mada.aaa -mpascal.pasc
Option: -debug
Purpose: Debug option.
Primarily a debug tool, with this option, SloCnt dumps the
current counter state to stderr for each line of each file.
Displayed debug information includes a statement of which
counter module is being used for each source file and which
source files have been ignored due to no extension to
language mapping.
----------------------------------------------------------------------
SloCnt Output
----------------------------------------------------------------------
SloCnt writes its count output to standard output which may
be redirected by the user to a file or printer. Most of the
SloCnt output format is self explanatory. The following defines
the meaning of the six counters SloCnt maintains and displays in
six columns in the output report for each file, subtotal and
final total.
Text: Number of text lines source. Typically number of
linefeeds (LF) in source file though the linefeed
on last line of file is optional as in DOS/Win.
Spaces: Number of blank lines OR
lines with only a comment delimiter OR
a comment line with 1 or more occurrences
of one other character (e.g. a line of ***
to separate blocks of comments or code).
Cmnts: Number of lines containing only comments.
P-SLOC: Number of physical source lines of code (SLOC).
This is most common definition of source lines of code.
For most languages, P-SLOC = Text - Spaces - Cmnts.
L-SLOC: Number of logical language statements.
Very language dependent, but preferred in some organizations.
Example: in 'C', L-Sloc is count of semi-colons in code
specifically limited to text outside comments or strings.
ICmnts: Number of source lines (P-SLOC) which include comments.
Maximum number of lines supported: 2147483647 (2**31)
----------------------------------------------------------------------
Peculiar Options
----------------------------------------------------------------------
To provide historical compatibility with the 'CLOCS.exe' counter,
slocnt provides the "-Osmartpsloc" option. With this option specified
the 'C' language counter will consider "{", "}" and ";" spacing.
That is, they do not identify P-SLOC.