• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H01-May-2021-6852

Unix/H03-May-2022-18,22915,526

tests/H01-May-2021-34,34125,024

.gitignoreH A D01-May-202135 32

DockerfileH A D01-May-2021764 3626

Dockerfile.buildH A D01-May-202165 43

LICENSEH A D01-May-202117.6 KiB341281

README.mdH A D01-May-2021160.4 KiB3,0552,772

clocH A D03-May-2022679.4 KiB17,06014,290

sqlite_formatterH A D01-May-20211.8 KiB6341

README.md

1<a name="___top"></a>
2# cloc
3*Count Lines of Code*
4
5* * *
6cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.
7
8Latest release:  v1.90 (May 1, 2021)
9
10cloc moved to GitHub in September 2015 after being hosted
11at http://cloc.sourceforge.net/ since August 2006.
12
13*   [Quick Start](#quick-start-)
14*   [Overview](#overview-)
15*   [Download](https://github.com/AlDanial/cloc/releases/latest)
16    *   [Install via package manager](#install-via-package-manager)
17    *   [Stable release](#stable-release)
18    *   [Development version](#development-version)
19*   [License](#license-)
20*   [Why Use cloc?](#why-use-cloc-)
21*   [Other Counters](#other-counters-)
22*   [Building a Windows Executable](#building-a-windows-executable-)
23*   [Basic Use](#basic-use-)
24*   [Options](#options-)
25*   [Recognized Languages](#recognized-languages-)
26*   [How it Works](#how-it-works-)
27*   [Advanced Use](#advanced-use-)
28    *   [Remove Comments from Source Code](#remove-comments-from-source-code-)
29    *   [Work with Compressed Archives](#work-with-compressed-archives-)
30    *   [Differences](#differences-)
31    *   [Create Custom Language Definitions](#create-custom-language-definitions-)
32    *   [Combine Reports](#combine-reports-)
33    *   [SQL](#sql-)
34    *   [Custom Column Output](#custom-column-output-)
35    *   [Wrapping cloc in other scripts](#wrapping-cloc-in-other-scripts-)
36    *   [git and UTF8 pathnames](#git-and-UTF8-pathnames-)
37    *   [Third Generation Language Scale Factors](#third-generation-language-scale-factors-)
38    *   [options.txt configuration file](#optionstxt-configuration-file-)
39*   [Complex regular subexpression recursion limit ](#complex-regular-subexpression-recursion-limit-)
40*   [Limitations](#limitations-)
41*   [Requesting Support for Additional Languages](#requesting-support-for-additional-languages-)
42*   [Reporting Problems](#reporting-problems-)
43*   [Acknowledgments](#acknowledgments-)
44*   [Copyright](#copyright-)
45
46<a name="Quick_Start"></a>      []({{{1)
47# [Quick Start &#9650;](#___top "click to go to top of document")
48
49Step 1:  Download cloc (several methods, see below) or run cloc's
50[docker image](#Docker-).  The Windows executable has no requirements.
51The source version of cloc requires a Perl interpreter, and the
52Docker version of cloc requires a Docker installation.
53
54Step 2:  Open a terminal (`cmd.exe` on Windows).
55
56Step 3:  Invoke cloc to count your source files, directories, archives,
57or git commits.
58The executable name differs depending on whether you use the
59development source version (`cloc`), source for a
60released version (`cloc-1.90.pl`) or a Windows executable
61(`cloc-1.90.exe`).  On this page, `cloc` is the generic term
62used to refer to any of these.
63
64**a file**
65<pre>
66prompt> cloc hello.c
67       1 text file.
68       1 unique file.
69       0 files ignored.
70
71https://github.com/AlDanial/cloc v 1.65  T=0.04 s (28.3 files/s, 340.0 lines/s)
72-------------------------------------------------------------------------------
73Language                     files          blank        comment           code
74-------------------------------------------------------------------------------
75C                                1              0              7              5
76-------------------------------------------------------------------------------
77</pre>
78
79**a directory**
80<pre>
81prompt> cloc gcc-5.2.0/gcc/c
82      16 text files.
83      15 unique files.
84       3 files ignored.
85
86https://github.com/AlDanial/cloc v 1.65  T=0.23 s (57.1 files/s, 188914.0 lines/s)
87-------------------------------------------------------------------------------
88Language                     files          blank        comment           code
89-------------------------------------------------------------------------------
90C                               10           4680           6621          30812
91C/C++ Header                     3             99            286            496
92-------------------------------------------------------------------------------
93SUM:                            13           4779           6907          31308
94-------------------------------------------------------------------------------
95</pre>
96
97**an archive**
98
99We'll pull cloc's source zip file from GitHub, then count the contents:
100<pre>
101prompt> wget https://github.com/AlDanial/cloc/archive/master.zip
102
103prompt> cloc master.zip
104https://github.com/AlDanial/cloc v 1.65  T=0.07 s (26.8 files/s, 141370.3 lines/s)
105-------------------------------------------------------------------------------
106Language                     files          blank        comment           code
107-------------------------------------------------------------------------------
108Perl                             2            725           1103           8713
109-------------------------------------------------------------------------------
110SUM:                             2            725           1103           8713
111-------------------------------------------------------------------------------
112</pre>
113
114**a git repository, using a specific commit**
115
116This example uses code from
117<a href=https://pypi.python.org/pypi/pudb>PuDB</a>, a fantastic Python debugger.
118
119<pre>
120prompt> git clone http://git.tiker.net/trees/pudb.git
121
122prompt> cd pudb
123
124prompt> cloc 6be804e07a5db
125      48 text files.
126      48 unique files.
127      15 files ignored.
128
129github.com/AlDanial/cloc v 1.73  T=0.15 s (223.1 files/s, 46159.0 lines/s)
130-------------------------------------------------------------------------------
131Language                     files          blank        comment           code
132-------------------------------------------------------------------------------
133Python                          28           1519            728           4659
134YAML                             2              9              2             75
135Bourne Shell                     3              6              0             17
136make                             1              4              6             10
137-------------------------------------------------------------------------------
138SUM:                            34           1538            736           4761
139-------------------------------------------------------------------------------
140
141</pre>
142
143**each subdirectory of a particular directory**
144
145Say you have a directory with three different git-managed projects,
146Project0, Project1, and Project2.  You can use your shell's looping
147capability to count the code in each.  This example uses bash (scroll down for cmd.exe example):
148<pre>
149prompt> for d in ./*/ ; do (cd "$d" && echo "$d" && cloc --vcs git); done
150./Project0/
1517 text files.
152       7 unique files.
153       1 file ignored.
154
155github.com/AlDanial/cloc v 1.71  T=0.02 s (390.2 files/s, 25687.6 lines/s)
156-------------------------------------------------------------------------------
157Language                     files          blank        comment           code
158-------------------------------------------------------------------------------
159D                                4             61             32            251
160Markdown                         1              9              0             38
161make                             1              0              0              4
162-------------------------------------------------------------------------------
163SUM:                             6             70             32            293
164-------------------------------------------------------------------------------
165./Project1/
166       7 text files.
167       7 unique files.
168       0 files ignored.
169
170github.com/AlDanial/cloc v 1.71  T=0.02 s (293.0 files/s, 52107.1 lines/s)
171-------------------------------------------------------------------------------
172Language                     files          blank        comment           code
173-------------------------------------------------------------------------------
174Go                               7            165            282            798
175-------------------------------------------------------------------------------
176SUM:                             7            165            282            798
177-------------------------------------------------------------------------------
178./Project2/
179      49 text files.
180      47 unique files.
181      13 files ignored.
182
183github.com/AlDanial/cloc v 1.71  T=0.10 s (399.5 files/s, 70409.4 lines/s)
184-------------------------------------------------------------------------------
185Language                     files          blank        comment           code
186-------------------------------------------------------------------------------
187Python                          33           1226           1026           3017
188C                                4            327            337            888
189Markdown                         1             11              0             28
190YAML                             1              0              2             12
191-------------------------------------------------------------------------------
192SUM:                            39           1564           1365           3945
193-------------------------------------------------------------------------------
194</pre>
195
196**each subdirectory of a particular directory (Windows/cmd.exe)**
197<pre>
198for /D %I in (.\*) do cd %I && cloc --vcs git && cd ..
199</pre>
200
201[](1}}})
202<a name="Overview"></a>      []({{{1)
203# [Overview &#9650;](#___top "click to go to top of document")
204
205cloc counts blank lines, comment lines, and physical lines of source
206code in [many programming languages](#Languages). Given two versions of
207a code base, cloc can compute differences in blank, comment, and source
208lines. It is written entirely in Perl with no dependencies outside the
209standard distribution of Perl v5.6 and higher (code from some external
210modules is [embedded within
211cloc](https://github.com/AlDanial/cloc#regexp_common)) and so is
212quite portable. cloc is known to run on many flavors of Linux, FreeBSD,
213NetBSD, OpenBSD, macOS, AIX, HP-UX, Solaris, IRIX, z/OS, and Windows.
214(To run the Perl source version of cloc on Windows one needs
215[ActiveState Perl](http://www.activestate.com/activeperl) 5.6.1 or
216higher, [Strawberry Perl](http://strawberryperl.com/),
217Windows Subsystem for Linux,
218[Cygwin](http://www.cygwin.com/),
219[MobaXTerm](http://mobaxterm.mobatek.net/) with the Perl plug-in
220installed,
221or
222a mingw environment and terminal such as provided by
223[Git for Windows](https://gitforwindows.org/).
224Alternatively one can use the Windows binary of cloc
225generated with [PAR::Packer](http://search.cpan.org/~rschupp/PAR-Packer-1.019/lib/pp.pm)
226to run on Windows computers that have neither Perl nor Cygwin.)
227
228cloc contains code from David Wheeler's
229[SLOCCount](http://www.dwheeler.com/sloccount/),
230Damian Conway and Abigail's Perl module
231[Regexp::Common](http://search.cpan.org/%7Eabigail/Regexp-Common-2.120/lib/Regexp/Common.pm),
232Sean M. Burke's Perl module
233[Win32::Autoglob](http://search.cpan.org/%7Esburke/Win32-Autoglob-1.01/Autoglob.pm),
234and Tye McQueen's Perl module
235[Algorithm::Diff](http://search.cpan.org/%7Etyemq/Algorithm-Diff-1.1902/lib/Algorithm/Diff.pm).
236Language scale factors were derived from Mayes Consulting, LLC web site
237http://softwareestimator.com/IndustryData2.htm.
238[](1}}})
239
240<a name="Docker"></a> []({{{1)
241## Run via docker
242```shell
243docker run --rm -v $PWD:/tmp aldanial/cloc
244```
245## Install via package manager
246Depending your operating system, one of these installation methods may
247work for you (all but the last two entries for Windows require
248a Perl interpreter):
249
250    npm install -g cloc              # https://www.npmjs.com/package/cloc
251    sudo apt install cloc            # Debian, Ubuntu
252    sudo yum install cloc            # Red Hat, Fedora
253    sudo dnf install cloc            # Fedora 22 or later
254    sudo pacman -S cloc              # Arch
255    sudo emerge -av dev-util/cloc    # Gentoo https://packages.gentoo.org/packages/dev-util/cloc
256    sudo apk add cloc                # Alpine Linux
257    doas pkg_add cloc                # OpenBSD
258    sudo pkg install cloc            # FreeBSD
259    sudo port install cloc           # macOS with MacPorts
260    brew install cloc                # macOS with Homebrew
261    choco install cloc               # Windows with Chocolatey
262    scoop install cloc               # Windows with Scoop
263
264**Note**: I don't control any of these packages.
265If you encounter a bug in cloc using one of the above
266packages, try with cloc pulled from the latest stable release here
267on GitHub (link follows below) before submitting a problem report.
268[](1}}})
269<a name="Stable"></a> []({{{1)
270## Stable release
271https://github.com/AlDanial/cloc/releases/latest
272
273<a name="Dev"></a>
274## Development version
275https://github.com/AlDanial/cloc/raw/master/cloc
276[](1}}})
277<a name="License"></a> []({{{1)
278# [License &#9650;](#___top "click to go to top of document")
279
280cloc is licensed under the
281[GNU General Public License, v 2](http://www.gnu.org/licenses/gpl-2.0.html),
282excluding portions which
283are copied from other sources. Code
284copied from the Regexp::Common, Win32::Autoglob, and Algorithm::Diff
285Perl modules is subject to the
286[Artistic License](http://www.opensource.org/licenses/artistic-license-2.0.php).
287[](1}}})
288<a name="why_use"></a> []({{{1)
289# [Why Use cloc? &#9650;](#___top "click to go to top of document")
290
291cloc has many features that make it easy to use, thorough, extensible, and portable:
292
2931.  Exists as a single, self-contained file that requires minimal installation effort---just download the file and run it.
2942.  Can read language comment definitions from a file and thus potentially work with computer languages that do not yet exist.
2953.  Allows results from multiple runs to be summed together by language and by project.
2964.  Can produce results in a variety of formats: plain text, SQL, JSON, XML, YAML, comma separated values.
2975.  Can count code within compressed archives (tar balls, Zip files, Java .ear files).
2986.  Has numerous troubleshooting options.
2997.  Handles file and directory names with spaces and other unusual characters.
3008.  Has no dependencies outside the standard Perl distribution.
3019.  Runs on Linux, FreeBSD, NetBSD, OpenBSD, macOS, AIX, HP-UX, Solaris, IRIX, and z/OS systems that have Perl 5.6 or higher. The source version runs on Windows with either ActiveState Perl, Strawberry Perl, Cygwin, or MobaXTerm+Perl plugin. Alternatively on Windows one can run the Windows binary which has no dependencies.
302[](1}}})
303
304<a name="Other_Counters"></a> []({{{1)
305# [Other Counters &#9650;](#___top "click to go to top of document")
306
307If cloc does not suit your needs here are other freely available counters to consider:
308
309*   [loc](https://github.com/cgag/loc/)
310*   [gocloc](https://github.com/hhatto/gocloc/)
311*   [Ohcount](https://github.com/blackducksoftware/ohcount/)
312*   [scc](https://github.com/boyter/scc/)
313*   [sclc](https://code.google.com/archive/p/sclc/)
314*   [SLOCCount](http://www.dwheeler.com/sloccount/)
315*   [Sonar](http://www.sonarsource.org/)
316*   [tokei](https://github.com/Aaronepower/tokei/)
317*   [Unified Code Count](http://csse.usc.edu/ucc_new/wordpress/)
318
319Other references:
320
321*   QSM's [directory](http://www.qsm.com/CodeCounters.html) of code counting tools.
322*   The [Wikipedia entry](http://en.wikipedia.org/wiki/Source_lines_of_code) for source code line counts.
323[](1}}})
324
325# <a name="regexp_common">Regexp::Common, Digest::MD5, Win32::Autoglob, Algorithm::Diff</a> []({{{1)
326
327Although cloc does not need Perl modules outside those found in the
328standard distribution, cloc does rely on a few external modules. Code
329from three of these external modules--Regexp::Common, Win32::Autoglob,
330and Algorithm::Diff--is embedded within cloc. A fourth module,
331Digest::MD5, is used only if it is available. If cloc finds
332Regexp::Common or Algorithm::Diff installed locally it will use those
333installation. If it doesn't, cloc will install the parts of
334Regexp::Common and/or Algorithm:Diff it needs to temporary directories
335that are created at the start of a cloc run then removed when the run is
336complete. The necessary code from Regexp::Common v2.120 and
337Algorithm::Diff v1.1902 are embedded within the cloc source code (see
338subroutines `Install_Regexp_Common()` and `Install_Algorithm_Diff()` ).
339Only three lines are needed from Win32::Autoglob and these are included
340directly in cloc.
341
342Additionally, cloc will use Digest::MD5 to validate uniqueness among
343equally-sized input files if Digest::MD5 is installed locally.
344
345A parallel processing option, <tt>--processes=<i>N</i></tt>, was introduced with
346cloc version 1.76 to enable faster runs on multi-core machines.  However,
347to use it, one must have the module Parallel::ForkManager installed.
348This module does not work reliably on Windows so parallel processing
349will only work on Unix-like operating systems.
350
351The Windows binary is built on a computer that has both Regexp::Common
352and Digest::MD5 installed locally.
353[](1}}})
354<a name="building_exe"></a> []({{{1)
355# [Building a Windows Executable &#9650;](#___top "click to go to top of document")
356
357The Windows downloads
358<tt>cloc-1.90.exe</tt> and
359<tt>cloc-1.88.exe</tt> were built on a 64 bit Windows 10 computer
360using
361[Strawberry Perl](http://strawberryperl.com/)
3625.30.2 and
363[PAR::Packer](http://search.cpan.org/~rschupp/PAR-Packer-1.050/lib/pp.pm)
364to build the `.exe`.
365
366Release 1.86 was built on a 64 bit Windows 10 virtual machine
367downloaded from https://developer.microsoft.com/en-us/microsoft-edge/tools/vms/;
368releases 1.74 through 1.84
369were was built on a 32 bit Windows 7 virtual machine
370using Strawberry Perl 5.26.1.1, while
3711.70 and 1.72 were built with Strawberry Perl 5.24.0.1
372on an Amazon Web Services t2.micro instance running Microsoft Windows Server 2008
373(32 bit for 1.70 and 1.72; 64 bit for 1.74).
374Release 1.66 was built on a 32 bit Windows 7 VirtualBox image.
375Windows executables of cloc versions 1.60 and earlier were built with
376[perl2exe](http://www.indigostar.com/perl2exe/) on a 32 bit Windows
377XP computer. A small modification was made to the cloc source code
378before passing it to perl2exe; lines 87 and 88 were uncommented:
379
380<pre>
381<font color="gray">85</font>  # Uncomment next two lines when building Windows executable with perl2exe
382<font color="gray">86</font>  # or if running on a system that already has Regexp::Common.
383<font color="gray">87</font>  <font color="red">#use Regexp::Common;</font>
384<font color="gray">88</font>  <font color="red">#$HAVE_Rexexp_Common = 1;</font>
385</pre>
386
387#### Is the Windows executable safe to run?  Does it have malware?
388
389Ideally, no one would need the Windows executable because they
390have a Perl interpreter installed on their machines and can
391run the cloc source file.
392On centrally-managed corporate Windows machines, however, this
393this may be difficult or impossible.
394
395The Windows executable distributed with cloc is provided as
396a best-effort of a virus and malware-free `.exe`.
397You are encouraged to run your own virus scanners against the
398executable and also check sites such
399https://www.virustotal.com/ .
400The entries for recent versions are:
401
402cloc-1.90.exe:
403https://www.virustotal.com/gui/file/d655caae55486f9bac39f7e3c7b7553bcfcfe2b88914c79bfc328055f22b8a37/detection
404
405cloc-1.88.exe:
406https://www.virustotal.com/gui/file/97d5d2631d1cccdbfd99267ab8a4cf5968816bbe52c0f9324e72e768857f642d/detection
407
408cloc-1.86.exe:
409https://www.virustotal.com/gui/file/1b2e189df1834411b34534db446330d1c379b4bc008af3042ee9ade818c6a1c8/detection
410
411cloc-1.84.exe:
412https://www.virustotal.com/gui/file/e73d490c1e4ae2f50ee174005614029b4fa2610dcb76988714839d7be68479af/detection
413
414cloc-1.82.exe:
415https://www.virustotal.com/#/file/2e5fb443fdefd776d7b6b136a25e5ee2048991e735042897dbd0bf92efb16563/detection
416
417cloc-1.80.exe:
418https://www.virustotal.com/#/file/9e547b01c946aa818ffad43b9ebaf05d3da08ed6ca876ef2b6847be3bf1cf8be/detection
419
420cloc-1.78.exe:
421https://www.virustotal.com/#/file/256ade3df82fa92febf2553853ed1106d96c604794606e86efd00d55664dd44f/detection
422
423cloc-1.76.exe:
424https://www.virustotal.com/#/url/c1b9b9fe909f91429f95d41e9a9928ab7c58b21351b3acd4249def2a61acd39d/detection
425
426cloc-1.74_x86.exe:
427https://www.virustotal.com/#/file/b73dece71f6d3199d90d55db53a588e1393c8dbf84231a7e1be2ce3c5a0ec75b/detection
428
429cloc 1.72 exe:
430https://www.virustotal.com/en/url/8fd2af5cd972f648d7a2d7917bc202492012484c3a6f0b48c8fd60a8d395c98c/analysis/
431
432cloc 1.70 exe:
433https://www.virustotal.com/en/url/63edef209099a93aa0be1a220dc7c4c7ed045064d801e6d5daa84ee624fc0b4a/analysis/
434
435cloc 1.68 exe:
436https://www.virustotal.com/en/file/c484fc58615fc3b0d5569b9063ec1532980281c3155e4a19099b11ef1c24443b/analysis/
437
438cloc 1.66 exe:
439https://www.virustotal.com/en/file/54d6662e59b04be793dd10fa5e5edf7747cf0c0cc32f71eb67a3cf8e7a171d81/analysis/1453601367/
440
441#### Why is the Windows executable so large?
442
443Windows executables of cloc versions 1.60 and earlier, created with
444perl2exe as noted above, are about 1.6 MB, while versions 1.62 and 1.54, created
445with `PAR::Packer`, are 11 MB.
446Version 1.66, built with a newer version of `PAR::Packer`, is about 5.5 MB.
447Why are the `PAR::Packer`, executables so
448much larger than those built with perl2exe? My theory is that perl2exe
449uses smarter tree pruning logic
450than `PAR::Packer`, but that's pure speculation.
451
452#### Create your own executable
453The most robust option for creating a Windows executable of
454cloc is to use [ActiveState's Perl Development Kit](http://www.activestate.com/perl-dev-kit).
455It includes a utility, `perlapp`, which can build stand-alone
456Windows, Mac, and Linux binaries of Perl source code.
457
458[perl2exe](http://www.indigostar.com/perl2exe/)
459will also do the trick.  If you do have `perl2exe`, modify lines
46084-87 in the cloc source code for a minor code
461modification that is necessary to make a cloc Windows executable.
462
463Otherwise, to build a Windows executable with `pp` from
464`PAR::Packer`, first install a Windows-based Perl distribution
465(for example Strawberry Perl or ActivePerl) following their
466instructions. Next, open a command prompt, aka a DOS window and install
467the PAR::Packer module. Finally, invoke the newly installed `pp`
468command with the cloc source code to create an `.exe` file:
469
470<pre>
471C:> cpan -i Digest::MD5
472C:> cpan -i Regexp::Common
473C:> cpan -i Algorithm::Diff
474C:> cpan -i PAR::Packer
475C:> pp -M Digest::MD5 -c -x -o cloc-1.90.exe cloc-1.90.pl
476</pre>
477
478A variation on the instructions above is if you installed the portable
479version of Strawberry Perl, you will need to run `portableshell.bat` first
480to properly set up your environment.
481
482[](1}}})
483<a name="Basic_Use"></a> []({{{1)
484# [Basic Use &#9650;](#___top "click to go to top of document")
485
486cloc is a command line program that takes file, directory, and/or
487archive names as inputs. Here's an example of running cloc against the
488Perl v5.22.0 source distribution:
489
490<pre>
491prompt> cloc perl-5.22.0.tar.gz
492    5605 text files.
493    5386 unique files.
494    2176 files ignored.
495
496https://github.com/AlDanial/cloc v 1.65  T=25.49 s (134.7 files/s, 51980.3 lines/s)
497-----------------------------------------------------------------------------------
498Language                         files          blank        comment           code
499-----------------------------------------------------------------------------------
500Perl                              2892         136396         184362         536445
501C                                  130          24676          33684         155648
502C/C++ Header                       148           9766          16569         147858
503Bourne Shell                       112           4044           6796          42668
504Pascal                               8            458           1603           8592
505XML                                 33            142              0           2410
506YAML                                49             20             15           2078
507C++                                 10            313            277           2033
508make                                 4            426            488           1986
509Prolog                              12            438              2           1146
510JSON                                14              1              0           1037
511yacc                                 1             85             76            998
512Windows Message File                 1            102             11            489
513DOS Batch                           14             92             41            389
514Windows Resource File                3             10              0             85
515D                                    1              5              7              8
516Lisp                                 2              0              3              4
517-----------------------------------------------------------------------------------
518SUM:                              3434         176974         243934         903874
519-----------------------------------------------------------------------------------
520
521</pre>
522
523To run cloc on Windows computers, open up a command (aka DOS) window
524and invoke cloc.exe from the command line there.
525Alternatively, try ClocViewer, the GUI wrapper around cloc found at
526https://github.com/Roemer/ClocViewer.
527
528See also https://github.com/jmensch1/codeflower for a
529graphical rendering of cloc results.
530[](1}}})
531<a name="Options"></a> []({{{1)
532# [Options &#9650;](#___top "click to go to top of document")
533
534<pre>
535prompt> cloc --help
536
537Usage: cloc [options] &lt;file(s)/dir(s)/git hash(es)&gt; | &lt;set 1&gt; &lt;set 2&gt; | &lt;report files&gt;
538
539 Count, or compute differences of, physical lines of source code in the
540 given files (may be archives such as compressed tarballs or zip files,
541 or git commit hashes or branch names) and/or recursively below the
542 given directories.
543
544 Input Options
545   --extract-with=&lt;cmd&gt;      This option is only needed if cloc is unable
546                             to figure out how to extract the contents of
547                             the input file(s) by itself.
548                             Use &lt;cmd&gt; to extract binary archive files (e.g.:
549                             .tar.gz, .zip, .Z).  Use the literal '&gt;FILE&lt;' as
550                             a stand-in for the actual file(s) to be
551                             extracted.  For example, to count lines of code
552                             in the input files
553                                gcc-4.2.tar.gz  perl-5.8.8.tar.gz
554                             on Unix use
555                               --extract-with='gzip -dc &gt;FILE&lt; | tar xf -'
556                             or, if you have GNU tar,
557                               --extract-with='tar zxf &gt;FILE&lt;'
558                             and on Windows use, for example:
559                               --extract-with="\"c:\Program Files\WinZip\WinZip32.exe\" -e -o &gt;FILE&lt; ."
560                             (if WinZip is installed there).
561   --list-file=&lt;file&gt;        Take the list of file and/or directory names to
562                             process from &lt;file&gt;, which has one file/directory
563                             name per line.  Only exact matches are counted;
564                             relative path names will be resolved starting from
565                             the directory where cloc is invoked.  Set &lt;file&gt;
566                             to - to read file names from a STDIN pipe.
567                             See also --exclude-list-file.
568   --diff-list-file=&lt;file&gt;   Take the pairs of file names to be diff'ed from
569                             &lt;file&gt;, whose format matches the output of
570                             --diff-alignment.  (Run with that option to
571                             see a sample.)  The language identifier at the
572                             end of each line is ignored.  This enables --diff
573                             mode and bypasses file pair alignment logic.
574   --vcs=&lt;VCS&gt;               Invoke a system call to &lt;VCS&gt; to obtain a list of
575                             files to work on.  If &lt;VCS&gt; is 'git', then will
576                             invoke 'git ls-files' to get a file list and
577                             'git submodule status' to get a list of submodules
578                             whose contents will be ignored.  See also --git
579                             which accepts git commit hashes and branch names.
580                             If &lt;VCS&gt; is 'svn' then will invoke 'svn list -R'.
581                             The primary benefit is that cloc will then skip
582                             files explicitly excluded by the versioning tool
583                             in question, ie, those in .gitignore or have the
584                             svn:ignore property.
585                             Alternatively &lt;VCS&gt; may be any system command
586                             that generates a list of files.
587                             Note:  cloc must be in a directory which can read
588                             the files as they are returned by &lt;VCS&gt;.  cloc will
589                             not download files from remote repositories.
590                             'svn list -R' may refer to a remote repository
591                             to obtain file names (and therefore may require
592                             authentication to the remote repository), but
593                             the files themselves must be local.
594                             Setting &lt;VCS&gt; to 'auto' selects between 'git'
595                             and 'svn' (or neither) depending on the presence
596                             of a .git or .svn subdirectory below the directory
597                             where cloc is invoked.
598   --unicode                 Check binary files to see if they contain Unicode
599                             expanded ASCII text.  This causes performance to
600                             drop noticeably.
601
602 Processing Options
603   --autoconf                Count .in files (as processed by GNU autoconf) of
604                             recognized languages.  See also --no-autogen.
605   --by-file                 Report results for every source file encountered.
606   --by-file-by-lang         Report results for every source file encountered
607                             in addition to reporting by language.
608   --config &lt;file&gt;           Read command line switches from &lt;file&gt; instead of
609                             the default location of /home/al/.config/cloc/options.txt.
610                             The file should contain one switch, along with
611                             arguments (if any), per line.  Blank lines and lines
612                             beginning with '#' are skipped.  Options given on
613                             the command line take priority over entries read from
614                             the file.
615   --count-and-diff &lt;set1&gt; &lt;set2&gt;
616                             First perform direct code counts of source file(s)
617                             of &lt;set1&gt; and &lt;set2&gt; separately, then perform a diff
618                             of these.  Inputs may be pairs of files, directories,
619                             or archives.  If --out or --report-file is given,
620                             three output files will be created, one for each
621                             of the two counts and one for the diff.  See also
622                             --diff, --diff-alignment, --diff-timeout,
623                             --ignore-case, --ignore-whitespace.
624   --diff &lt;set1&gt; &lt;set2&gt;      Compute differences in code and comments between
625                             source file(s) of &lt;set1&gt; and &lt;set2&gt;.  The inputs
626                             may be any mix of files, directories, archives,
627                             or git commit hashes.  Use --diff-alignment to
628                             generate a list showing which file pairs where
629                             compared.  When comparing git branches, only files
630                             which have changed in either commit are compared.
631                             See also --git, --count-and-diff, --diff-alignment,
632                             --diff-list-file, --diff-timeout, --ignore-case,
633                             --ignore-whitespace.
634   --diff-timeout &lt;N&gt;        Ignore files which take more than &lt;N&gt; seconds
635                             to process.  Default is 10 seconds.  Setting &lt;N&gt;
636                             to 0 allows unlimited time.  (Large files with many
637                             repeated lines can cause Algorithm::Diff::sdiff()
638                             to take hours.) See also --timeout.
639   --docstring-as-code       cloc considers docstrings to be comments, but this is
640                             not always correct as docstrings represent regular
641                             strings when they appear on the right hand side of an
642                             assignment or as function arguments.  This switch
643                             forces docstrings to be counted as code.
644   --follow-links            [Unix only] Follow symbolic links to directories
645                             (sym links to files are always followed).
646                             See also --stat.
647   --force-lang=&lt;lang&gt;[,&lt;ext&gt;]
648                             Process all files that have a &lt;ext&gt; extension
649                             with the counter for language &lt;lang&gt;.  For
650                             example, to count all .f files with the
651                             Fortran 90 counter (which expects files to
652                             end with .f90) instead of the default Fortran 77
653                             counter, use
654                               --force-lang="Fortran 90",f
655                             If &lt;ext&gt; is omitted, every file will be counted
656                             with the &lt;lang&gt; counter.  This option can be
657                             specified multiple times (but that is only
658                             useful when &lt;ext&gt; is given each time).
659                             See also --script-lang, --lang-no-ext.
660   --force-lang-def=&lt;file&gt;   Load language processing filters from &lt;file&gt;,
661                             then use these filters instead of the built-in
662                             filters.  Note:  languages which map to the same
663                             file extension (for example:
664                             MATLAB/Mathematica/Objective-C/MUMPS/Mercury;
665                             Pascal/PHP; Lisp/OpenCL; Lisp/Julia; Perl/Prolog)
666                             will be ignored as these require additional
667                             processing that is not expressed in language
668                             definition files.  Use --read-lang-def to define
669                             new language filters without replacing built-in
670                             filters (see also --write-lang-def,
671                             --write-lang-def-incl-dup).
672   --git                     Forces the inputs to be interpreted as git targets
673                             (commit hashes, branch names, et cetera) if these
674                             are not first identified as file or directory
675                             names.  This option overrides the --vcs=git logic
676                             if this is given; in other words, --git gets its
677                             list of files to work on directly from git using
678                             the hash or branch name rather than from
679                             'git ls-files'.  This option can be used with
680                             --diff to perform line count diffs between git
681                             commits, or between a git commit and a file,
682                             directory, or archive.  Use -v/--verbose to see
683                             the git system commands cloc issues.
684   --git-diff-rel            Same as --git --diff, or just --diff if the inputs
685                             are recognized as git targets.  Only files which
686                             have changed in either commit are compared.
687   --git-diff-all            Git diff strategy #2:  compare all files in the
688                             repository between the two commits.
689   --ignore-whitespace       Ignore horizontal white space when comparing files
690                             with --diff.  See also --ignore-case.
691   --ignore-case             Ignore changes in case within file contents;
692                             consider upper- and lowercase letters equivalent
693                             when comparing files with --diff.  See also
694                             --ignore-whitespace.
695   --ignore-case-ext         Ignore case of file name extensions.  This will
696                             cause problems counting some languages
697                             (specifically, .c and .C are associated with C and
698                             C++; this switch would count .C files as C rather
699                             than C++ on *nix operating systems).  File name
700                             case insensitivity is always true on Windows.
701   --lang-no-ext=&lt;lang&gt;      Count files without extensions using the &lt;lang&gt;
702                             counter.  This option overrides internal logic
703                             for files without extensions (where such files
704                             are checked against known scripting languages
705                             by examining the first line for #!).  See also
706                             --force-lang, --script-lang.
707   --max-file-size=&lt;MB&gt;      Skip files larger than &lt;MB&gt; megabytes when
708                             traversing directories.  By default, &lt;MB&gt;=100.
709                             cloc's memory requirement is roughly twenty times
710                             larger than the largest file so running with
711                             files larger than 100 MB on a computer with less
712                             than 2 GB of memory will cause problems.
713                             Note:  this check does not apply to files
714                             explicitly passed as command line arguments.
715   --no-autogen[=list]       Ignore files generated by code-production systems
716                             such as GNU autoconf.  To see a list of these files
717                             (then exit), run with --no-autogen list
718                             See also --autoconf.
719   --original-dir            [Only effective in combination with
720                             --strip-comments]  Write the stripped files
721                             to the same directory as the original files.
722   --read-binary-files       Process binary files in addition to text files.
723                             This is usually a bad idea and should only be
724                             attempted with text files that have embedded
725                             binary data.
726   --read-lang-def=&lt;file&gt;    Load new language processing filters from &lt;file&gt;
727                             and merge them with those already known to cloc.
728                             If &lt;file&gt; defines a language cloc already knows
729                             about, cloc's definition will take precedence.
730                             Use --force-lang-def to over-ride cloc's
731                             definitions (see also --write-lang-def,
732                             --write-lang-def-incl-dup).
733   --script-lang=&lt;lang&gt;,&lt;s&gt;  Process all files that invoke &lt;s&gt; as a #!
734                             scripting language with the counter for language
735                             &lt;lang&gt;.  For example, files that begin with
736                                #!/usr/local/bin/perl5.8.8
737                             will be counted with the Perl counter by using
738                                --script-lang=Perl,perl5.8.8
739                             The language name is case insensitive but the
740                             name of the script language executable, &lt;s&gt;,
741                             must have the right case.  This option can be
742                             specified multiple times.  See also --force-lang,
743                             --lang-no-ext.
744   --sdir=&lt;dir&gt;              Use &lt;dir&gt; as the scratch directory instead of
745                             letting File::Temp chose the location.  Files
746                             written to this location are not removed at
747                             the end of the run (as they are with File::Temp).
748   --skip-uniqueness         Skip the file uniqueness check.  This will give
749                             a performance boost at the expense of counting
750                             files with identical contents multiple times
751                             (if such duplicates exist).
752   --stat                    Some file systems (AFS, CD-ROM, FAT, HPFS, SMB)
753                             do not have directory 'nlink' counts that match
754                             the number of its subdirectories.  Consequently
755                             cloc may undercount or completely skip the
756                             contents of such file systems.  This switch forces
757                             File::Find to stat directories to obtain the
758                             correct count.  File search speed will decrease.
759                             See also --follow-links.
760   --stdin-name=&lt;file&gt;       Give a file name to use to determine the language
761                             for standard input.  (Use - as the input name to
762                             receive source code via STDIN.)
763   --strip-comments=&lt;ext&gt;    For each file processed, write to the current
764                             directory a version of the file which has blank
765                             and commented lines removed (in-line comments
766                             persist).  The name of each stripped file is the
767                             original file name with .&lt;ext&gt; appended to it.
768                             It is written to the current directory unless
769                             --original-dir is on.
770   --strip-str-comments      Replace comment markers embedded in strings with
771                             'xx'.  This attempts to work around a limitation
772                             in Regexp::Common::Comment where comment markers
773                             embedded in strings are seen as actual comment
774                             markers and not strings, often resulting in a
775                             'Complex regular subexpression recursion limit'
776                             warning and incorrect counts.  There are two
777                             disadvantages to using this switch:  1/code count
778                             performance drops, and 2/code generated with
779                             --strip-comments will contain different strings
780                             where ever embedded comments are found.
781   --sum-reports             Input arguments are report files previously
782                             created with the --report-file option in plain
783                             format (eg. not JSON, YAML, XML, or SQL).
784                             Makes a cumulative set of results containing the
785                             sum of data from the individual report files.
786   --timeout &lt;N&gt;             Ignore files which take more than &lt;N&gt; seconds
787                             to process at any of the language's filter stages.
788                             The default maximum number of seconds spent on a
789                             filter stage is the number of lines in the file
790                             divided by one thousand.  Setting &lt;N&gt; to 0 allows
791                             unlimited time.  See also --diff-timeout.
792   --processes=NUM           [Available only on systems with a recent version
793                             of the Parallel::ForkManager module.  Not
794                             available on Windows.] Sets the maximum number of
795                             cores that cloc uses.  The default value of 0
796                             disables multiprocessing.
797   --unix                    Override the operating system autodetection
798                             logic and run in UNIX mode.  See also
799                             --windows, --show-os.
800   --use-sloccount           If SLOCCount is installed, use its compiled
801                             executables c_count, java_count, pascal_count,
802                             php_count, and xml_count instead of cloc's
803                             counters.  SLOCCount's compiled counters are
804                             substantially faster than cloc's and may give
805                             a performance improvement when counting projects
806                             with large files.  However, these cloc-specific
807                             features will not be available: --diff,
808                             --count-and-diff, --strip-comments, --unicode.
809   --windows                 Override the operating system autodetection
810                             logic and run in Microsoft Windows mode.
811                             See also --unix, --show-os.
812
813 Filter Options
814   --exclude-content=&lt;regex&gt; Exclude files containing text that matches the given
815                             regular expression.
816   --exclude-dir=&lt;D1&gt;[,D2,]  Exclude the given comma separated directories
817                             D1, D2, D3, et cetera, from being scanned.  For
818                             example  --exclude-dir=.cache,test  will skip
819                             all files and subdirectories that have /.cache/
820                             or /test/ as their parent directory.
821                             Directories named .bzr, .cvs, .hg, .git, .svn,
822                             and .snapshot are always excluded.
823                             This option only works with individual directory
824                             names so including file path separators is not
825                             allowed.  Use --fullpath and --not-match-d=&lt;regex&gt;
826                             to supply a regex matching multiple subdirectories.
827   --exclude-ext=&lt;ext1&gt;[,&lt;ext2&gt;[...]]
828                             Do not count files having the given file name
829                             extensions.
830   --exclude-lang=&lt;L1&gt;[,L2[...]]
831                             Exclude the given comma separated languages
832                             L1, L2, L3, et cetera, from being counted.
833   --exclude-list-file=&lt;file&gt;  Ignore files and/or directories whose names
834                             appear in &lt;file&gt;.  &lt;file&gt; should have one file
835                             name per line.  Only exact matches are ignored;
836                             relative path names will be resolved starting from
837                             the directory where cloc is invoked.
838                             See also --list-file.
839   --fullpath                Modifies the behavior of --match-f, --not-match-f,
840                             and --not-match-d to include the file's path
841                             in the regex, not just the file's basename.
842                             (This does not expand each file to include its
843                             absolute path, instead it uses as much of
844                             the path as is passed in to cloc.)
845                             Note:  --match-d always looks at the full
846                             path and therefore is unaffected by --fullpath.
847   --include-ext=&lt;ext1&gt;[,ext2[...]]
848                             Count only languages having the given comma
849                             separated file extensions.  Use --show-ext to
850                             see the recognized extensions.
851   --include-lang=&lt;L1&gt;[,L2[...]]
852                             Count only the given comma separated languages
853                             L1, L2, L3, et cetera.  Use --show-lang to see
854                             the list of recognized languages.
855   --match-d=&lt;regex&gt;         Only count files in directories matching the Perl
856                             regex.  For example
857                               --match-d='/(src|include)/'
858                             only counts files in directories containing
859                             /src/ or /include/.  Unlike --not-match-d,
860                             --match-f, and --not-match-f, --match-d always
861                             compares the fully qualified path against the
862                             regex.
863   --not-match-d=&lt;regex&gt;     Count all files except those in directories
864                             matching the Perl regex.  Only the trailing
865                             directory name is compared, for example, when
866                             counting in /usr/local/lib, only 'lib' is
867                             compared to the regex.
868                             Add --fullpath to compare parent directories to
869                             the regex.
870                             Do not include file path separators at the
871                             beginning or end of the regex.
872   --match-f=&lt;regex&gt;         Only count files whose basenames match the Perl
873                             regex.  For example
874                               --match-f='^[Ww]idget'
875                             only counts files that start with Widget or widget.
876                             Add --fullpath to include parent directories
877                             in the regex instead of just the basename.
878   --not-match-f=&lt;regex&gt;     Count all files except those whose basenames
879                             match the Perl regex.  Add --fullpath to include
880                             parent directories in the regex instead of just
881                             the basename.
882   --skip-archive=&lt;regex&gt;    Ignore files that end with the given Perl regular
883                             expression.  For example, if given
884                               --skip-archive='(zip|tar(.(gz|Z|bz2|xz|7z))?)'
885                             the code will skip files that end with .zip,
886                             .tar, .tar.gz, .tar.Z, .tar.bz2, .tar.xz, and
887                             .tar.7z.
888   --skip-win-hidden         On Windows, ignore hidden files.
889
890 Debug Options
891   --categorized=&lt;file&gt;      Save names of categorized files to &lt;file&gt;.
892   --counted=&lt;file&gt;          Save names of processed source files to &lt;file&gt;.
893   --diff-alignment=&lt;file&gt;   Write to &lt;file&gt; a list of files and file pairs
894                             showing which files were added, removed, and/or
895                             compared during a run with --diff.  This switch
896                             forces the --diff mode on.
897   --explain=&lt;lang&gt;          Print the filters used to remove comments for
898                             language &lt;lang&gt; and exit.  In some cases the
899                             filters refer to Perl subroutines rather than
900                             regular expressions.  An examination of the
901                             source code may be needed for further explanation.
902   --help                    Print this usage information and exit.
903   --found=&lt;file&gt;            Save names of every file found to &lt;file&gt;.
904   --ignored=&lt;file&gt;          Save names of ignored files and the reason they
905                             were ignored to &lt;file&gt;.
906   --print-filter-stages     Print processed source code before and after
907                             each filter is applied.
908   --show-ext[=&lt;ext&gt;]        Print information about all known (or just the
909                             given) file extensions and exit.
910   --show-lang[=&lt;lang&gt;]      Print information about all known (or just the
911                             given) languages and exit.
912   --show-os                 Print the value of the operating system mode
913                             and exit.  See also --unix, --windows.
914   -v[=&lt;n&gt;]                  Verbose switch (optional numeric value).
915   -verbose[=&lt;n&gt;]            Long form of -v.
916   --version                 Print the version of this program and exit.
917   --write-lang-def=&lt;file&gt;   Writes to &lt;file&gt; the language processing filters
918                             then exits.  Useful as a first step to creating
919                             custom language definitions. Note: languages which
920                             map to the same file extension will be excluded.
921                             (See also --force-lang-def, --read-lang-def).
922   --write-lang-def-incl-dup=&lt;file&gt;
923                             Same as --write-lang-def, but includes duplicated
924                             extensions.  This generates a problematic language
925                             definition file because cloc will refuse to use
926                             it until duplicates are removed.
927
928 Output Options
929   --3                       Print third-generation language output.
930                             (This option can cause report summation to fail
931                             if some reports were produced with this option
932                             while others were produced without it.)
933   --by-percent  X           Instead of comment and blank line counts, show
934                             these values as percentages based on the value
935                             of X in the denominator:
936                                X = 'c'   -&gt; # lines of code
937                                X = 'cm'  -&gt; # lines of code + comments
938                                X = 'cb'  -&gt; # lines of code + blanks
939                                X = 'cmb' -&gt; # lines of code + comments + blanks
940                             For example, if using method 'c' and your code
941                             has twice as many lines of comments as lines
942                             of code, the value in the comment column will
943                             be 200%.  The code column remains a line count.
944   --csv                     Write the results as comma separated values.
945   --csv-delimiter=&lt;C&gt;       Use the character &lt;C&gt; as the delimiter for comma
946                             separated files instead of ,.  This switch forces --csv to be on.
947   --file-encoding=&lt;E&gt;       Write output files using the &lt;E&gt; encoding instead of
948                             the default ASCII (&lt;E&gt; = 'UTF-7').  Examples: 'UTF-16',
949                             'euc-kr', 'iso-8859-16'.  Known encodings can be
950                             printed with
951                               perl -MEncode -e 'print join("\n", Encode-&gt;encodings(":all")), "\n"'
952   --hide-rate               Do not show line and file processing rates in the
953                             output header. This makes output deterministic.
954   --json                    Write the results as JavaScript Object Notation
955                             (JSON) formatted output.
956   --md                      Write the results as Markdown-formatted text.
957   --out=&lt;file&gt;              Synonym for --report-file=&lt;file&gt;.
958   --progress-rate=&lt;n&gt;       Show progress update after every &lt;n&gt; files are
959                             processed (default &lt;n&gt;=100).  Set &lt;n&gt; to 0 to
960                             suppress progress output (useful when redirecting
961                             output to STDOUT).
962   --quiet                   Suppress all information messages except for
963                             the final report.
964   --report-file=&lt;file&gt;      Write the results to &lt;file&gt; instead of STDOUT.
965   --sql=&lt;file&gt;              Write results as SQL create and insert statements
966                             which can be read by a database program such as
967                             SQLite.  If &lt;file&gt; is -, output is sent to STDOUT.
968   --sql-append              Append SQL insert statements to the file specified
969                             by --sql and do not generate table creation
970                             statements.  Only valid with the --sql option.
971   --sql-project=&lt;name&gt;      Use &lt;name&gt; as the project identifier for the
972                             current run.  Only valid with the --sql option.
973   --sql-style=&lt;style&gt;       Write SQL statements in the given style instead
974                             of the default SQLite format.  Styles include
975                             'Oracle' and 'Named_Columns'.
976   --sum-one                 For plain text reports, show the SUM: output line
977                             even if only one input file is processed.
978   --xml                     Write the results in XML.
979   --xsl=&lt;file&gt;              Reference &lt;file&gt; as an XSL stylesheet within
980                             the XML output.  If &lt;file&gt; is 1 (numeric one),
981                             writes a default stylesheet, cloc.xsl (or
982                             cloc-diff.xsl if --diff is also given).
983                             This switch forces --xml on.
984   --yaml                    Write the results in YAML.
985</pre>
986[](1}}})
987<a name="Languages"></a> []({{{1)
988# [Recognized Languages &#9650;](#___top "click to go to top of document")
989
990<pre>
991prompt> cloc --show-lang
992
993ABAP                       (abap)
994ActionScript               (as)
995Ada                        (ada, adb, ads, pad)
996ADSO/IDSM                  (adso)
997Agda                       (agda, lagda)
998AMPLE                      (ample, dofile, startup)
999Ant                        (build.xml, build.xml)
1000ANTLR Grammar              (g, g4)
1001Apex Class                 (cls)
1002Apex Trigger               (trigger)
1003APL                        (apl, apla, aplc, aplf, apli, apln, aplo, dyalog, dyapp, mipage)
1004Arduino Sketch             (ino, pde)
1005AsciiDoc                   (adoc, asciidoc)
1006ASP                        (asa, ashx, asp, axd)
1007ASP.NET                    (asax, ascx, asmx, aspx, master, sitemap, webinfo)
1008AspectJ                    (aj)
1009Assembly                   (a51, asm, nasm, S, s)
1010AutoHotkey                 (ahk, ahkl)
1011awk                        (auk, awk, gawk, mawk, nawk)
1012Bazel                      (bazel, BUILD)
1013BizTalk Orchestration      (odx)
1014BizTalk Pipeline           (btp)
1015Blade                      (blade, blade.php)
1016Bourne Again Shell         (bash)
1017Bourne Shell               (sh)
1018BrightScript               (brs)
1019builder                    (xml.builder)
1020C                          (c, cats, ec, idc, pgc)
1021C Shell                    (csh, tcsh)
1022C#                         (cs)
1023C# Designer                (designer.cs)
1024C++                        (C, c++, cc, CPP, cpp, cxx, h++, inl, ipp, pcc, tcc, tpp)
1025C/C++ Header               (H, h, hh, hpp, hxx)
1026Cake Build Script          (cake)
1027CCS                        (ccs)
1028Chapel                     (chpl)
1029Clean                      (dcl, icl)
1030Clojure                    (boot, cl2, clj, cljs.hl, cljscm, cljx, hic, riemann.config)
1031ClojureC                   (cljc)
1032ClojureScript              (cljs)
1033CMake                      (cmake, cmake.in, CMakeLists.txt)
1034COBOL                      (CBL, cbl, ccp, COB, cob, cobol, cpy)
1035CoffeeScript               (_coffee, cakefile, cjsx, coffee, iced)
1036ColdFusion                 (cfm, cfml)
1037ColdFusion CFScript        (cfc)
1038Coq                        (v)
1039Crystal                    (cr)
1040CSON                       (cson)
1041CSS                        (css)
1042CSV                        (csv)
1043Cucumber                   (feature)
1044CUDA                       (cu, cuh)
1045Cython                     (pxd, pxi, pyx)
1046D                          (d)
1047DAL                        (da)
1048Dart                       (dart)
1049Delphi Form                (dfm)
1050dhall                      (dhall)
1051DIET                       (dt)
1052diff                       (diff, patch)
1053DITA                       (dita)
1054Dockerfile                 (Dockerfile, dockerfile)
1055DOORS Extension Language   (dxl)
1056DOS Batch                  (BAT, bat, BTM, btm, CMD, cmd)
1057Drools                     (drl)
1058DTD                        (dtd)
1059dtrace                     (d)
1060ECPP                       (ecpp)
1061EEx                        (eex)
1062EJS                        (ejs)
1063Elixir                     (ex, exs)
1064Elm                        (elm)
1065Embedded Crystal           (ecr)
1066ERB                        (ERB, erb)
1067Erlang                     (app.src, emakefile, erl, hrl, rebar.config, rebar.config.lock, rebar.lock, xrl, yrl)
1068Expect                     (exp)
1069F#                         (fsi, fs, fs)
1070F# Script                  (fsx)
1071Fennel                     (fnl)
1072Fish Shell                 (fish)
1073Focus                      (focexec)
1074Forth                      (4th, e4, f83, fb, forth, fpm, fr, frt, ft, fth, rx, fs, f, for)
1075Fortran 77                 (F, F77, f77, FOR, FTN, ftn, pfo, f, for)
1076Fortran 90                 (F90, f90)
1077Fortran 95                 (F95, f95)
1078Freemarker Template        (ftl)
1079FXML                       (fxml)
1080GDScript                   (gd)
1081Gencat NLS                 (msg)
1082Glade                      (glade, ui)
1083Gleam                      (gleam)
1084GLSL                       (comp, fp, frag, frg, fsh, fshader, geo, geom, glsl, glslv, gshader, tesc, tese, vert, vrx, vsh, vshader)
1085Go                         (go)
1086Godot Resource             (tres)
1087Godot Scene                (tscn)
1088Gradle                     (gradle, gradle.kts)
1089Grails                     (gsp)
1090GraphQL                    (gql, graphql, graphqls)
1091Groovy                     (gant, groovy, grt, gtpl, gvy, jenkinsfile)
1092Haml                       (haml, haml.deface)
1093Handlebars                 (handlebars, hbs)
1094Harbour                    (hb)
1095Haskell                    (hs, hsc, lhs)
1096Haxe                       (hx, hxsl)
1097HCL                        (hcl, nomad, tf, tfvars)
1098HLSL                       (cg, cginc, fxh, hlsl, hlsli, shader)
1099Hoon                       (hoon)
1100HTML                       (htm, html, html.hl, xht)
1101IDL                        (dlm, idl, pro)
1102Idris                      (idr)
1103Igor Pro                   (ipf)
1104Imba                       (imba)
1105INI                        (buildozer.spec, ini, lektorproject, prefs)
1106InstallShield              (ism)
1107IPL                        (ipl)
1108Java                       (java)
1109JavaScript                 (_js, bones, es6, jake, jakefile, js, jsb, jscad, jsfl, jsm, jss, mjs, njs, pac, sjs, ssjs, xsjs, xsjslib)
1110JavaServer Faces           (jsf)
1111JCL                        (jcl)
1112Jinja Template             (jinja, jinja2)
1113JSON                       (arcconfig, avsc, composer.lock, geojson, gltf, har, htmlhintrc, json, json-tmlanguage, jsonl, mcmeta, mcmod.info, tern-config, tern-project, tfstate, tfstate.backup, topojson, watchmanconfig, webapp, webmanifest, yyp)
1114JSON5                      (json5)
1115JSP                        (jsp, jspf)
1116JSX                        (jsx)
1117Julia                      (jl)
1118Juniper Junos              (junos)
1119Jupyter Notebook           (ipynb)
1120Kermit                     (ksc)
1121Korn Shell                 (ksh)
1122Kotlin                     (kt, ktm, kts)
1123Lean                       (hlean, lean)
1124LESS                       (less)
1125lex                        (l, lex)
1126LFE                        (lfe)
1127liquid                     (liquid)
1128Lisp                       (asd, el, lisp, lsp, cl, jl)
1129Literate Idris             (lidr)
1130LiveLink OScript           (oscript)
1131LLVM IR                    (ll)
1132Logos                      (x, xm)
1133Logtalk                    (lgt, logtalk)
1134Lua                        (lua, nse, p8, pd_lua, rbxs, wlua)
1135m4                         (ac, m4)
1136make                       (am, Gnumakefile, gnumakefile, Makefile, makefile, mk)
1137Mako                       (mako, mao)
1138Markdown                   (contents.lr, markdown, md, mdown, mdwn, mdx, mkd, mkdn, mkdown, ronn, workbook)
1139Mathematica                (cdf, ma, mathematica, mt, nbp, wl, wlt, m)
1140MATLAB                     (m)
1141Maven                      (pom, pom.xml)
1142Meson                      (meson.build)
1143Modula3                    (i3, ig, m3, mg)
1144Mojo                       (mojom)
1145MSBuild script             (btproj, csproj, msbuild, vcproj, wdproj, wixproj)
1146MUMPS                      (mps, m)
1147Mustache                   (mustache)
1148MXML                       (mxml)
1149NAnt script                (build)
1150NASTRAN DMAP               (dmap)
1151Nemerle                    (n)
1152Nim                        (nim, nim.cfg, nimble, nimrod, nims)
1153Nix                        (nix)
1154Objective-C                (m)
1155Objective-C++              (mm)
1156OCaml                      (eliom, eliomi, ml, ml4, mli, mll, mly)
1157Odin                       (odin)
1158OpenCL                     (cl)
1159Oracle Forms               (fmt)
1160Oracle PL/SQL              (bod, fnc, prc, spc, trg)
1161Oracle Reports             (rex)
1162Pascal                     (dpr, lpr, p, pas, pascal)
1163Pascal/Puppet              (pp)
1164Patran Command Language    (pcl, ses)
1165Perl                       (ack, al, cpanfile, makefile.pl, perl, ph, plh, plx, pm, psgi, rexfile, pl, p6)
1166PHP                        (aw, ctp, phakefile, php, php3, php4, php5, php_cs, php_cs.dist, phps, phpt, phtml)
1167PHP/Pascal                 (inc)
1168Pig Latin                  (pig)
1169PL/I                       (pl1)
1170PL/M                       (lit, plm)
1171PO File                    (po)
1172PowerBuilder               (pbt, sra, srf, srm, srs, sru, srw)
1173PowerShell                 (ps1, psd1, psm1)
1174ProGuard                   (pro)
1175Prolog                     (P, prolog, yap, pl, p6, pro)
1176Protocol Buffers           (proto)
1177Pug                        (jade, pug)
1178PureScript                 (purs)
1179Python                     (buck, build.bazel, gclient, gyp, gypi, lmi, py, py3, pyde, pyi, pyp, pyt, pyw, sconscript, sconstruct, snakefile, tac, workspace, wscript, wsgi, xpy)
1180QML                        (qbs, qml)
1181Qt                         (ui)
1182Qt Linguist                (ts)
1183Qt Project                 (pro)
1184R                          (expr-dist, R, r, rd, rprofile, rsx)
1185Racket                     (rkt, rktd, rktl, scrbl)
1186Raku                       (pm6, raku, rakumod)
1187Raku/Prolog                (P6, p6)
1188RAML                       (raml)
1189RapydScript                (pyj)
1190Razor                      (cshtml, razor)
1191ReasonML                   (re, rei)
1192ReScript                   (res, resi)
1193reStructuredText           (rest, rest.txt, rst, rst.txt)
1194Rexx                       (pprx, rexx)
1195Ring                       (rform, rh, ring)
1196Rmd                        (Rmd)
1197RobotFramework             (robot)
1198Ruby                       (appraisals, berksfile, brewfile, builder, buildfile, capfile, dangerfile, deliverfile, eye, fastfile, gemfile, gemfile.lock, gemspec, god, guardfile, irbrc, jarfile, jbuilder, mavenfile, mspec, podfile, podspec, pryrc, puppetfile, rabl, rake, rb, rbuild, rbw, rbx, ru, snapfile, thor, thorfile, vagrantfile, watchr)
1199Ruby HTML                  (rhtml)
1200Rust                       (rs, rs.in)
1201SaltStack                  (sls)
1202SAS                        (sas)
1203Sass                       (sass, scss)
1204Scala                      (kojo, sbt, scala)
1205Scheme                     (sc, sch, scm, sld, sps, ss, sls)
1206sed                        (sed)
1207SKILL                      (il)
1208SKILL++                    (ils)
1209Slice                      (ice)
1210Slim                       (slim)
1211Smalltalk                  (st, cs)
1212Smarty                     (smarty, tpl)
1213Softbridge Basic           (SBL, sbl)
1214Solidity                   (sol)
1215SparForte                  (sp)
1216Specman e                  (e)
1217SQL                        (cql, mysql, psql, SQL, sql, tab, udf, viw)
1218SQL Data                   (data.sql)
1219SQL Stored Procedure       (spc.sql, spoc.sql, sproc.sql, udf.sql)
1220Squirrel                   (nut)
1221Standard ML                (fun, sig, sml)
1222Starlark                   (bzl)
1223Stata                      (ado, DO, do, doh, ihlp, mata, matah, sthlp)
1224Stylus                     (styl)
1225SugarSS                    (sss)
1226Svelte                     (svelte)
1227SVG                        (SVG, svg)
1228Swift                      (swift)
1229SWIG                       (i)
1230Tcl/Tk                     (itk, tcl, tk)
1231Teamcenter met             (met)
1232Teamcenter mth             (mth)
1233TeX                        (aux, bbx, bib, bst, cbx, dtx, ins, lbx, ltx, mkii, mkiv, mkvi, sty, tex, cls)
1234Thrift                     (thrift)
1235TITAN Project File Information (tpd)
1236Titanium Style Sheet       (tss)
1237TNSDL                      (cii, cin, in1, in2, in3, in4, inf, interface, rou, sdl, sdt, spd, ssc, sst)
1238TOML                       (toml)
1239TTCN                       (ttcn, ttcn2, ttcn3, ttcnpp)
1240Twig                       (twig)
1241TypeScript                 (tsx, ts)
1242Unity-Prefab               (mat, prefab)
1243Vala                       (vala)
1244Vala Header                (vapi)
1245VB for Applications        (VBA, vba)
1246Velocity Template Language (vm)
1247Verilog-SystemVerilog      (sv, svh, v)
1248VHDL                       (VHD, vhd, VHDL, vhdl, vhf, vhi, vho, vhs, vht, vhw)
1249vim script                 (vim)
1250Visual Basic               (BAS, bas, ctl, dsr, frm, FRX, frx, VBHTML, vbhtml, vbp, vbw, cls)
1251Visual Basic .NET          (VB, vb, vbproj)
1252Visual Basic Script        (VBS, vbs)
1253Visual Fox Pro             (SCA, sca)
1254Visual Studio Solution     (sln)
1255Visualforce Component      (component)
1256Visualforce Page           (page)
1257Vuejs Component            (vue)
1258Web Services Description   (wsdl)
1259WebAssembly                (wast, wat)
1260Windows Message File       (mc)
1261Windows Module Definition  (def)
1262Windows Resource File      (rc, rc2)
1263WiX include                (wxi)
1264WiX source                 (wxs)
1265WiX string localization    (wxl)
1266WXML                       (wxml)
1267WXSS                       (wxss)
1268XAML                       (xaml)
1269xBase                      (prg, prw)
1270xBase Header               (ch)
1271XHTML                      (xhtml)
1272XMI                        (XMI, xmi)
1273XML                        (adml, admx, ant, app.config, axml, builds, ccproj, ccxml, classpath, clixml, cproject, cscfg, csdef, csl, ct, depproj, ditamap, ditaval, dll.config, dotsettings, filters, fsproj, gmx, grxml, iml, ivy, jelly, jsproj, kml, launch, mdpolicy, mjml, natvis, ndproj, nproj, nuget.config, nuspec, odd, osm, packages.config, pkgproj, plist, proj, project, props, ps1xml, psc1, pt, rdf, resx, rss, scxml, settings.stylecop, sfproj, shproj, srdf, storyboard, sttheme, sublime-snippet, targets, tmcommand, tml, tmlanguage, tmpreferences, tmsnippet, tmtheme, urdf, ux, vcxproj, vsixmanifest, vssettings, vstemplate, vxml, web.config, web.debug.config, web.release.config, wsf, x3d, xacro, xib, xlf, xliff, XML, xml, xml.dist, xproj, xspec, xul, zcml)
1274XQuery                     (xq, xql, xqm, xquery, xqy)
1275XSD                        (XSD, xsd)
1276XSLT                       (XSL, xsl, XSLT, xslt)
1277Xtend                      (xtend)
1278yacc                       (y, yacc)
1279YAML                       (clang-format, clang-tidy, gemrc, glide.lock, mir, reek, rviz, sublime-syntax, syntax, yaml, yaml-tmlanguage, yml, yml.mysql)
1280Zig                        (zig)
1281zsh                        (zsh)
1282</pre>
1283
1284The above list can be customized by reading language definitions from a
1285file with the `--read-lang-def` or `--force-lang-def` options.
1286
1287These file extensions map to multiple languages:
1288
1289*   `cl`  files could be Lisp or OpenCL
1290*   `cls` files could be Visual Basic, TeX or Apex Class
1291*   `cs`  files could be C# or Smalltalk
1292*   `d`   files could be D or dtrace
1293*   `f`   files could be Fortran 77 or Forth
1294*   `fnc` files could be Oracle PL or SQL
1295*   `for` files could be Fortran 77 or Forth
1296*   `fs`  files could be F# or Forth
1297*   `inc` files could be PHP or Pascal
1298*   `itk` files could be Tcl or Tk
1299*   `jl`  files could be Lisp or Julia
1300*   `lit` files could be PL or M
1301*   `m`   files could be MATLAB, Mathematica, Objective-C, MUMPS or Mercury
1302*   `p6`  files could be Perl or Prolog
1303*   `pl`  files could be Perl or Prolog
1304*   `PL`  files could be Perl or Prolog
1305*   `pp`  files could be Pascal or Puppet
1306*   `pro` files could be IDL, Qt Project, Prolog or ProGuard
1307*   `ts`  files could be TypeScript or Qt Linguist
1308*   `ui`  files could be Qt or Glade
1309*   `v`   files could be Verilog-SystemVerilog or Coq
1310
1311cloc has subroutines that attempt to identify the correct language based
1312on the file's contents for these special cases. Language identification
1313accuracy is a function of how much code the file contains; .m files with
1314just one or two lines for example, seldom have enough information to
1315correctly distinguish between MATLAB, Mercury, MUMPS, or Objective-C.
1316
1317Languages with file extension collisions are difficult to customize with
1318`--read-lang-def` or `--force-lang-def` as they have no mechanism to
1319identify languages with common extensions. In this situation one must
1320modify the cloc source code.
1321[](1}}})
1322<a name="How_it_works"></a> []({{{1)
1323# [How It Works &#9650;](#___top "click to go to top of document")
1324
1325cloc's method of operation resembles SLOCCount's: First, create a list
1326of files to consider. Next, attempt to determine whether or not found
1327files contain recognized computer language source code. Finally, for
1328files identified as source files, invoke language-specific routines to
1329count the number of source lines.
1330
1331A more detailed description:
1332
13331.  If the input file is an archive (such as a .tar.gz or .zip file),
1334    create a temporary directory and expand the archive there using a
1335    system call to an appropriate underlying utility (tar, bzip2, unzip,
1336    etc) then add this temporary directory as one of the inputs. (This
1337    works more reliably on Unix than on Windows.)
13382.  Use File::Find to recursively descend the input directories and make
1339    a list of candidate file names. Ignore binary and zero-sized files.
13403.  Make sure the files in the candidate list have unique contents
1341    (first by comparing file sizes, then, for similarly sized files,
1342    compare MD5 hashes of the file contents with Digest::MD5). For each
1343    set of identical files, remove all but the first copy, as determined
1344    by a lexical sort, of identical files from the set. The removed
1345    files are not included in the report. (The `--skip-uniqueness` switch
1346    disables the uniqueness tests and forces all copies of files to be
1347    included in the report.) See also the `--ignored=` switch to see which
1348    files were ignored and why.
13494.  Scan the candidate file list for file extensions which cloc
1350    associates with programming languages (see the `--show-lang` and
1351    `--show-ext` options). Files which match are classified as
1352    containing source
1353    code for that language. Each file without an extensions is opened
1354    and its first line read to see if it is a Unix shell script
1355    (anything that begins with #!). If it is shell script, the file is
1356    classified by that scripting language (if the language is
1357    recognized). If the file does not have a recognized extension or is
1358    not a recognized scripting language, the file is ignored.
13595.  All remaining files in the candidate list should now be source files
1360    for known programming languages. For each of these files:
1361
1362    1.  Read the entire file into memory.
1363    2.  Count the number of lines (= L<sub>original</sub>).
1364    3.  Remove blank lines, then count again (= L<sub>non_blank</sub>).
1365    4.  Loop over the comment filters defined for this language. (For
1366        example, C++ has two filters: (1) remove lines that start with
1367        optional whitespace followed by // and (2) remove text between
1368        /* and */) Apply each filter to the code to remove comments.
1369        Count the left over lines (= L<sub>code</sub>).
1370    5.  Save the counts for this language:
1371        * blank lines = L<sub>original</sub> - L<sub>non_blank</sub>
1372        * comment lines = L<sub>non_blank</sub> - L<sub>code</sub>
1373        * code lines = L<sub>code</sub>
1374
1375The options modify the algorithm slightly. The `--read-lang-def` option
1376for example allows the user to read definitions of comment filters,
1377known file extensions, and known scripting languages from a file. The
1378code for this option is processed between Steps 2 and 3.
1379[](1}}})
1380<a name="Advanced_Use"></a> []({{{1)
1381# [Advanced Use &#9650;](#___top "click to go to top of document")
1382[](1}}})
1383<a name="strip_comments"></a> []({{{1)
1384##  [Remove Comments from Source Code &#9650;](#___top "click to go to top of document")
1385
1386How can you tell if cloc correctly identifies comments? One way to
1387convince yourself cloc is doing the right thing is to use its
1388`--strip-comments` option to remove comments and blank lines from files, then
1389compare the stripped-down files to originals.
1390
1391Let's try this out with the SQLite amalgamation, a C file containing all
1392code needed to build the SQLite library along with a header file:
1393
1394<pre>
1395prompt> tar zxf sqlite-amalgamation-3.5.6.tar.gz
1396prompt> cd sqlite-3.5.6/
1397prompt> cloc --strip-comments=nc sqlite.c
1398       1 text file.
1399       1 unique file.
1400Wrote sqlite3.c.nc
1401       0 files ignored.
1402
1403http://cloc.sourceforge.net v 1.03  T=1.0 s (1.0 files/s, 82895.0 lines/s)
1404-------------------------------------------------------------------------------
1405Language          files     blank   comment      code    scale   3rd gen. equiv
1406-------------------------------------------------------------------------------
1407C                     1      5167     26827     50901 x   0.77 =       39193.77
1408-------------------------------------------------------------------------------
1409</pre>
1410
1411The extension argument given to --strip-comments is arbitrary; here nc was used as an abbreviation for "no comments".
1412
1413cloc removed over 31,000 lines from the file:
1414
1415<pre>
1416prompt> wc -l sqlite3.c sqlite3.c.nc
1417  82895 sqlite3.c
1418  50901 sqlite3.c.nc
1419 133796 total
1420prompt> echo "82895 - 50901" | bc
142131994
1422</pre>
1423
1424We can now compare the original file, sqlite3.c and the one stripped of
1425comments, sqlite3.c.nc with tools like diff or vimdiff and see what
1426exactly cloc considered comments and blank lines. A rigorous proof that
1427the stripped-down file contains the same C code as the original is to
1428compile these files and compare checksums of the resulting object files.
1429
1430First, the original source file:
1431
1432<pre>
1433prompt> gcc -c sqlite3.c
1434prompt> md5sum sqlite3.o
1435cce5f1a2ea27c7e44b2e1047e2588b49  sqlite3.o
1436</pre>
1437
1438Next, the version without comments:
1439
1440<pre>
1441prompt> mv sqlite3.c.nc sqlite3.c
1442prompt> gcc -c sqlite3.c
1443prompt> md5sum sqlite3.o
1444cce5f1a2ea27c7e44b2e1047e2588b49  sqlite3.o
1445</pre>
1446
1447cloc removed over 31,000 lines of comments and blanks but did not modify the source code in any significant way since the resulting object file matches the original.
1448[](1}}})
1449<a name="compressed_arch"></a> []({{{1)
1450##  [Work with Compressed Archives &#9650;](#___top "click to go to top of document")
1451Versions of cloc before v1.07 required an
1452 `--extract-with=CMD` option to tell cloc how
1453to expand an archive file.  Beginning with v1.07 this is extraction is
1454attempted automatically.  At the moment the automatic extraction method works
1455reasonably well on Unix-type OS's for the following file types:
1456`.tar.gz`,
1457`.tar.bz2`,
1458`.tar.xz`,
1459`.tgz`,
1460`.zip`,
1461`.ear`,
1462`.deb`.
1463Some of these extensions work on Windows if one has WinZip installed
1464in the default location (`C:\Program Files\WinZip\WinZip32.exe`).
1465Additionally, with newer versions of WinZip, the
1466[http://www.winzip.com/downcl.htm](command line add-on)
1467is needed for correct operation; in this case one would invoke cloc with
1468something like <br>
1469<pre>
1470 --extract-with="\"c:\Program Files\WinZip\wzunzip\" -e -o &gt;FILE&lt; ."
1471 </code>
1472</pre>
1473Ref. http://sourceforge.net/projects/cloc/forums/forum/600963/topic/4021070?message=8938196
1474
1475In situations where the automatic extraction fails, one can try the
1476`--extract-with=CMD`
1477option to count lines of code within tar files, Zip files, or
1478other compressed archives for which one has an extraction tool.
1479cloc takes the user-provided extraction command and expands the archive
1480to a temporary directory (created with File::Temp),
1481counts the lines of code in the temporary directory,
1482then removes that directory.  While not especially helpful when dealing
1483with a single compressed archive (after all, if you're going to type
1484the extraction command anyway why not just manually expand the archive?)
1485this option is handy for working with several archives at once.
1486
1487For example, say you have the following source tarballs on a Unix machine<br>
1488
1489    perl-5.8.5.tar.gz
1490    Python-2.4.2.tar.gz
1491
1492and you want to count all the code within them.  The command would be
1493<pre>
1494cloc --extract-with='gzip -dc &gt;FILE&lt; | tar xf -' perl-5.8.5.tar.gz Python-2.4.2.tar.gz
1495</pre>
1496If that Unix machine has GNU tar (which can uncompress and extract in
1497one step) the command can be shortened to
1498<pre>
1499cloc --extract-with='tar zxf &gt;FILE&lt;' perl-5.8.5.tar.gz Python-2.4.2.tar.gz
1500</pre>
1501On a Windows computer with WinZip installed in
1502`c:\Program Files\WinZip` the command would look like
1503<pre>
1504cloc.exe --extract-with="\"c:\Program Files\WinZip\WinZip32.exe\" -e -o &gt;FILE&lt; ." perl-5.8.5.tar.gz Python-2.4.2.tar.gz
1505</pre>
1506Java `.ear` files are Zip files that contain additional Zip
1507files.  cloc can handle nested compressed archives without
1508difficulty--provided all such files are compressed and archived in the
1509same way.  Examples of counting a
1510Java `.ear` file in Unix and Windows:
1511<pre>
1512<i>Unix&gt;</i> cloc --extract-with="unzip -d . &gt;FILE&lt; " Project.ear
1513<i>DOS&gt;</i> cloc.exe --extract-with="\"c:\Program Files\WinZip\WinZip32.exe\" -e -o &gt;FILE&lt; ." Project.ear
1514</pre>
1515
1516[](1}}})
1517<a name="diff"></a> []({{{1)
1518##  [Differences &#9650;](#___top "click to go to top of document")
1519The `--diff` switch allows one to measure the relative change in
1520source code and comments between two versions of a file, directory,
1521or archive.  Differences reveal much more than absolute code
1522counts of two file versions.  For example, say a source file
1523has 100 lines and its developer delivers a newer version with
1524102 lines.  Did the developer add two comment lines,
1525or delete seventeen source
1526lines and add fourteen source lines and five comment lines, or did
1527the developer
1528do a complete rewrite, discarding all 100 original lines and
1529adding 102 lines of all new source?  The diff option tells how
1530many lines of source were added, removed, modified or stayed
1531the same, and how many lines of comments were added, removed,
1532modified or stayed the same.
1533
1534Differences in blank lines are handled much more coarsely
1535because these are stripped by cloc early on.  Unless a
1536file pair is identical, cloc will report only differences
1537in absolute counts of blank lines.  In other words, one
1538can expect to see only entries for 'added' if the second
1539file has more blanks than the first, and 'removed' if the
1540situation is reversed.  The entry for 'same' will be non-zero
1541only when the two files are identical.
1542
1543In addition to file pairs, one can give cloc pairs of
1544directories, or pairs of file archives, or a file archive
1545and a directory.  cloc will try to align
1546file pairs within the directories or archives and compare diffs
1547for each pair.  For example, to see what changed between
1548GCC 4.4.0 and 4.5.0 one could do
1549<pre>
1550cloc --diff gcc-4.4.0.tar.bz2  gcc-4.5.0.tar.bz2
1551</pre>
1552
1553Be prepared to wait a while for the results though; the `--diff`
1554option runs much more slowly than an absolute code count.
1555
1556To see how cloc aligns files between the two archives, use the
1557`--diff-alignment` option
1558<pre>
1559cloc --diff-alignment=align.txt gcc-4.4.0.tar.bz2  gcc-4.5.0.tar.bz2
1560</pre>
1561to produce the file `align.txt` which shows the file pairs as well
1562as files added and deleted.  The symbols `==` and `!=` before each
1563file pair indicate if the files are identical (`==`)
1564or if they have different content (`!=`).
1565
1566Here's sample output showing the difference between the Python 2.6.6 and 2.7
1567releases:
1568<pre><i>prompt&gt;</i> cloc --diff Python-2.7.9.tgz Python-2.7.10.tar.xz
1569    4315 text files.
1570    4313 text files.s
1571    2173 files ignored.
1572
15734 errors:
1574Diff error, exceeded timeout:  /tmp/8ToGAnB9Y1/Python-2.7.9/Mac/Modules/qt/_Qtmodule.c
1575Diff error, exceeded timeout:  /tmp/M6ldvsGaoq/Python-2.7.10/Mac/Modules/qt/_Qtmodule.c
1576Diff error (quoted comments?):  /tmp/8ToGAnB9Y1/Python-2.7.9/Mac/Modules/qd/qdsupport.py
1577Diff error (quoted comments?):  /tmp/M6ldvsGaoq/Python-2.7.10/Mac/Modules/qd/qdsupport.py
1578
1579https://github.com/AlDanial/cloc v 1.65  T=298.59 s (0.0 files/s, 0.0 lines/s)
1580-----------------------------------------------------------------------------
1581Language                   files          blank        comment           code
1582-----------------------------------------------------------------------------
1583Visual Basic
1584 same                          2              0              1             12
1585 modified                      0              0              0              0
1586 added                         0              0              0              0
1587 removed                       0              0              0              0
1588make
1589 same                         11              0            340           2952
1590 modified                      1              0              0              1
1591 added                         0              0              0              0
1592 removed                       0              0              0              0
1593diff
1594 same                          1              0             87            105
1595 modified                      0              0              0              0
1596 added                         0              0              0              0
1597 removed                       0              0              0              0
1598CSS
1599 same                          0              0             19            327
1600 modified                      1              0              0              1
1601 added                         0              0              0              0
1602 removed                       0              0              0              0
1603Objective-C
1604 same                          7              0             61            635
1605 modified                      0              0              0              0
1606 added                         0              0              0              0
1607 removed                       0              0              0              0
1608NAnt script
1609 same                          2              0              0             30
1610 modified                      0              0              0              0
1611 added                         0              0              0              0
1612 removed                       0              0              0              0
1613XML
1614 same                          3              0              2             72
1615 modified                      1              0              0              1
1616 added                         0              0              0              1
1617 removed                       0              1              0              0
1618Windows Resource File
1619 same                          3              0             56            206
1620 modified                      1              0              0              1
1621 added                         0              0              0              0
1622 removed                       0              0              0              0
1623Expect
1624 same                          6              0            161            565
1625 modified                      0              0              0              0
1626 added                         0              0              0              0
1627 removed                       0              0              0              0
1628HTML
1629 same                         14              0             11           2344
1630 modified                      0              0              0              0
1631 added                         0              0              0              0
1632 removed                       0              0              0              0
1633vim script
1634 same                          1              0              7            106
1635 modified                      0              0              0              0
1636 added                         0              0              0              0
1637 removed                       0              0              0              0
1638C++
1639 same                          2              0             18            128
1640 modified                      0              0              0              0
1641 added                         0              0              0              0
1642 removed                       0              0              0              0
1643Windows Module Definition
1644 same                          7              0            187           2080
1645 modified                      2              0              0              0
1646 added                         0              0              0              1
1647 removed                       0              1              0              2
1648Prolog
1649 same                          1              0              0             24
1650 modified                      0              0              0              0
1651 added                         0              0              0              0
1652 removed                       0              0              0              0
1653Javascript
1654 same                          3              0             49            229
1655 modified                      0              0              0              0
1656 added                         0              0              0              0
1657 removed                       0              0              0              0
1658Assembly
1659 same                         51              0           6794          12298
1660 modified                      0              0              0              0
1661 added                         0              0              0              0
1662 removed                       0              0              0              0
1663Bourne Shell
1664 same                         41              0           7698          45024
1665 modified                      1              0              0              3
1666 added                         0             13              2             64
1667 removed                       0              0              0              0
1668DOS Batch
1669 same                         29              0            107            494
1670 modified                      1              0              0              9
1671 added                         0              1              0              3
1672 removed                       0              0              0              0
1673MSBuild script
1674 same                         77              0              3          38910
1675 modified                      0              0              0              0
1676 added                         0              0              0              0
1677 removed                       0              0              0              0
1678Python
1679 same                       1947              0         109012         430335
1680 modified                    192              0             94            950
1681 added                         2            323            283           2532
1682 removed                       2             55             58            646
1683m4
1684 same                         18              0            191          15352
1685 modified                      1              0              0              2
1686 added                         1             31              0            205
1687 removed                       0              0              0              0
1688C
1689 same                        505              0          37439         347837
1690 modified                     45              0             13            218
1691 added                         0             90             33            795
1692 removed                       0              9              2            148
1693C/C++ Header
1694 same                        255              0          10361          66635
1695 modified                      5              0              5              7
1696 added                         0              1              3            300
1697 removed                       0              0              0              0
1698---------------------------------------------------------------------
1699SUM:
1700 same                       2986              0         172604         966700
1701 modified                    251              0            112           1193
1702 added                         3            459            321           3901
1703 removed                       2             66             60            796
1704---------------------------------------------------------------------
1705</pre>
1706A pair of errors occurred.
1707The first pair was caused by timing out when computing diffs of the file
1708`Python-X/Mac/Modules/qt/_Qtmodule.c` in each Python version.
1709This file has > 26,000 lines of C code and takes more than
171010 seconds--the default maximum duration for diff'ing a
1711single file--on my slow computer.  (Note:  this refers to
1712performing differences with
1713the `sdiff()` function in the Perl `Algorithm::Diff` module,
1714not the command line `diff` utility.)  This error can be
1715overcome by raising the time to, say, 20 seconds
1716with `--diff-timeout 20`.
1717
1718The second error is more problematic.  The files
1719`Python-X/Mac/Modules/qd/qdsupport.py`
1720include Python docstring (text between pairs of triple quotes)
1721containing C comments.  cloc treats docstrings as comments and handles them
1722by first converting them to C comments, then using the C comment removing
1723regular expression.  Nested C comments yield erroneous results however.
1724
1725[](1}}})
1726<a name="custom_lang"></a> []({{{1)
1727##  [Create Custom Language Definitions &#9650;](#___top "click to go to top of document")
1728cloc can write its language comment definitions to a file or can read
1729comment definitions from a file, overriding the built-in definitions.
1730This can be useful when you want to use cloc to count lines of a
1731language not yet included, to change association of file extensions
1732to languages, or to modify the way existing languages are counted.
1733
1734The easiest way to create a custom language definition file is to
1735make cloc write its definitions to a file, then modify that file:
1736<pre><i>Unix&gt;</i> cloc --write-lang-def=my_definitions.txt
1737</pre>
1738creates the file `my_definitions.txt` which can be modified
1739then read back in with either the `--read-lang-def` or
1740`--force-lang-def` option.  The difference between the options is
1741former merges language definitions from the given file in with
1742cloc's internal definitions with cloc's taking precedence
1743if there are overlaps.  The `--force-lang-def` option, on the
1744other hand, replaces cloc's definitions completely.
1745This option has a disadvantage in preventing cloc from counting
1746<a class="u" href="#extcollision" name="extcollision">
1747languages whose extensions map to multiple languages
1748</a> as these languages require additional logic that is not easily
1749expressed in a definitions file.
1750<pre><i>Unix&gt;</i> cloc --read-lang-def=my_definitions.txt  <i>file1 file2 dir1 ...</i>
1751</pre>
1752
1753Each language entry has four parts:
1754* The language name starting in column 1.
1755* One or more comment *filters* starting in column 5.
1756* One or more filename extensions starting in column 5.
1757* A 3rd generation scale factor starting in column 5.
1758  This entry must be provided
1759  but its value is not important
1760  unless you want to compare your language to a hypothetical
1761  third generation programming language.
1762
1763A filter defines a method to remove comment text from the source file.
1764For example the entry for C++ looks like this
1765<pre>C++
1766    filter call_regexp_common C++
1767    filter remove_inline //.*$
1768    extension C
1769    extension c++
1770    extension cc
1771    extension cpp
1772    extension cxx
1773    extension pcc
1774    3rd_gen_scale 1.51
1775    end_of_line_continuation \\$
1776</pre>
1777C++ has two filters:  first, remove lines matching
1778Regexp::Common's C++ comment regex.
1779The second filter using remove_inline is currently
1780unused.  Its intent is to identify lines with both
1781code and comments and it may be implemented in the future.
1782
1783A more complete discussion of the different filter options may appear
1784here in the future.  The output of cloc's
1785`--write-lang-def` option should provide enough examples
1786for motivated individuals to modify or extend cloc's language definitions.
1787
1788[](1}}})
1789<a name="combine_reports"></a> []({{{1)
1790##  [Combine Reports &#9650;](#___top "click to go to top of document")
1791
1792If you manage multiple software projects you might be interested in
1793seeing line counts by project, not just by language.
1794Say you manage three software projects called MariaDB, PostgreSQL, and SQLite.
1795The teams responsible for each of these projects run cloc on their
1796source code and provide you with the output.
1797For example MariaDB team does
1798
1799<pre>cloc --out mariadb-10.1.txt mariadb-server-10.1.zip</pre>
1800
1801and provides you with the file `mariadb-10.1.txt`.
1802The contents of the three files you get are
1803
1804<pre>
1805<i>Unix&gt;</i> cat mariadb-10.1.txt
1806https://github.com/AlDanial/cloc v 1.65  T=45.36 s (110.5 files/s, 66411.4 lines/s)
1807-----------------------------------------------------------------------------------
1808Language                         files          blank        comment           code
1809-----------------------------------------------------------------------------------
1810C++                               1613         225338         290077         983026
1811C                                  853          62442          73017         715018
1812C/C++ Header                      1327          48300         114577         209394
1813Bourne Shell                       256          10224          10810          61943
1814Perl                               147          10342           8305          35562
1815Pascal                             107           4907           5237          32541
1816HTML                                56            195              6          16489
1817Javascript                           5           3309           3019          15540
1818m4                                  30           1599            359          14215
1819CMake                              190           1919           4097          12206
1820XML                                 35            648             56           5210
1821Ruby                                59            619            184           4998
1822Puppet                              10              0              1           3848
1823make                               134            724            360           3631
1824SQL                                 23            306            377           3405
1825Python                              34            371            122           2545
1826Bourne Again Shell                  27            299            380           1604
1827Windows Module Definition           37             27             13           1211
1828lex                                  4            394            166            991
1829yacc                                 2            152             64            810
1830DOS Batch                           19             89             82            700
1831Prolog                               1              9             40            448
1832RobotFramework                       1              0              0            441
1833CSS                                  2             33            155            393
1834JSON                                 5              0              0            359
1835dtrace                               9             59            179            306
1836Windows Resource File               10             61             89            250
1837Assembly                             2             70            284            237
1838WiX source                           1             18             10            155
1839Visual Basic                         6              0              0             88
1840YAML                                 2              4              4             65
1841PHP                                  1             11              2             24
1842SKILL                                1              8             15             16
1843sed                                  2              0              0             16
1844Windows Message File                 1              2              8              6
1845diff                                 1              1              4              4
1846D                                    1              4             11              4
1847-----------------------------------------------------------------------------------
1848SUM:                              5014         372484         512110        2127699
1849-----------------------------------------------------------------------------------
1850
1851<i>Unix&gt;</i> cat sqlite-3081101.txt
1852https://github.com/AlDanial/cloc v 1.65  T=1.22 s (3.3 files/s, 143783.6 lines/s)
1853-------------------------------------------------------------------------------
1854Language                     files          blank        comment           code
1855-------------------------------------------------------------------------------
1856C                                2          11059          53924         101454
1857C/C++ Header                     2            211           6630           1546
1858-------------------------------------------------------------------------------
1859SUM:                             4          11270          60554         103000
1860-------------------------------------------------------------------------------
1861
1862<i>Unix&gt;</i> cat postgresql-9.4.4.txt
1863https://github.com/AlDanial/cloc v 1.65  T=22.46 s (172.0 files/s, 96721.6 lines/s)
1864-----------------------------------------------------------------------------------
1865Language                         files          blank        comment           code
1866-----------------------------------------------------------------------------------
1867HTML                              1254           3725              0         785991
1868C                                 1139         139289         244045         736519
1869C/C++ Header                       667          12277          32488          57014
1870SQL                                410          13400           8745          51926
1871yacc                                 8           3163           2669          28491
1872Bourne Shell                        41           2647           2440          17170
1873Perl                                81           1702           1308           9456
1874lex                                  9            792           1631           4285
1875make                               205           1525           1554           4114
1876m4                                  12            218             25           1642
1877Windows Module Definition           13              4             17           1152
1878XSLT                                 5             76             55            294
1879DOS Batch                            7             29             30             92
1880CSS                                  1             20              7             69
1881Assembly                             3             17             38             69
1882D                                    1             14             14             66
1883Windows Resource File                3              4              0             62
1884Lisp                                 1              1              1             16
1885sed                                  1              1              7             15
1886Python                               1              5              0             13
1887Bourne Again Shell                   1              8              6             10
1888Windows Message File                 1              0              0              5
1889-----------------------------------------------------------------------------------
1890SUM:                              3864         178917         295080        1698471
1891-----------------------------------------------------------------------------------
1892</pre>
1893
1894While these three files are interesting, you also want to see
1895the combined counts from all projects.
1896That can be done with cloc's `--sum_reports`
1897option:
1898
1899<pre>
1900<i>Unix&gt;</i> cloc --sum-reports --out=databases mariadb-10.1.txt  sqlite-3081101.txt  postgresql-9.4.4.txt
1901Wrote databases.lang
1902Wrote databases.file
1903</pre>
1904
1905The report combination produces two output files, one for sums by
1906programming language (`databases.lang`) and one by project
1907(`databases.file`).
1908Their contents are
1909<pre><i>Unix&gt;</i> cat databases.lang
1910https://github.com/AlDanial/cloc v 1.65
1911--------------------------------------------------------------------------------
1912Language                      files          blank        comment           code
1913--------------------------------------------------------------------------------
1914C                              1994         212790         370986        1552991
1915C++                            1613         225338         290077         983026
1916HTML                           1310           3920              6         802480
1917C/C++ Header                   1996          60788         153695         267954
1918Bourne Shell                    297          12871          13250          79113
1919SQL                             433          13706           9122          55331
1920Perl                            228          12044           9613          45018
1921Pascal                          107           4907           5237          32541
1922yacc                             10           3315           2733          29301
1923m4                               42           1817            384          15857
1924Javascript                        5           3309           3019          15540
1925CMake                           190           1919           4097          12206
1926make                            339           2249           1914           7745
1927lex                              13           1186           1797           5276
1928XML                              35            648             56           5210
1929Ruby                             59            619            184           4998
1930Puppet                           10              0              1           3848
1931Python                           35            376            122           2558
1932Windows Module Definition        50             31             30           2363
1933Bourne Again Shell               28            307            386           1614
1934DOS Batch                        26            118            112            792
1935CSS                               3             53            162            462
1936Prolog                            1              9             40            448
1937RobotFramework                    1              0              0            441
1938JSON                              5              0              0            359
1939Windows Resource File            13             65             89            312
1940Assembly                          5             87            322            306
1941dtrace                            9             59            179            306
1942XSLT                              5             76             55            294
1943WiX source                        1             18             10            155
1944Visual Basic                      6              0              0             88
1945D                                 2             18             25             70
1946YAML                              2              4              4             65
1947sed                               3              1              7             31
1948PHP                               1             11              2             24
1949SKILL                             1              8             15             16
1950Lisp                              1              1              1             16
1951Windows Message File              2              2              8             11
1952diff                              1              1              4              4
1953--------------------------------------------------------------------------------
1954SUM:                           8882         562671         867744        3929170
1955--------------------------------------------------------------------------------
1956
1957<i>Unix&gt;</i> cat databases.file
1958----------------------------------------------------------------------------------
1959File                            files          blank        comment           code
1960----------------------------------------------------------------------------------
1961mariadb-10.1.txt                 5014         372484         512110        2127699
1962postgresql-9.4.4.txt             3864         178917         295080        1698471
1963sqlite-3081101.txt                  4          11270          60554         103000
1964----------------------------------------------------------------------------------
1965SUM:                             8882         562671         867744        3929170
1966----------------------------------------------------------------------------------
1967</pre>
1968
1969Report files themselves can be summed together.  Say you also manage
1970development of Perl and Python and you want to keep track
1971of those line counts separately from your database projects.  First
1972create reports for Perl and Python separately:
1973
1974<pre>
1975cloc --out perl-5.22.0.txt   perl-5.22.0.tar.gz
1976cloc --out python-2.7.10.txt Python-2.7.10.tar.xz
1977</pre>
1978
1979then sum these together with
1980
1981<pre>
1982<i>Unix&gt;</i> cloc --sum-reports --out script_lang perl-5.22.0.txt python-2.7.10.txt
1983Wrote script_lang.lang
1984Wrote script_lang.file
1985
1986<i>Unix&gt;</i> cat script_lang.lang
1987https://github.com/AlDanial/cloc v 1.65
1988-------------------------------------------------------------------------------
1989Language                     files          blank        comment           code
1990-------------------------------------------------------------------------------
1991Perl                          2892         136396         184362         536445
1992C                              680          75566          71211         531203
1993Python                        2141          89642         109524         434015
1994C/C++ Header                   408          16433          26938         214800
1995Bourne Shell                   154          11088          14496          87759
1996MSBuild script                  77              0              3          38910
1997m4                              20           1604            191          15559
1998Assembly                        51           3775           6794          12298
1999Pascal                           8            458           1603           8592
2000make                            16            897            828           4939
2001XML                             37            198              2           2484
2002HTML                            14            393             11           2344
2003C++                             12            338            295           2161
2004Windows Module Definition        9            171            187           2081
2005YAML                            49             20             15           2078
2006Prolog                          12            438              2           1146
2007JSON                            14              1              0           1037
2008yacc                             1             85             76            998
2009DOS Batch                       44            199            148            895
2010Objective-C                      7             98             61            635
2011Expect                           6            104            161            565
2012Windows Message File             1            102             11            489
2013CSS                              1             98             19            328
2014Windows Resource File            7             55             56            292
2015Javascript                       3             31             49            229
2016vim script                       1             36              7            106
2017diff                             1             17             87            105
2018NAnt script                      2              1              0             30
2019IDL                              1              0              0             24
2020Visual Basic                     2              1              1             12
2021D                                1              5              7              8
2022Lisp                             2              0              3              4
2023-------------------------------------------------------------------------------
2024SUM:                          6674         338250         417148        1902571
2025-------------------------------------------------------------------------------
2026
2027<i>Unix&gt;</i> cat script_lang.file
2028-------------------------------------------------------------------------------
2029File                         files          blank        comment           code
2030-------------------------------------------------------------------------------
2031python-2.7.10.txt             3240         161276         173214         998697
2032perl-5.22.0.txt               3434         176974         243934         903874
2033-------------------------------------------------------------------------------
2034SUM:                          6674         338250         417148        1902571
2035-------------------------------------------------------------------------------
2036</pre>
2037
2038Finally, combine the combination files:
2039
2040<pre>
2041<i>Unix&gt;</i> cloc --sum-reports --report_file=everything databases.lang script_lang.lang
2042Wrote everything.lang
2043Wrote everything.file
2044
2045<i>Unix&gt;</i> cat everything.lang
2046https://github.com/AlDanial/cloc v 1.65
2047---------------------------------------------------------------------------------
2048Language                       files          blank        comment           code
2049---------------------------------------------------------------------------------
2050C                               2674         288356         442197        2084194
2051C++                             1625         225676         290372         985187
2052HTML                            1324           4313             17         804824
2053Perl                            3120         148440         193975         581463
2054C/C++ Header                    2404          77221         180633         482754
2055Python                          2176          90018         109646         436573
2056Bourne Shell                     451          23959          27746         166872
2057SQL                              433          13706           9122          55331
2058Pascal                           115           5365           6840          41133
2059MSBuild script                    77              0              3          38910
2060m4                                62           3421            575          31416
2061yacc                              11           3400           2809          30299
2062Javascript                         8           3340           3068          15769
2063make                             355           3146           2742          12684
2064Assembly                          56           3862           7116          12604
2065CMake                            190           1919           4097          12206
2066XML                               72            846             58           7694
2067lex                               13           1186           1797           5276
2068Ruby                              59            619            184           4998
2069Windows Module Definition         59            202            217           4444
2070Puppet                            10              0              1           3848
2071YAML                              51             24             19           2143
2072DOS Batch                         70            317            260           1687
2073Bourne Again Shell                28            307            386           1614
2074Prolog                            13            447             42           1594
2075JSON                              19              1              0           1396
2076CSS                                4            151            181            790
2077Objective-C                        7             98             61            635
2078Windows Resource File             20            120            145            604
2079Expect                             6            104            161            565
2080Windows Message File               3            104             19            500
2081RobotFramework                     1              0              0            441
2082dtrace                             9             59            179            306
2083XSLT                               5             76             55            294
2084WiX source                         1             18             10            155
2085diff                               2             18             91            109
2086vim script                         1             36              7            106
2087Visual Basic                       8              1              1            100
2088D                                  3             23             32             78
2089sed                                3              1              7             31
2090NAnt script                        2              1              0             30
2091IDL                                1              0              0             24
2092PHP                                1             11              2             24
2093Lisp                               3              1              4             20
2094SKILL                              1              8             15             16
2095---------------------------------------------------------------------------------
2096SUM:                           15556         900921        1284892        5831741
2097---------------------------------------------------------------------------------
2098
2099<i>Unix&gt;</i> cat everything.file
2100-------------------------------------------------------------------------------
2101File                         files          blank        comment           code
2102-------------------------------------------------------------------------------
2103databases.lang                8882         562671         867744        3929170
2104script_lang.lang              6674         338250         417148        1902571
2105-------------------------------------------------------------------------------
2106SUM:                         15556         900921        1284892        5831741
2107-------------------------------------------------------------------------------
2108</pre>
2109
2110One limitation of the `--sum-reports` feature is that the individual counts must
2111be saved in the plain text format.  Counts saved as
2112XML, JSON, YAML, or SQL will produce errors if used in a summation.
2113
2114[](1}}})
2115<a name="sql"></a> []({{{1)
2116##  [SQL &#9650;](#___top "click to go to top of document")
2117Cloc can write results in the form of SQL table create and insert
2118statements for use
2119with relational database programs such as SQLite, MySQL,
2120PostgreSQL, Oracle, or Microsoft SQL.
2121Once the code count information is in a database,
2122the information can be interrogated and displayed in interesting ways.
2123
2124A database created from cloc SQL output has two tables,
2125**metadata** and **t**:
2126
2127Table **metadata**:
2128
2129|Field     | Type |
2130|----------|------|
2131|timestamp | text |
2132|project   | text |
2133|elapsed_s | text |
2134
2135Table **t**:
2136
2137|Field       | Type   |
2138|------------|--------|
2139| project    |text    |
2140| language   |text    |
2141| file       |text    |
2142| nBlank     |integer |
2143| nComment   |integer |
2144| nCode      |integer |
2145| nScaled    |real    |
2146
2147The **metadata** table contains information about when the cloc run
2148was made.  The `--sql-append` switch allows one to combine
2149many runs in a single database; each run adds a
2150row to the metadata table.
2151The code count information resides in table **t**.
2152
2153Let's repeat the code count examples of Perl, Python, SQLite, MySQL and
2154PostgreSQL tarballs shown in the
2155[Combine Reports](#combine_reports)
2156example above, this time
2157using the SQL output options and the
2158[SQLite](http://www.sqlite.org/)
2159database engine.
2160
2161The `--sql` switch tells cloc to generate output in the form
2162of SQL table `create` and `insert` commands.  The switch takes
2163an argument of a file name to write these SQL statements into, or,
2164if the argument is 1 (numeric one), streams output to STDOUT.
2165Since the SQLite command line program, `sqlite3`, can read
2166commands from STDIN, we can dispense with storing SQL statements to
2167a file and use `--sql 1` to pipe data directly into the
2168SQLite executable:
2169
2170<pre>
2171cloc --sql 1 --sql-project mariadb mariadb-server-10.1.zip | sqlite3 code.db
2172</pre>
2173
2174The `--sql-project mariadb` part is optional; there's no need
2175to specify a project name when working with just one code base.  However,
2176since we'll be adding code counts from four other tarballs, we'll only
2177be able to identify data by input source if we supply a
2178project name for each run.
2179
2180Now that we have a database we will need to pass in the `--sql-append`
2181switch to tell cloc not to wipe out this database but instead add more data:
2182
2183<pre>
2184cloc --sql 1 --sql-project postgresql --sql-append postgresql-9.4.4.tar.bz2        | sqlite3 code.db
2185cloc --sql 1 --sql-project sqlite     --sql-append sqlite-amalgamation-3081101.zip | sqlite3 code.db
2186cloc --sql 1 --sql-project python     --sql-append Python-2.7.10.tar.xz            | sqlite3 code.db
2187cloc --sql 1 --sql-project perl       --sql-append perl-5.22.0.tar.gz              | sqlite3 code.db
2188</pre>
2189
2190Now the fun begins--we have a database, `code.db`, with lots of
2191information about the five projects and can query it
2192for all manner of interesting facts.
2193
2194**Which is the longest file over all projects?**
2195
2196<pre>
2197prompt> sqlite3 code.db 'select project,file,nBlank+nComment+nCode as nL from t
2198                                 where nL = (select max(nBlank+nComment+nCode) from t)'
2199
2200sqlite|sqlite-amalgamation-3081101/sqlite3.c|161623
2201</pre>
2202
2203`sqlite3`'s default output format leaves a bit to be desired.
2204We can add an option to the program's rc file,
2205`~/.sqliterc`, to show column headers:
2206<pre>
2207  .header on
2208</pre>
2209One might be tempted to also include
2210<pre>
2211  .mode column
2212</pre>
2213in `~/.sqliterc` but this causes problems when the output has more than
2214one row since the widths of entries in the first row govern the maximum
2215width for all subsequent rows. Often this leads to truncated output--not
2216at all desirable. One option is to write a custom SQLite output
2217formatter such as `sqlite_formatter`, included with cloc.
2218
2219To use it, simply pass `sqlite3`'s STDOUT into `sqlite_formatter`
2220via a pipe:
2221
2222<pre>
2223prompt> sqlite3 code.db 'select project,file,nBlank+nComment+nCode as nL from t
2224                         where nL = (select max(nBlank+nComment+nCode) from t)' | ./sqlite_formatter
2225  <font color="darkgreen">
2226  -- Loading resources from ~/.sqliterc
2227  Project File                                  nL
2228  _______ _____________________________________ ______
2229  sqlite  sqlite-amalgamation-3081101/sqlite3.c 161623
2230  </font>
2231</pre>
2232
2233If the "Project File" line doesn't appear, add `.header on` to your
2234`~/.sqliterc` file as explained above.
2235
2236
2237**What is the longest file over all projects?**
2238
2239<pre>
2240prompt> sqlite3 code.db 'select project,file,nBlank+nComment+nCode as nL from t
2241                         where nL = (select max(nBlank+nComment+nCode) from t)' | sqlite_formatter
2242
2243Project File                                  nL
2244_______ _____________________________________ ______
2245sqlite  sqlite-amalgamation-3081101/sqlite3.c 161623
2246</pre>
2247
2248**What is the longest file in each project?**
2249
2250<pre>
2251prompt> sqlite3 code.db 'select project,file,max(nBlank+nComment+nCode) as nL from t
2252                          group by project order by nL;' | sqlite_formatter
2253
2254Project    File                                                             nL
2255__________ ________________________________________________________________ ______
2256python     Python-2.7.10/Mac/Modules/qt/_Qtmodule.c                          28091
2257postgresql postgresql-9.4.4/src/interfaces/ecpg/preproc/preproc.c            54623
2258mariadb    server-10.1/storage/mroonga/vendor/groonga/lib/nfkc.c             80246
2259perl       perl-5.22.0/cpan/Locale-Codes/lib/Locale/Codes/Language_Codes.pm 100747
2260sqlite     sqlite-amalgamation-3081101/sqlite3.c                            161623
2261</pre>
2262
2263**Which files in each project have the most code lines?**
2264
2265<pre>
2266prompt> sqlite3 code.db 'select project,file,max(nCode) as nL from t
2267                         group by project order by nL desc;' | sqlite_formatter
2268
2269Project    File                                                             nL
2270__________ ________________________________________________________________ ______
2271perl       perl-5.22.0/cpan/Locale-Codes/lib/Locale/Codes/Language_Codes.pm 100735
2272sqlite     sqlite-amalgamation-3081101/sqlite3.c                             97469
2273mariadb    server-10.1/storage/mroonga/vendor/groonga/lib/nfkc.c             80221
2274postgresql postgresql-9.4.4/src/interfaces/ecpg/preproc/preproc.c            45297
2275python     Python-2.7.10/Mac/Modules/qt/_Qtmodule.c                          26705
2276</pre>
2277
2278**Which C source files with more than 300 lines have a comment ratio below 1%?**
2279
2280<pre>
2281prompt> sqlite3 code.db 'select project, file, nCode, nComment,
2282                         (100.0*nComment)/(nComment+nCode) as comment_ratio from t
2283                         where language="C" and nCode > 300 and
2284                         comment_ratio < 1 order by comment_ratio;' | sqlite_formatter
2285
2286Project    File                                                                                            nCode nComment comment_ratio
2287__________ _______________________________________________________________________________________________ _____ ________ __________________
2288mariadb    server-10.1/storage/mroonga/vendor/groonga/lib/nfkc.c                                           80221       14 0.0174487443135789
2289python     Python-2.7.10/Python/graminit.c                                                                  2175        1 0.0459558823529412
2290postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_UTF_8_turkish.c                            2095        1 0.0477099236641221
2291postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_UTF_8_french.c                             1211        1 0.0825082508250825
2292postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_ISO_8859_1_french.c                        1201        1 0.0831946755407654
2293postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_UTF_8_hungarian.c                          1182        1 0.084530853761623
2294postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_ISO_8859_1_hungarian.c                     1178        1 0.0848176420695505
2295mariadb    server-10.1/strings/ctype-eucjpms.c                                                             67466       60 0.0888546633889169
2296postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_UTF_8_english.c                            1072        1 0.0931966449207828
2297postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_ISO_8859_1_english.c                       1064        1 0.0938967136150235
2298postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_UTF_8_spanish.c                            1053        1 0.094876660341556
2299postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_ISO_8859_1_spanish.c                       1049        1 0.0952380952380952
2300postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_UTF_8_italian.c                            1031        1 0.0968992248062016
2301postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_ISO_8859_1_italian.c                       1023        1 0.09765625
2302postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_UTF_8_portuguese.c                          981        1 0.10183299389002
2303postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_ISO_8859_1_portuguese.c                     975        1 0.102459016393443
2304postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_UTF_8_romanian.c                            967        1 0.103305785123967
2305postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_ISO_8859_2_romanian.c                       961        1 0.103950103950104
2306mariadb    server-10.1/strings/ctype-ujis.c                                                                67177       79 0.117461639110265
2307postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_UTF_8_finnish.c                             720        1 0.13869625520111
2308postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_UTF_8_porter.c                              717        1 0.139275766016713
2309postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_ISO_8859_1_finnish.c                        714        1 0.13986013986014
2310postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_ISO_8859_1_porter.c                         711        1 0.140449438202247
2311postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_KOI8_R_russian.c                            660        1 0.151285930408472
2312postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_UTF_8_russian.c                             654        1 0.152671755725191
2313python     Python-2.7.10/Mac/Modules/qt/_Qtmodule.c                                                        26705       42 0.157026956294164
2314python     Python-2.7.10/Mac/Modules/icn/_Icnmodule.c                                                       1521        3 0.196850393700787
2315mariadb    server-10.1/strings/ctype-extra.c                                                                8282       18 0.216867469879518
2316postgresql postgresql-9.4.4/src/bin/psql/sql_help.c                                                         3576        8 0.223214285714286
2317mariadb    server-10.1/strings/ctype-sjis.c                                                                34006       86 0.252258594391646
2318python     Python-2.7.10/Python/Python-ast.c                                                                6554       17 0.258712524729874
2319mariadb    server-10.1/strings/ctype-cp932.c                                                               34609       92 0.265122042592432
2320perl       perl-5.22.0/keywords.c                                                                           2815        8 0.283386468296139
2321python     Python-2.7.10/Mac/Modules/menu/_Menumodule.c                                                     3263       10 0.305530094714329
2322postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_UTF_8_dutch.c                               596        2 0.334448160535117
2323postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_ISO_8859_1_dutch.c                          586        2 0.340136054421769
2324mariadb    server-10.1/strings/ctype-gbk.c                                                                 10684       38 0.354411490393583
2325python     Python-2.7.10/Mac/Modules/qd/_Qdmodule.c                                                         6694       24 0.357249181303959
2326python     Python-2.7.10/Mac/Modules/win/_Winmodule.c                                                       3056       11 0.358656667753505
2327postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_UTF_8_german.c                              476        2 0.418410041841004
2328postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_ISO_8859_1_german.c                         470        2 0.423728813559322
2329mariadb    server-10.1/strings/ctype-euc_kr.c                                                               9956       44 0.44
2330postgresql postgresql-9.4.4/src/backend/utils/fmgrtab.c                                                     4815       23 0.475403059115337
2331python     Python-2.7.10/Mac/Modules/ctl/_Ctlmodule.c                                                       5442       28 0.511882998171846
2332python     Python-2.7.10/Mac/Modules/ae/_AEmodule.c                                                         1347        7 0.51698670605613
2333python     Python-2.7.10/Mac/Modules/app/_Appmodule.c                                                       1712        9 0.52295177222545
2334mariadb    server-10.1/strings/ctype-gb2312.c                                                               6377       35 0.54585152838428
2335mariadb    server-10.1/storage/tokudb/ft-index/third_party/xz-4.999.9beta/src/liblzma/lzma/fastpos_table.c   516        3 0.578034682080925
2336python     Python-2.7.10/Mac/Modules/evt/_Evtmodule.c                                                        504        3 0.591715976331361
2337python     Python-2.7.10/Modules/expat/xmlrole.c                                                            1256        8 0.632911392405063
2338postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_UTF_8_danish.c                              312        2 0.636942675159236
2339postgresql postgresql-9.4.4/src/backend/snowball/libstemmer/stem_ISO_8859_1_danish.c                         310        2 0.641025641025641
2340python     Python-2.7.10/Mac/Modules/res/_Resmodule.c                                                       1621       12 0.734843845682792
2341python     Python-2.7.10/Mac/Modules/drag/_Dragmodule.c                                                     1046        8 0.759013282732448
2342python     Python-2.7.10/Mac/Modules/list/_Listmodule.c                                                     1021        8 0.777453838678329
2343python     Python-2.7.10/Mac/Modules/te/_TEmodule.c                                                         1198       10 0.827814569536424
2344python     Python-2.7.10/Mac/Modules/cg/_CGmodule.c                                                         1190       10 0.833333333333333
2345python     Python-2.7.10/Modules/clmodule.c                                                                 2379       23 0.957535387177352
2346python     Python-2.7.10/Mac/Modules/folder/_Foldermodule.c                                                  306        3 0.970873786407767
2347</pre>
2348
2349**What are the ten longest files (based on code lines) that have no comments at all?  Exclude header, .html, and YAML files.**
2350
2351<pre>
2352prompt> sqlite3 code.db 'select project, file, nCode from t
2353                         where nComment = 0 and
2354                         language not in ("C/C++ Header", "YAML", "HTML")
2355                         order by nCode desc limit 10;' | sqlite_formatter
2356
2357Project File                                                                 nCode
2358_______ ____________________________________________________________________ _____
2359perl    perl-5.22.0/cpan/Unicode-Collate/Collate/Locale/ja.pl                 1938
2360python  Python-2.7.10/PCbuild/pythoncore.vcproj                               1889
2361python  Python-2.7.10/PC/VS8.0/pythoncore.vcproj                              1889
2362mariadb server-10.1/mysql-test/extra/binlog_tests/mysqlbinlog_row_engine.inc  1862
2363perl    perl-5.22.0/cpan/Unicode-Collate/Collate/Locale/zh_strk.pl            1589
2364perl    perl-5.22.0/cpan/Unicode-Collate/Collate/Locale/zh_zhu.pl             1563
2365mariadb server-10.1/storage/mroonga/vendor/groonga/configure.ac               1526
2366perl    perl-5.22.0/cpan/Unicode-Collate/Collate/Locale/zh_pin.pl             1505
2367mariadb server-10.1/mysql-test/suite/funcs_1/storedproc/storedproc_02.inc     1465
2368python  Python-2.7.10/PC/VS8.0/_bsddb.vcproj                                  1463
2369</pre>
2370
2371**What are the most popular languages (in terms of lines
2372of code) in each project?**
2373
2374<pre>
2375prompt> sqlite3 code.db 'select project, language, sum(nCode) as SumCode from t
2376                         group by project,language
2377                         order by project,SumCode desc;' | sqlite_formatter
2378Project    Language                  SumCode
2379__________ _________________________ _______
2380mariadb    C++                        983026
2381mariadb    C                          715018
2382mariadb    C/C++ Header               209394
2383mariadb    Bourne Shell                61943
2384mariadb    Perl                        35562
2385mariadb    Pascal                      32541
2386mariadb    HTML                        16489
2387mariadb    Javascript                  15540
2388mariadb    m4                          14215
2389mariadb    CMake                       12206
2390mariadb    XML                          5210
2391mariadb    Ruby                         4998
2392mariadb    Puppet                       3848
2393mariadb    make                         3631
2394mariadb    SQL                          3405
2395mariadb    Python                       2545
2396mariadb    Bourne Again Shell           1604
2397mariadb    Windows Module Definition    1211
2398mariadb    lex                           991
2399mariadb    yacc                          810
2400mariadb    DOS Batch                     700
2401mariadb    Prolog                        448
2402mariadb    RobotFramework                441
2403mariadb    CSS                           393
2404mariadb    JSON                          359
2405mariadb    dtrace                        306
2406mariadb    Windows Resource File         250
2407mariadb    Assembly                      237
2408mariadb    WiX source                    155
2409mariadb    Visual Basic                   88
2410mariadb    YAML                           65
2411mariadb    PHP                            24
2412mariadb    SKILL                          16
2413mariadb    sed                            16
2414mariadb    Windows Message File            6
2415mariadb    D                               4
2416mariadb    diff                            4
2417perl       Perl                       536445
2418perl       C                          155648
2419perl       C/C++ Header               147858
2420perl       Bourne Shell                42668
2421perl       Pascal                       8592
2422perl       XML                          2410
2423perl       YAML                         2078
2424perl       C++                          2033
2425perl       make                         1986
2426perl       Prolog                       1146
2427perl       JSON                         1037
2428perl       yacc                          998
2429perl       Windows Message File          489
2430perl       DOS Batch                     389
2431perl       Windows Resource File          85
2432perl       D                               8
2433perl       Lisp                            4
2434postgresql HTML                       785991
2435postgresql C                          736519
2436postgresql C/C++ Header                57014
2437postgresql SQL                         51926
2438postgresql yacc                        28491
2439postgresql Bourne Shell                17170
2440postgresql Perl                         9456
2441postgresql lex                          4285
2442postgresql make                         4114
2443postgresql m4                           1642
2444postgresql Windows Module Definition    1152
2445postgresql XSLT                          294
2446postgresql DOS Batch                      92
2447postgresql Assembly                       69
2448postgresql CSS                            69
2449postgresql D                              66
2450postgresql Windows Resource File          62
2451postgresql Lisp                           16
2452postgresql sed                            15
2453postgresql Python                         13
2454postgresql Bourne Again Shell             10
2455postgresql Windows Message File            5
2456python     Python                     434015
2457python     C                          375555
2458python     C/C++ Header                66942
2459python     Bourne Shell                45091
2460python     MSBuild script              38910
2461python     m4                          15559
2462python     Assembly                    12298
2463python     make                         2953
2464python     HTML                         2344
2465python     Windows Module Definition    2081
2466python     Objective-C                   635
2467python     Expect                        565
2468python     DOS Batch                     506
2469python     CSS                           328
2470python     Javascript                    229
2471python     Windows Resource File         207
2472python     C++                           128
2473python     vim script                    106
2474python     diff                          105
2475python     XML                            74
2476python     NAnt script                    30
2477python     Prolog                         24
2478python     Visual Basic                   12
2479sqlite     C                          101454
2480sqlite     C/C++ Header                 1546
2481</pre>
2482
2483[](1}}})
2484<a name="custom_column_output"></a> []({{{1)
2485##  [Custom Column Output &#9650;](#___top "click to go to top of document")
2486Cloc's default output is a text table with five columns:
2487language, file count, number of blank lines, number of comment
2488lines and number of code lines.  The switches `--by-file`,
2489`--3`, and `--by-percent` generate additional information but
2490sometimes even those are insufficient.
2491
2492The `--sql` option described in the previous section offers the
2493ability to create custom output.  This section has a pair of examples
2494that show how to create custom columns.
2495The first example includes an extra column, **Total**, which is the
2496sum of the numbers of blank, comment, and code lines.
2497The second shows how to include the language name when running
2498with `--by-file`.
2499
2500**Example 1:  Add a "Totals" column.**
2501
2502The first step is to run cloc and save the output to a relational database,
2503SQLite in this case:
2504<pre>
2505cloc --sql 1 --sql-project x yaml-cpp-yaml-cpp-0.5.3.tar.gz | sqlite3 counts.db
2506</pre>
2507(the tar file comes from the
2508[YAML-C++](https://github.com/jbeder/yaml-cpp) project).
2509
2510Second, we craft an SQL query that returns the regular cloc output
2511plus an extra column for totals, then save the SQL statement to
2512a file, `query_with_totals.sql`:
2513<pre>
2514-- file query_with_totals.sql
2515select Language, count(File)   as files                       ,
2516                 sum(nBlank)   as blank                       ,
2517                 sum(nComment) as comment                     ,
2518                 sum(nCode)    as code                        ,
2519                 sum(nBlank)+sum(nComment)+sum(nCode) as Total
2520    from t group by Language order by code desc;
2521</pre>
2522
2523Third, we run this query through SQLite using the `counts.db` database.
2524We'll include the `-header` switch so that SQLite prints the
2525column names:
2526
2527<pre>
2528&gt; cat query_with_totals.sql | sqlite3 -header counts.db
2529Language|files|blank|comment|code|Total
2530C++|141|12786|17359|60378|90523
2531C/C++ Header|110|8566|17420|51502|77488
2532Bourne Shell|10|6351|6779|38264|51394
2533m4|11|2037|260|17980|20277
2534Python|30|1613|2486|4602|8701
2535MSBuild script|11|0|0|1711|1711
2536CMake|7|155|285|606|1046
2537make|5|127|173|464|764
2538Markdown|2|30|0|39|69
2539</pre>
2540
2541The extra column for **Total** is there but the format is unappealing.
2542Running the output through `sqlite_formatter` yields the desired result:
2543
2544<pre>
2545&gt; cat query_with_totals.sql | sqlite3 -header counts.db | sqlite_formatter
2546Language       files blank comment code  Total
2547______________ _____ _____ _______ _____ _____
2548C++              141 12786   17359 60378 90523
2549C/C++ Header     110  8566   17420 51502 77488
2550Bourne Shell      10  6351    6779 38264 51394
2551m4                11  2037     260 17980 20277
2552Python            30  1613    2486  4602  8701
2553MSBuild script    11     0       0  1711  1711
2554CMake              7   155     285   606  1046
2555make               5   127     173   464   764
2556Markdown           2    30       0    39    69
2557</pre>
2558
2559The next section,
2560[Wrapping cloc in other scripts](#wrapping-cloc-in-other-scripts-),
2561shows one way these commands can be combined
2562into a new utility program.
2563
2564**Example 2:  Include a column for "Language" when running with `--by-file`.**
2565
2566Output from `--by-file` omits each file's language to save screen real estate;
2567file paths for large projects can be long and including an extra 20 or so
2568characters for a Language column can be excessive.
2569
2570As an example, here are the first few lines of output using the same
2571code base as in Example 1:
2572
2573<pre>
2574&gt; cloc --by-file yaml-cpp-yaml-cpp-0.5.3.tar.gz
2575github.com/AlDanial/cloc v 1.81  T=1.14 s (287.9 files/s, 221854.9 lines/s)
2576--------------------------------------------------------------------------------------------------------------------------------------------
2577File                                                                                                     blank        comment           code
2578--------------------------------------------------------------------------------------------------------------------------------------------
2579yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/configure                                                        2580           2264          13691
2580yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/gtest/configure                                                  2541           2235          13446
2581yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/gtest/fused-src/gtest/gtest.h                                    1972           4681          13408
2582yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/fused-src/gmock/gmock.h                                          1585           3397           9216
2583yaml-cpp-yaml-cpp-0.5.3/test/integration/gen_emitter_test.cpp                                              999              0           8760
2584yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/aclocal.m4                                                        987            100           8712
2585yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/gtest/m4/libtool.m4                                               760             65           7176
2586yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/gtest/build-aux/ltmain.sh                                         959           1533           7169
2587yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/fused-src/gmock-gtest-all.cc                                     1514           3539           6390
2588yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/gtest/fused-src/gtest/gtest-all.cc                               1312           2896           5384
2589yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/gtest/test/gtest_unittest.cc                                     1226           1091           5098
2590yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/gtest/include/gtest/internal/gtest-param-util-generated.h         349            235           4559
2591</pre>
2592
2593The absence of language identification for each file
2594is a bit disappointing, but
2595this can be remedied with a custom column solution.
2596
2597The first step, creating a database, matches that from Example 1 so
2598we'll go straight to the second step of creating the desired
2599SQL query.  We'll store this one in the file `by_file_with_language.sql`:
2600
2601<pre>
2602-- file by_file_with_language.sql
2603select File, Language, nBlank   as blank  ,
2604                       nComment as comment,
2605                       nCode    as code
2606    from t order by code desc;
2607</pre>
2608
2609Our desired extra column appears when we pass this custom SQL query
2610through our database:
2611
2612<pre>
2613&gt; cat by_file_with_language.sql | sqlite3 -header counts.db | sqlite_formatter
2614File                                                                                               Language       blank comment code
2615__________________________________________________________________________________________________ ______________ _____ _______ _____
2616yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/configure                                                 Bourne Shell    2580    2264 13691
2617yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/gtest/configure                                           Bourne Shell    2541    2235 13446
2618yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/gtest/fused-src/gtest/gtest.h                             C/C++ Header    1972    4681 13408
2619yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/fused-src/gmock/gmock.h                                   C/C++ Header    1585    3397  9216
2620yaml-cpp-yaml-cpp-0.5.3/test/integration/gen_emitter_test.cpp                                      C++              999       0  8760
2621yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/aclocal.m4                                                m4               987     100  8712
2622yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/gtest/m4/libtool.m4                                       m4               760      65  7176
2623yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/gtest/build-aux/ltmain.sh                                 Bourne Shell     959    1533  7169
2624yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/fused-src/gmock-gtest-all.cc                              C++             1514    3539  6390
2625yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/gtest/fused-src/gtest/gtest-all.cc                        C++             1312    2896  5384
2626yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/gtest/test/gtest_unittest.cc                              C++             1226    1091  5098
2627yaml-cpp-yaml-cpp-0.5.3/test/gmock-1.7.0/gtest/include/gtest/internal/gtest-param-util-generated.h C/C++ Header     349     235  4559
2628</pre>
2629
2630[](1}}})
2631<a name="wrapping_cloc_in_other_scripts"></a> []({{{1)
2632    *   [](#wrapping-cloc-in-other-scripts-)
2633##  [Wrapping cloc in other scripts &#9650;](#___top "click to go to top of document")
2634
2635More complex code counting solutions are possible by wrapping
2636cloc in scripts or programs.  The "total lines" column from
2637example 1 of [Custom Column Output](#custom-column-output-)
2638could be simplified to a single command with this shell script (on Linux):
2639
2640<pre>
2641#!/bin/sh
2642#
2643# These commands must be in the user's $PATH:
2644#   cloc
2645#   sqlite3
2646#   sqlite_formatter
2647#
2648if test $# -eq 0 ; then
2649    echo "Usage: $0  [cloc arguments]"
2650    echo "       Run cloc to count lines of code with an additional"
2651    echo "       output column for total lines (code+comment+blank)."
2652    exit
2653fi
2654DBFILE=`tempfile`
2655cloc --sql 1 --sql-project x $@ | sqlite3 ${DBFILE}
2656SQL="select Language, count(File)   as files                       ,
2657                      sum(nBlank)   as blank                       ,
2658                      sum(nComment) as comment                     ,
2659                      sum(nCode)    as code                        ,
2660                      sum(nBlank)+sum(nComment)+sum(nCode) as Total
2661         from t group by Language order by code desc;
2662"
2663echo ${SQL} | sqlite3 -header ${DBFILE} | sqlite_formatter
2664rm ${DBFILE}
2665</pre>
2666
2667Saving the lines above to ``total_columns.sh`` and making it
2668executable (``chmod +x total_columns.sh``) would let us do
2669<pre>
2670./total_columns.sh yaml-cpp-yaml-cpp-0.5.3.tar.gz
2671</pre>
2672to directly get
2673<pre>
2674Language       files blank comment code  Total
2675______________ _____ _____ _______ _____ _____
2676C++              141 12786   17359 60378 90523
2677C/C++ Header     110  8566   17420 51502 77488
2678Bourne Shell      10  6351    6779 38264 51394
2679m4                11  2037     260 17980 20277
2680Python            30  1613    2486  4602  8701
2681MSBuild script    11     0       0  1711  1711
2682CMake              7   155     285   606  1046
2683make               5   127     173   464   764
2684Markdown           2    30       0    39    69
2685</pre>
2686
2687Other examples:
2688* Count code from a specific branch of a web-hosted
2689git repository and send the results as a .csv email attachment:
2690https://github.com/dannyloweatx/checkmarx
2691
2692
2693[](1}}})
2694<a name="git_and_UTF8_pathnames"></a> []({{{1)
2695##  [git and UTF8 pathnames &#9650;](#___top "click to go to top of document")
2696
2697cloc's ``--git`` option may fail if you work with directory or
2698file names with UTF-8 characters (for example, see
2699<a href=https://github.com/AlDanial/cloc/issues/457>issue 457</a>).
2700The solution,
2701https://stackoverflow.com/questions/22827239/how-to-make-git-properly-display-utf-8-encoded-pathnames-in-the-console-window,
2702is to apply this git configuration command:
2703
2704<pre>
2705git config --global core.quotepath off
2706</pre>
2707
2708Your console's font will need to be capable of displaying
2709Unicode characters.
2710
2711[](1}}})
2712<a name="scale_factors"></a> []({{{1)
2713##  [Third Generation Language Scale Factors &#9650;](#___top "click to go to top of document")
2714
2715cloc versions before 1.50 by default computed, for the provided inputs, a
2716rough estimate of how many lines of code would be needed to write the
2717same code in a hypothetical third-generation computer language.
2718To produce this output one must now use the `--3` switch.
2719
2720Scale factors were derived from the 2006 version of language gearing ratios
2721listed at Mayes Consulting web site,
2722[http://softwareestimator.com/IndustryData2.htm](http://softwareestimator.com/IndustryData2.htm), using this equation:
2723
2724cloc scale factor for language X = 3rd generation default gearing ratio / language X gearing ratio
2725
2726For example, cloc 3rd generation scale factor for DOS Batch = 80 / 128 = 0.625.
2727
2728The biggest flaw with this approach is that gearing ratios are defined
2729for logical lines of source code not physical lines (which cloc counts).
2730The values in cloc's 'scale' and '3rd gen. equiv.' columns should be
2731taken with a large grain of salt.
2732
2733[](1}}})
2734<a name="options_txt"></a> []({{{1)
2735##  [options.txt configuration file &#9650;](#___top "click to go to top of document")
2736
2737If you find yourself using the same command line switches every
2738time you invoke cloc, you can save some typing by adding those
2739switches to the ``options.txt`` runtime configuration file.
2740cloc will look for this file in the following default locations:
2741<pre>
2742# Linux, NetBSD, FreeBSD, macOS:
2743/home/USERNAME/.config/cloc/options.txt
2744
2745# Windows
2746C:\Users\USERNAME\AppData\cloc\options.txt
2747</pre>
2748
2749Place each switch and arguments, if any, on a line by itself.
2750Lines prefixed with ``#`` symbol are ignored as comments and
2751blank lines are skipped.  Leading hyphens on the switches are
2752optional.  Here's a sample file:
2753<pre>
2754# options.txt
2755--vcs git
2756v      # verbose level 1
2757exclude-ext svg,html
2758</pre>
2759
2760The path to the ``options.txt`` file can also be specified
2761with the ``--config FILE`` switch.
2762
2763Finally, if cloc finds an ``options.txt`` file in the same
2764directory as files given by any of these switches (in the
2765listed priority), it will use that configuration file
2766from that location:
2767
27681. ``--list-file``
27691. ``--exclude-list-file``
27701. ``--read-lang-def``
27711. ``--force-lang-def``
27721. ``--diff-list-file``
2773
2774Run with ``--verbose`` to have cloc tell you which, if
2775any, ``options.txt`` file it uses.
2776
2777[](1}}})
2778<a name="complex_regex_recursion"></a> []({{{1)
2779#  [Complex regular subexpression recursion limit &#9650;](#___top "click to go to top of document")
2780cloc relies on the Regexp::Common module's regular expressions to remove
2781comments from source code.  If comments are malformed, for example the
2782``/*`` start comment marker appears in a C program without a corresponding ``*/``
2783marker, the regular expression engine could enter a recursive
2784loop, eventually triggering the warning
2785``Complex regular subexpression recursion limit``.
2786
2787The most common cause for this warning is the existence of comment markers
2788in string literals.  While language compilers and interpreters are smart
2789enough to recognize that ``"/*"`` (for example) is a string and not a comment,
2790cloc is fooled.  File path globs, as in this line of JavaScript
2791<pre>var paths = globArray("**/*.js", {cwd: srcPath});
2792</pre>
2793are frequent culprits.
2794
2795In an attempt to overcome this problem, a different
2796algorithm which removes comment markers in strings can be enabled
2797with the ``--strip-str-comments`` switch.  Doing so, however,
2798has drawbacks:  cloc
2799will run more slowly and the output of ``--strip-comments``
2800will contain strings that no longer match the input source.
2801
2802[](1}}})
2803<a name="Limitations"></a> []({{{1)
2804#   [Limitations &#9650;](#___top "click to go to top of document")
2805Identifying comments within source code is trickier than one might expect.
2806Many languages would need a complete parser to be counted correctly.
2807cloc does not attempt to parse any of
2808the languages it aims to count and therefore is an imperfect tool.
2809The following are known problems:
2810
2811<ol>
2812<li>  Lines containing both source code and comments are counted as lines of code.
2813</li>
2814<li>  Comment markers within strings or
2815<a href="http://www.faqs.org/docs/abs/HTML/here-docs.html">here-documents</a>
2816are treated as actual comment markers and not string literals.
2817For example the following lines of C code
2818<pre>printf(" /* ");
2819for (i = 0; i < 100; i++) {
2820    a += i;
2821}
2822printf(" */ ");
2823</pre>
2824look to cloc like this:
2825<pre>printf(" xxxxxxx
2826xxxxxxx
2827xxxxxxx
2828xxxxxxx
2829xxxxxxx     ");
2830</pre>
2831where <tt>xxxxxxx</tt> represents cloc's view of commented text.
2832Therefore cloc counts the five lines as two lines of C code and three
2833lines of comments (lines with both code and comment are counted as code).
2834
2835If you suspect your code has such strings, use the switch
2836``--strip-str-comments`` to switch to the algorithm which removes
2837embedded comment markers.  Its use will render the five lines above as
2838<pre>printf("  ");
2839for (i = 0; i < 100; i++) {
2840    a += i;
2841}
2842printf("  ");
2843</pre>
2844and therefore return a count of five lines of code.
2845See the
2846[previous section](#complex-regular-subexpression-recursion-limit-)
2847on drawbacks to using ``--strip-str-comments``.
2848</li>
2849<li> Embedded languages are not recognized.  For example, an HTML file containing
2850JavaScript will be counted entirely as HTML.
2851</li>
2852<li> Python docstrings can serve several purposes.  They may
2853contain documentation,
2854comment out blocks of code, or they can be regular strings (when
2855they appear on the right hand side of an assignment or as a function argument).
2856cloc is unable to infer the meaning of docstrings by context; by default
2857cloc treats all docstrings as comments.  The switch
2858<tt>--docstring-as--code</tt>
2859treats all docstrings as code.
2860</li>
2861<li> Language definition files read with <tt>--read-lang-def</tt> or
2862<tt>--force-lang-def</tt> must be plain ASCII text files.
2863</li>
2864<li> cloc treats compiler pragma's, for example <tt>#if</tt> / <tt>#endif</tt>, as code
2865even if these are used to block lines of source from being compiled;
2866the blocked lines still contribute to the code count.
2867</li>
2868<li> On Windows, cloc  will fail with <tt>Can't cd to ... No such file or
2869directory at <embedded>/File/Find.pm</tt> if the code being scanned has
2870file paths longer than 255 characters.  A work-around is to run cloc
2871from the Windows Subsystem for Linux (WSL).
2872</li>
2873</ol>
2874
2875[](1}}})
2876<a name="AdditionalLanguages"></a> []({{{1)
2877#   [Requesting Support for Additional Languages &#9650;](#___top "click to go to top of document")
2878
2879If cloc does not recognize a language you are interested in counting,
2880create a [GitHub issue](https://github.com/AlDanial/cloc/issues)
2881requesting support for your language.  Include this information:
2882<ol>
2883<li> File extensions associated with the language.  If the language does
2884not rely on file extensions and instead works with fixed file names or
2885with `#!` style program invocations, explain what those are.</li>
2886<li> A description of how comments are defined.</li>
2887<li> Links to sample code.</li>
2888</ol>
2889
2890[](1}}})
2891<a name="reporting_problems"></a> []({{{1)
2892#  [Reporting Problems &#9650;](#___top "click to go to top of document")
2893
2894If you encounter a problem with cloc, first check to see if
2895you're running with the latest version of the tool:
2896<pre>
2897  cloc --version
2898</pre>
2899If the version is older than the most recent release
2900at https://github.com/AlDanial/cloc/releases, download the
2901latest version and see if it solves your problem.
2902
2903If the problem happens with the latest release, submit
2904a new issue at https://github.com/AlDanial/cloc/issues *only*
2905if you can supply enough information for anyone reading the
2906issue report to reproduce the problem.
2907That means providing
2908<ol>
2909<li> the operating system you're running on</li>
2910<li> the cloc command with all options</li>
2911<li> the code you are counting (URL to a public git repo or zip file or
2912tar file, et cetera)</li>
2913</ol>
2914The last item is generally problematic.  If the code base is
2915proprietary or amounts to more than a few dozen kilobytes,
2916you'll need to try to reconstruct similar inputs or demonstrate
2917the problem with an existing public code base.
2918
2919Problem reports that cannot be reproduced will be ignored and
2920eventually closed.
2921
2922[](1}}})
2923<a name="Acknowledgments"></a> []({{{1)
2924#   [Acknowledgments &#9650;](#___top "click to go to top of document")
2925[Wolfram Rösler](https://github.com/wolframroesler) provided most of the code examples in the test suite.
2926These examples come from his [Hello World collection](http://helloworldcollection.de/).
2927
2928Ismet Kursunoglu found errors with the MUMPS counter and provided
2929access to a computer with a large body of MUMPS code to test cloc.
2930
2931Tod Huggins gave helpful suggestions for the Visual Basic filters.
2932
2933Anton Demichev found a flaw with the JSP counter in cloc v0.76
2934and wrote the XML output generator for the `--xml` option.
2935
2936Reuben Thomas pointed out that ISO C99 allows `//` as a comment
2937marker, provided code for the `--no3` and `--stdin-name`
2938options, counting the m4 language,
2939and suggested several user-interface enhancements.
2940
2941Michael Bello provided code for the `--opt-match-f`,
2942`--opt-not-match-f`,
2943`--opt-match-d`, and `--opt-not-match-d`
2944options.
2945
2946Mahboob Hussain inspired the `--original-dir` and
2947`--skip-uniqueness` options, found a
2948bug in the duplicate file detection logic and improved the JSP filter.
2949
2950Randy Sharo found and fixed an uninitialized variable bug for shell
2951scripts having only one line.
2952
2953Steven Baker found and fixed a problem with the YAML output generator.
2954
2955Greg Toth provided code to improve blank line detection in COBOL.
2956
2957Joel Oliveira provided code to let `--exclude-list-file` handle
2958directory name exclusion.
2959
2960Blazej Kroll provided code to produce an XSLT file, `cloc-diff.xsl`,
2961when producing XML output for the `--diff` option.
2962
2963Denis Silakov enhanced the code which generates `cloc.xsl` when
2964using `--by-file` and `--by-file-by-lang` options, and
2965provided an XSL file that works with `--diff` output.
2966
2967Andy (awalshe@sf.net) provided code to fix several bugs:
2968correct output of `--counted`
2969so that only files that are used in the code count appear and
2970that results are shown by language rather than file name;
2971allow `--diff` output from multiple runs to be summed
2972together with `--sum-reports`.
2973
2974Jari Aalto created the initial version of `cloc.1.pod` and
2975maintains the Debian package for cloc.
2976
2977Mikkel Christiansen (mikkels@gmail.com) provided counter definitions
2978for Clojure and ClojureScript.
2979
2980Vera Djuraskovic from [Webhostinggeeks.com](http://webhostinggeeks.com/)
2981provided the
2982[Serbo-Croatian](http://science.webhostinggeeks.com/cloc)
2983translation.
2984
2985Gill Ajoft of [Ajoft Softwares](http://www.ajoft.com)
2986provided the
2987[Bulgarian](http://www.ajoft.com/wpaper/aj-cloc.html)
2988translation.
2989
2990The
2991[Knowledge Team](http://newknowledgez.com/)
2992provided the
2993[Slovakian](http://newknowledgez.com/cloc.html) translation.
2994
2995Erik Gooven Arellano Casillas provided an update to the MXML counter to
2996recognize ActionScript comments.
2997
2998[Gianluca Casati](http://g14n.info) created the
2999[cloc CPAN package](https://metacpan.org/pod/App::cloc).
3000
3001<!--- broken link
3002Mary Stefanova provided the
3003[Polish](http://www.trevister.com/blog/cloc.html)
3004translation. --->
3005
3006Ryan Lindeman implemented the `--by-percent` feature.
3007
3008Kent C. Dodds, [@kentcdodds](https://twitter.com/kentcdodd),
3009created and maintains the npm package of cloc.
3010
3011[Viktoria Parnak](http://kudoybook.com)
3012provided the
3013[Ukrainian](http://blog.kudoybook.com/cloc/)
3014translation.
3015
3016Natalie Harmann provided the
3017[Belarussian](http://www.besteonderdelen.nl/blog/?p=5426)
3018translation.
3019
3020Nithyal at [Healthcare Administration Portal](http://healthcareadministrationdegree.co/)
3021provided the
3022[Tamil](http://healthcareadministrationdegree.co/socialwork/aldanial-cloc/)
3023translation.
3024
3025Patricia Motosan
3026provided the
3027[Romanian](http://www.bildelestore.dk/blog/cloc-contele-de-linii-de-cod/)
3028translation.
3029
3030<!--- broken link
3031The [Garcinia Cambogia Review Team](http://www.garciniacambogiareviews.ca/)
3032provided the
3033[Arabic translation](http://www.garciniacambogiareviews.ca/translations/aldanial-cloc/). --->
3034
3035Gajk Melikyan provided the
3036provided the
3037[Armenian translation](http://students.studybay.com/?p=34)
3038for http://studybay.com.
3039
3040<a href="http://www.forallworld.com/cloc-grof-sornyi-kodot/">Hungarian translation</a>
3041courtesy of <a href="http://www.forallworld.com/">Zsolt Boros</a>.
3042
3043<a href=https://github.com/stsnel>Sietse Snel</a> implemented the parallel
3044processing capability available with the <tt>--processes=<i>N</i></tt>
3045switch.
3046
3047The development of cloc was partially funded by the Northrop Grumman
3048Corporation.
3049
3050[](1}}})
3051<a name="Copyright"></a> []({{{1)
3052#   [Copyright &#9650;](#___top "click to go to top of document")
3053Copyright (c) 2006-2018, [Al Danial](https://github.com/AlDanial)
3054[](1}}})
3055