#   Copyright
#
#      Copyright (C) 2018-2024 Al Danial <al.danial@gmail.com>.
#      Copyright (C) 2010-2017 Jari Aalto <jari.aalto@cante.net>
#
#   License
#
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#       GNU General Public License for more details.
#
#       You should have received a copy of the GNU General Public License
#       along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#   Description
#
#       To learn what TOP LEVEL section to use in manual pages,
#       see POSIX/Susv standard and "Utility Description Defaults" at
#       http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap01.html#tag_01_11
#
#       This is manual page in Perl POD format. Read more at
#       http://perldoc.perl.org/perlpod.html or run command:
#
#           perldoc perlpod | less
#
#       To check the syntax:
#
#           podchecker *.pod
#
#       Create manual page with command:
#
#           pod2man PAGE.N.pod > PAGE.N

=pod

=head1 NAME

cloc - Count, or compute differences of, lines of source code and comments.

=head1 SYNOPSIS

  cloc [options] <FILE|DIR> ...

=head1 DESCRIPTION

Count, or compute differences of, physical lines of source code in the
given files (may be archives such as compressed tarballs or zip files,
or git commit hashes or branch names) and/or recursively below the given
directories.  It is written entirely in Perl, using only modules from the
standard distribution.

=head1 OPTIONS

=head2 Input Options

To count standard input, use the special filename B<-> and either
B<--stdin-name=FILE> to tell cloc the name of the file being
piped in, or B<--force-lang=LANG> to apply the LANG counter to
all input.

=over 4

=item B<--extract-with=CMD>

This option is only needed if cloc is unable to figure out how to
extract the contents of the input file(s) by itself. Use CMD to
extract binary archive files (e.g.: .tar.gz, .zip, .Z). Use the
literal 'E<gt>FILEE<lt>' as a stand-in for the actual file(s) to be
extracted. For example, to count lines of code in the input files
gcc-4.2.tar.gz perl-5.8.8.tar.gz on Unix use:

    --extract-with='gzip -dc >FILE< | tar xf -

or, if you have GNU tar:

    --extract-with='tar zxf >FILE<'

and on Windows, use, for example:

    --extract-with="\"c:\Program Files\WinZip\WinZip32.exe\" -e -o >FILE<

=item B<--list-file=FILE>

Take the list of file and/or directory names to
process from FILE, which has one file/directory
name per line.  Only exact matches are counted;
relative path names will be resolved starting from
the directory where cloc is invoked.
Set FILE to - to read file names from a STDIN pipe.
See also
B<--exclude-list-file>,
B<--config>.

=item B<--diff-list-file=FILE>

Take the pairs of file names to be diff'ed from
FILE, whose format matches the output of
B<--diff-alignment>.  (Run with that option to
see a sample.)  The language identifier at the
end of each line is ignored.  This enables B<--diff>
mode and by-passes file pair alignment logic.
See also
B<--config>.

=item B<--vcs=VCS>

Invoke a system call to VCS to obtain a list of
files to work on.  If VCS is 'git', then will
invoke 'git ls-files' to get a file list and
'git submodule status' to get a list of submodules
whose contents will be ignored.  See also B<--git>
which accepts git commit hashes and branch names.
If VCS is 'svn' then will invoke 'svn list -R'.
The primary benefit is that cloc will then skip
files explicitly excluded by the versioning tool
in question, ie, those in .gitignore or have the
svn:ignore property.
Alternatively VCS may be any system command
that generates a list of files.
Note:  cloc must be in a directory which can read
the files as they are returned by VCS.  cloc will
not download files from remote repositories.
'svn list -R' may refer to a remote repository
to obtain file names (and therefore may require
authentication to the remote repository), but
the files themselves must be local.
Setting VCS to 'auto' selects between 'git'
and 'svn' (or neither) depending on the presence
of a .git or .svn subdirectory below the directory
where cloc is invoked.

=item B<--unicode>

Check binary files to see if they contain Unicode expanded ASCII text.
This causes performance to drop noticeably.

=back

=head2 Processing Options

=over 4

=item B<--autoconf>

Count .in files (as processed by GNU autoconf) of recognized languages.
See also B<--no-autogen>.

=item B<--by-file>

Report results for every source file encountered.

=item B<--by-file-by-lang>

Report results for every source file encountered in addition to
reporting by language.

=item B<--config FILE>

Read command line switches from FILE instead of
the default location of ~/.config/cloc/options.txt.
The file should contain one switch, along with
arguments (if any), per line.  Blank lines and lines
beginning with '#' are skipped.  Options given on
the command line take priority over entries read from
the file.
If a directory is also given with any of these
switches: --list-file,
B<--exclude-list-file>,
B<--read-lang-def>,
B<--force-lang-def>,
B<--diff-list-file>
and a config file exists in that directory, it will
take priority over ~/.config/cloc/options.txt.

=item B<--count-and-diff SET1 SET2>

First perform direct code counts of source file(s)
of SET1 and SET2 separately, then perform a diff
of these.  Inputs may be pairs of files, directories,
or archives.  If --out or --report-file is given, three output
files will be created, one for each of the two counts and
one for the diff.  See also B<--diff>, B<--diff-alignment>,
B<--diff-timeout>, B<--ignore-case>, B<--ignore-whitespace>.

=item B<--diff SET1 SET2>

Compute differences in code and comments between source file(s) of
SET1 and SET2.  The inputs may be pairs of files, directories, or
archives.  Use B<--diff-alignment> to generate a list showing
which file pairs where compared.  See also
B<--count-and-diff>, B<--diff-alignment>, B<--diff-timeout>,
B<--ignore-case>, B<--ignore-whitespace>.

=item B<--diff-timeout N>

Ignore files which take more than N seconds
to process.  Default is 10 seconds.  Setting N
to 0 allows unlimited time.
(Large files with many repeated lines can cause
Algorithm::Diff::sdiff() to take hours.)

=item B<--docstring-as-code>

cloc considers docstrings to be comments, but this is
not always correct as docstrings represent regular
strings when they appear on the right hand side of an
assignment or as function arguments.  This switch
forces docstrings to be counted as code.

=item B<--follow-links>

[Unix only] Follow symbolic links to directories (sym links to files
are always followed).

=item B<--force-lang=LANG[,EXT]>

Process all files that have a EXT extension with the counter for
language LANG. For example, to count all .f files with the Fortran
90 counter (which expects files to end with .f90) instead of the
default Fortran 77 counter, use:

	--force-lang="Fortran 90",f

If EXT is omitted, every file will be counted with the LANG counter.
This option can be specified multiple times (but that is only useful
when EXT is given each time). See also B<--script-lang>,
B<--lang-no-ext>.

=item B<--force-lang-def=FILE>

Load language processing filters from FILE,
then use these filters instead of the built-in
filters.  Note:  languages which map to the same
file extension (for example:
MATLAB/Objective-C/MUMPS;  Pascal/PHP;
Lisp/OpenCL; Lisp/Julia; Perl/Prolog) will be ignored as
these require additional processing that is not expressed in
language definition files.
Use B<--read-lang-def> to define new language
filters without replacing built-in filters
(see also B<--write-lang-def>, B<--write-lang-def-incl-dup>).

=item B<--git>

Forces the inputs to be interpreted as git targets
(commit hashes, branch names, et cetera) if these
are not first identified as file or directory
names.  This option overrides the --vcs=git logic
if this is given; in other words, --git gets its
list of files to work on directly from git using
the hash or branch name rather than from
'git ls-files'.  This option can be used with
--diff to perform line count diffs between git
commits, or between a git commit and a file,
directory, or archive.  Use -v/--verbose to see
the git system commands cloc issues.

=item B<--git-diff-rel>

Same as B<--git --diff>, or just B<--diff> if the inputs
are recognized as git targets.  Only files which
have changed in either commit are compared.

=item B<--git-diff-all>

Git diff strategy #2:  compare all files in the
repository between the two commits.

=item B<--ignore-whitespace>

Ignore horizontal white space when comparing files
with B<--diff>.  See also B<--ignore-case>.

=item B<--ignore-case>

Ignore changes in case within file contents;
consider upper- and lowercase letters equivalent
when comparing files with B<--diff>.  See also
B<--ignore-whitespace>.

=item B<--ignore-case-ext>

Ignore case of file name extensions.  This will
cause problems counting some languages
(specifically, .c and .C are associated with C and
C++; this switch would count .C files as C rather
than C++ on *nix operating systems).  File name
case insensitivity is always true on Windows.

=item B<--ignore-regex>

Ignore lines in source files that match the given
Perl regular expression for the given language(s).
This option can be specified multiple times.
Language names are comma separated and are followed
by the pipe character and the regular expression.
Use * to match all languages.
Examples:

  --ignore-regex='C,Java,C++|^\s*[{};]\s*$'
  --ignore-regex='*|DEBUG|TEST\s+ONLY'

These filters are applied after comments are
removed.  Use --strip-comments=EXT to create
new files that show these filters applied.
The primary use case is to ignore lines
containing only braces, brackets, or puctuation.


=item B<--lang-no-ext=LANG>

Count files without extensions using the LANG counter.  This option
overrides internal logic for files without extensions (where such files
are checked against known scripting languages by examining the first
line for C<#!>).  See also B<--force-lang>, B<--script-lang>.

=item B<--max-file-size=MB>

Skip files larger than C<MB> megabytes when
traversing directories.  By default, C<MB>=100.
cloc's memory requirement is roughly twenty times
larger than the largest file so running with
files larger than 100 MB on a computer with less
than 2 GB of memory will cause problems.
Note:  this check does not apply to files
explicitly passed as command line arguments.

=item B<--no-autogen[=list]>

Ignore files generated by code-production systems
such as GNU autoconf.  To see a list of these files
(then exit), run with B<--no-autogen list>
See also B<--autoconf>.

=item B<--no-recurse>

Count files in the given directories without
recursively descending below them.

=item B<--only-count-files>

Only count files by language.  Blank, comment, and
code counts will be zero.

=item B<--original-dir>

Only effective in combination with
B<--strip-comments>.  Write the stripped files
to the same directory as the original files.

=item B<--read-binary-files>

Process binary files in addition to text files. This is usually a bad
idea and should only be attempted with text files that have embedded
binary data.

=item B<--read-lang-def=FILE>

Load new language processing filters from FILE
and merge them with those
already known to cloc.  If FILE defines a
language cloc already knows about, cloc's
definition will take precedence.  Use
B<--force-lang-def> to over-ride cloc's definitions.
(see also B<--write-lang-def>).

=item B<--script-lang=LANG,S>

Process all files that invoke C<S> as a C<#!> scripting language with the
counter for language LANG. For example, files that begin with
C<#!/usr/local/bin/perl5.8.8> will be counted with the Perl counter by
using

	--script-lang=Perl,perl5.8.8

The language name is case insensitive but the name of the script
language executable, C<S>, must have the right case. This option can be
specified multiple times. See also B<--force-lang>.

=item B<--sdir=DIR>

Use DIR as the scratch directory instead of letting I<File::Temp> chose
the location. Files written to this location are not removed at the
end of the run (as they are with I<File::Temp>).

=item B<--skip-leading=N[,ext]>

 Skip the first <N> lines of each file.  If a
comma separated list of extensions is also given,
only skip lines from those file types.  Example:

	--skip-leading=10,cpp,h

will skip the first ten lines of *.cpp and *.h
files.  This is useful for ignoring boilerplate
text.


=item B<--skip-uniqueness>

Skip the file uniqueness check. This will give a performance boost at
the expense of counting files with identical contents multiple times
(if such duplicates exist).

=item B<--stat>

Some file systems (AFS, CD-ROM, FAT, HPFS, SMB)
do not have directory 'nlink' counts that match
the number of its subdirectories.  Consequently
cloc may undercount or completely skip the
contents of such file systems.  This switch forces
File::Find to stat directories to obtain the
correct count.  File search speed will decrease.
See also B<--follow-links>.

=item B<--stdin-name=FILE>

Count lines streamed via I<STDIN> as if they came from a file named FILE.

=item B<--strip-code=EXT>

For each file processed, write to the current directory a version of
the file which has blank and code lines removed.
The name of each stripped file is the original file name with
C<.EXT> appended to it. It is written to the current directory unless
B<--original-dir> is on.

=item B<--strip-comments=EXT>

For each file processed, write to the current directory a version of
the file which has blank and commented lines removed (in-line comments
persist). The name of each stripped file is the original file name with
C<.EXT> appended to it. It is written to the current directory unless
B<--original-dir> is on.

=item B<--strip-str-comments>

Replace comment markers embedded in strings with
'xx'.  This attempts to work around a limitation
in Regexp::Common::Comment where comment markers
embedded in strings are seen as actual comment
markers and not strings, often resulting in a
'Complex regular subexpression recursion limit'
warning and incorrect counts.  There are two
disadvantages to using this switch:  1/code count
performance drops, and 2/code generated with
B<--strip-comments> will contain different strings
where ever embedded comments are found.

=item B<--sum-reports>

Input arguments are report files previously created with the
B<--report-file> option. Makes a cumulative set of results containing
the sum of data from the individual report files.

=item B<--timeout=N>

Ignore files which take more than <N> seconds
to process at any of the language's filter stages.
The default maximum number of seconds spent on a
filter stage is the number of lines in the file
divided by one thousand.  Setting B<N> to 0 allows
unlimited time.  See also B<--diff-timeout>.

=item B<--processes=NUM>

[Available only on systems with a recent version
of the Parallel::ForkManager module.  Not
available on Windows.] Sets the maximum number of
cores that cloc uses.  The default value of 0
disables multiprocessing.

=item B<--unix>

Over-ride the operating system detection logic and run in UNIX
mode.  See also B<--windows>, B<--show-os>.

=item B<--use-sloccount>

If SLOCCount is installed, use its compiled
executables c_count, java_count, pascal_count,
php_count, and xml_count instead of cloc's
counters.  SLOCCount's compiled counters are
substantially faster than cloc's and may give
a performance improvement when counting projects
with large files.  However, these cloc-specific
features will not be available: B<--diff>,
B<--count-and-diff>, B<--strip-comments>, B<--unicode>.

=item B<--windows>

Over-ride the operating system detection logic and run in
Microsoft Windows mode.  See also B<--unix>, B<--show-os>.

=back

=head2 Filter Options

=over 4

=item B<--include-content=REGEX>

Only count files containing text that matches the given
regular expression.

=item B<--exclude-content=REGEX>

Exclude files containing text that matches the given
regular expression.

=item B<--exclude-dir=DIR1[,DIR2 ...]>

Exclude the given comma separated directories from being scanned. For
example:

	--exclude-dir=.cache,test

will skip all files that match C</.cache/> or C</test/> as part of
their path. Directories named C<.bzr>, C<.cvs>, C<.hg>, C<.git>,
and C<.svn> are always excluded.
This option only works with individual directory
names so including file path separators is not
allowed.  Use B<--fullpath> and B<--not-match-d=REGEX>
to supply a regex matching multiple subdirectories.

=item B<--exclude-ext=EXT1[,EXT2 ...]>

Do not count files having the given file name extensions.

=item B<--exclude-lang=L1[,L2[...]]>

Exclude the given comma separated languages from being counted.

=item B<--exclude-list-file=FILE>

Ignore files and/or directories whose names
appear in FILE.  FILE should have one file
name per line.  Only exact matches are ignored;
relative path names will be resolved starting from
the directory where cloc is invoked.
See also B<--list-file>,
B<--config>.

=item B<--fullpath>

Modifies the behavior of B<--match-f> or
B<--not-match-f> to include the file's path
in the regex, not just the file's basename.
(This does not expand each file to include its
absolute path, instead it uses as much of
the path as is passed in to cloc.)

=item B<--include-ext=<ext1>[,ext2[...]]>

Count only languages having the given comma
separated file extensions.  Use B<--show-ext> to
see the recognized extensions.

=item B<--include-lang=L1[,L2 ...]>

Count only the given comma separated, case-insensitive languages
L1, L2, L3, et cetera.

=item B<--match-d=REGEX>

Only count files in directories matching the Perl regex.  For example

     --match-d='/(src|include)/'

only counts files in directory paths containing C</src/>
or C</include/>.

=item B<--not-match-d=REGEX>

Count all files except in directories matching the Perl regex.
Only the trailing directory name is compared, for example, when
counting in C</usr/local/lib>, only C<lib> is
compared to the regex.
Add B<--fullpath> to compare parent directories to
the regex.
Do not include file path separators at the beginning
or end of the regex.
This switch may be repeated.

=item B<--match-f=REGEX>

Only count files whose basenames match the Perl regex. For example
this only counts files at start with Widget or widget:

     --match-f='^[Ww]idget'

Add B<--fullpath> to include parent directories
in the regex instead of just the basename.

=item B<--not-match-f=REGEX>

Count all files except those whose basenames match the Perl regex.
Add B<--fullpath> to include parent directories
in the regex instead of just the basename.
This switch may be repeated.

=item B<--skip-archive=REGEX>

Ignore files that end with the given Perl regular
expression.  For example, if given

	--skip-archive='(zip|tar(\.(gz|Z|bz2|xz|7z))?)'

the code will skip files that end with .zip,
.tar, .tar.gz, .tar.Z, .tar.bz2, .tar.xz, and
.tar.7z.

=item B<--skip-win-hidden>

On Windows, ignore hidden files.

=back

=head2 Debug Options

=over 4

=item B<--categorized=FILE>

Save file sizes in bytes, identified languages and
names of categorized files to FILE.

=item B<--counted=FILE>

Save names of processed source files to FILE.
See also B<--found>, B<--ignored>, B<--unique>.

=item B<--diff-alignment=FILE>

Write to FILE a list of files and file pairs
showing which files were added, removed, and/or
compared during a run with B<--diff>.  This switch
forces the B<--diff> mode on.

=item B<--explain=LANG>

Print the filters used to remove comments for
language LANG and exit.  In some cases the
filters refer to Perl subroutines rather than
regular expressions.  An examination of the
source code may be needed for further explanation.

=item B<--help>

Print cloc's internal usage information and exit.

=item B<--found=FILE>

Save names of every file found to FILE.  See also B<--counted>,
B<--ignored>, B<--unique>.

=item B<--ignored=FILE>

Save names of ignored files and the reason they were ignored to FILE.
See also B<--counted>, B<--found>, B<--unique>.

=item B<--print-filter-stages>

Print to I<STDOUT> processed source code before and after each filter is
applied.

=item B<--show-ext[=EXT]>

Print information about all known (or just the given) file extensions
and exit.

=item B<--show-lang[=LANG]>

Print information about all known (or just the given) languages and
exit.

=item B<--show-os>

Print the value of the operating system mode and exit.  See also
B<--unix>, B<--windows>.

=item B<--unique=FILE>

Save names of ignored files and the reason they were ignored to FILE.
See also B<--counted>, B<--found>, B<--ignored>.

=item B<-v[=N]>

Turn on verbose with optional numeric value.

=item B<--verbose[=N]>

Long form of B<-v>.

=item B<--version>

Print the version of this program and exit.

=item B<--write-lang-def=FILE>

Writes to FILE the language processing filters then exits. Useful as a
first step to creating custom language definitions.
Note: languages which map to the same file extension will be excluded.
See also B<--force-lang-def>, B<--read-lang-def>.

=item B<--write-lang-def-incl-dup=FILE>

Same as B<--write-lang-def>, but includes duplicated
extensions.  This generates a problematic language
definition file because cloc will refuse to use
it until duplicates are removed.

=back

=head2 Output Options

=over 4

=item B<--3>

Print third-generation language output.  (This option can cause report
summation to fail if some reports were produced with this option while
others were produced without it.)

=item B<--by-percent X>

Instead of comment and blank line counts, show
these values as percentages based on the
value of X in the denominator, where X is one of
    c   meaning lines of code
    cm  meaning lines of code + comments
    cb  meaning lines of code + blanks
    cmb meaning lines of code + comments + blanks

For example, if using method 'c' and your code
has twice as many lines of comments as lines
of code, the value in the comment column will
be 200%.  The code column remains a line count.

=item B<--csv>

Write the results as comma separated values.

=item B<--csv-delimiter=C>

Use the character C as the delimiter for comma separated files
instead of ,.  This switch forces B<--csv> to be on.

=item B<--file-encoding=E>

Write output files using the B<E> encoding instead of
the default ASCII (B<E> = 'UTF-7').  Examples: 'UTF-16',
'euc-kr', 'iso-8859-16'.  Known encodings can be
printed with
  perl -MEncode -e 'print join("\n", Encode->encodings(":all")), "\n"'

=item B<--fmt=N>

Alternate text output format where B<N> is a number
from 1 to 5, or -1 to -5. 'total lines' means the
sum of code, comment, and blank lines.  Negative
values are the same as the positive values but retain,
instead of deleting, the intermediate JSON file that
is written.  The JSON file name is randomly generated
unless --out/--report-file is given.  The formats are:
  1:  by language (same as cloc default output)
  2:  by language with an extra column for total lines
  3:  by file with language
  4:  by file with a total lines column
  5:  by file with language and a total lines column

=item B<--hide-rate>

Do not show line and file processing rates in the output
header. This makes output deterministic.

=item B<--json>

Write the results in JavaScript Object Notation (JSON).

=item B<--md>

Write the results as Markdown-formatted text.

=item B<--out=FILE>

Synonym for B<--report-file=FILE>.

=item B<--progress-rate=N>

Show progress update after every N files are processed (default
N=100). Set N to 0 to suppress progress output; useful when
redirecting output to I<STDOUT>.

=item B<--quiet>

Suppress all information messages except for the final report.

=item B<--report-file=FILE>

Write the results to FILE instead of standard output.

=item B<--summary-cutoff=X:N>

Aggregate to 'Other' results having X lines
below N where X is one of
    c   meaning lines of code
    f   meaning files
    m   meaning lines of comments
    cm  meaning lines of code + comments
Appending a percent sign to N changes
the calculation from straight count to
percentage.
Ignored with --diff or --by-file.

=item B<--sql=FILE>

Write results as SQL CREATE and INSERT statements which can be read by
a database program such as SQLite. If FILE is B<->, output is sent to
I<STDOUT>.

=item B<--sql-append>

Append SQL insert statements to the file specified by B<--sql> and
do not generate table creation option.

=item B<--sql-project=NAME>

Use B<name> as the project identifier for the current run. Only valid
with the B<--sql> option.

=item B<--sql-style=STYLE>

Write SQL statements in the given style instead of the default
SQLite format.  Styles include B<Oracle> and B<Named_Columns>.

=item B<--sum-one>

For plain text reports, show the SUM: output line even if only
one input file is processed.

=item B<--xml>

Write the results in XML.

=item B<--xsl[=FILE]>

Reference FILE as an XSL stylesheet within the XML output. If FILE is
not given, writes a default stylesheet, cloc.xsl. This switch forces
B<--xml> to be on.

=item B<--yaml>

Write the results in YAML.

=back

=head1 EXAMPLES

Count the lines of code in the Perl 5.10.0 compressed tar file
on a UNIX-like operating system:

  cloc perl-5.10.0.tar.gz

Count the changes in files, code, and comments between Python
releases 2.6.6 and 2.7:

  cloc --diff Python-2.6.6.tar.bz  Python-2.7.tar.bz2

To see how cloc aligns files for comparison between two code
bases, use the B<--diff-alignment=FILE> option.  Here the
alignment information is written to C<align.txt>:

  cloc --diff-alignment=align.txt gcc-4.4.0.tar.bz2  gcc-4.5.0.tar.bz2

Count file, code, and comment changes between two git commits:

  cloc --git --diff b409850824 HEAD

Print the recognized languages:

  cloc --show-lang

Remove comments from C<foo.c> and save the result in C<foo.c.nc>
("nc" is an arbitrary extension; used here to denote "no comments"):

  cloc --strip-comments=nc foo.c

Additional examples can be found at L<https://github.com/AlDanial/cloc>.

=head1 ENVIRONMENT

None.

=head1 FILES

None.

=head1 SEE ALSO

sloccount(1)

=head1 AUTHORS

The cloc program was written by Al Danial <al.danial@gmail.com> and
is Copyright (C) 2006-2023 <al.danial@gmail.com>.

The manual page was originally written by Jari Aalto <jari.aalto@cante.net>.

Both the code and documentation is released under the GNU GPL version 2
or (at your option) any later version. For more information about
license, visit <http://www.gnu.org/copyleft/gpl.html>.

=cut
