Cloc Linux Download

4 views
Skip to first unread message

Kathrine Selvage

unread,
Jul 23, 2024, 6:22:52 PM (2 days ago) Jul 23
to opencog

cloc counts blank lines, comment lines,and physical lines of source code in many programming languages.Given two versions of a code base, cloc can computedifferences in blank, comment, and source lines.It is written entirely in Perl with no dependencies outside thestandard distribution of Perl v5.6 and higher (code from some external modules is embedded within cloc)and so is quite portable.cloc is known to run on many flavors of Linux, FreeBSD,NetBSD, OpenBSD,Mac OS X, AIX, HP-UX, Solaris, IRIX, z/OS, and Windows.(To run the Perl source version of cloc on Windows one needs ActiveState Perl5.6.1 or higher, Strawberry Perl, Cygwin, or MobaXTerm withthe Perl plug-in installed.Alternatively one can use the Windows binary of cloc generated with PAR::Packer to run on Windows computers that have neither Perl nor Cygwin.)

cloc linux download


Download Ziphttps://cinurl.com/2zHuQP



cloc contains code from David Wheeler's SLOCCount,Damian Conway and Abigail's Perl moduleRegexp::Common,Sean M. Burke's Perl moduleWin32::Autoglob, and Tye McQueen's Perl moduleAlgorithm::Diff.Language scale factors were derived from Mayes Consulting, LLC web site

npm install -g cloc # sudo apt-get install cloc # Debian, Ubuntu sudo yum install cloc # Red Hat, Fedora sudo pacman -S cloc # Arch sudo pkg install cloc # FreeBSD sudo port install cloc # Mac OS X with MacPorts

cloc is licensed under the GNU General Public License, v2, excludingportions which are copied from other sources. Code copied from the Regexp::Common, Win32::Autoglob, and Algorithm::Diff Perl modules is subject to the Artistic License.

Although cloc does not need Perl modules outside those found in the standard distribution, cloc does rely on a few external modules.Code from three of these external modules--Regexp::Common,Win32::Autoglob, and Algorithm::Diff--is embedded within cloc. A fourth module,Digest::MD5, is used only if it is available.If cloc finds Regexp::Common or Algorithm::Diffinstalled locally it will use thoseinstallation. If it doesn't, cloc will install the partsof Regexp::Commonand/or Algorithm:Diffit needs to temporary directories that are createdat the start of a cloc run then removed when the run is complete. The necessary code from Regexp::Common v2.120 andAlgorithm::Diff v1.1902 are embedded withinthe cloc source code (see subroutinesInstall_Regexp_Common() andInstall_Algorithm_Diff() ).Only three lines are needed from Win32::Autoglob and these areincluded directly in cloc.

The default Windows download, cloc-1.64.exe, was built with PAR::Packer on a Windows 7 computer with Strawberry Perl. Windows executables of cloc versions 1.60 and earlier were built withperl2exeon a 32 bit Windows XP computer. A small modification was madeto the cloc source code before passing it to perl2exe; lines 87 and88 were uncommented:85 # Uncomment next two lines when building Windows executable with perl2exe86 # or if running on a system that already has Regexp::Common. 87 #use Regexp::Common;88 #$HAVE_Rexexp_Common = 1;

Windows executables of cloc versions 1.60 and earlier, created with perl2exe as noted above,are about 1.6 MB, while newer versions, created with PAR::Packer,are 11 MB.Why are the newer executables so much larger? My theory is that perl2exe uses smarter tree pruning logic than PAR::Packer, but that's pure speculation.

Otherwise,to build a Windows executable with pp from PAR::Packer,first install a Windows-based Perl distribution (for exampleStrawberry Perl or ActivePerl) following their instructions. Next, opena command prompt, aka a DOS window and install the PAR::Packer module.Finally, invoke the newly installed pp command with thecloc souce code to create an .exe file:C:> perl -MCPAN -e shellcpan> install PAR::Packercpan> exitC:> pp cloc-1.64.plA variation on the above is if you installed the portable versionof Strawberry Perl, you will need to run portableshell.batfirst to properly set up your environment. The Strawberry Perlderived executable on the SourceForge download area was createdwith the portable version on a Windows 7 computer.

Languages with file extension collisions are difficult tocustomize with --read-lang-def or--force-lang-def as they have no mechanism to identify languages with common extensions. In thissituation one must modify the cloc source code.

cloc's method of operation resembles SLOCCount's: First, createa list of files to consider. Next, attempt to determine whether or notfound files contain recognized computer language source code. Finally, for files identified as source files, invoke language-specific routinesto count the number of source lines.

How can you tell if cloc correctly identifies comments?One way to convince yourself cloc is doing the right thing is to use its --strip-comments option toremove comments and blank lines from files, then compare the stripped-down files to originals.

We can now compare the orignial file,sqlite3.c and the one stripped of comments,sqlite3.c.nc with tools like diff or vimdiff and seewhat exactly cloc considered comments and blank lines.A rigorous proof that the stripped-down file contains the same C codeas the original is to compile these files and compare checksums of theresulting object files.

Versions of cloc before v1.07 required an --extract-with= option to tell cloc howto expand an archive file. Beginning with v1.07 this is extraction isattempted automatically. At the moment the automatic extraction method worksreasonably well on Unix-type OS's for the following file types:.tar.gz,.tar.bz2,.tgz,.zip,.ear.Some of these extensions work on Windows if one has WinZip installedin the default location (C:\Program Files\WinZip\WinZip32.exe).Additionally, with newer versions of WinZip, the command line add-onis needed for correct operation; in this case one would invoke cloc withsomething like
--extract-with="\"c:\Program Files\WinZip\wzunzip\" -e -o >FILE< ." (ref. forum post).

In situations where the automatic extraction fails, one can try the --extract-with=option to count lines of code within tar files, Zip files, orother compressed archives for which one has an extraction tool.cloc takes the user-provided extraction command and expands the archiveto a temporary directory (created with File::Temp), counts the lines of code in the temporary directory,then removes that directory. While not especially helpful when dealingwith a single compressed archive (after all, if you're going to typethe extraction command anyway why not just manually expand the archive?)this option is handy for working with several archives at once.

In addition to file pairs, one can give cloc pairs ofdirectories, or pairs of file archives, or a file archiveand a directory. cloc will try to align file pairs within the directories or archives and compare diffsfor each pair. For example, to see what changed betweenGCC 4.4.0 and 4.5.0 one could do

cloc can write its language comment definitions to a file or can readcomment definitions from a file, overriding the built-in definitions.This can be useful when you want to use cloc to count lines of alanguage not yet included, to change association of file extensionsto languages, or to modify the way existing languages are counted.

A more complete discussion of the different filter options may appearhere in the future. The output of cloc's --write-lang-def option should provide enough examplesfor motivated individuals to modify or extend cloc's language definitions.

If you manage multiple software projects you might be interested inseeing line counts by project, not just by language.Say you manage three software projects called MySQL, PostgreSQL, and SQLite.The teams responsible for each of these projects run cloc on theirsource code and provide you with the output.For example MySQL team does

The metadata table contains information about when the cloc run was made. The --sql-append switch allows one to combinemany runs in a single database; each run adds arow to the metadata table.The code count information resides in table t.

The --sql switch tells cloc to generate output in the formof SQL table create and insert commands. The switch takes an argument of a file name to write these SQL statements into, or,if the argument is 1 (numeric one), streams output to STDOUT.Since the SQLite command line program, sqlite3, can readcommands from STDIN, we can dispense with storing SQL statements toa file and use --sql 1 to pipe data directly into theSQLite executable:

cloc versions before 1.50 by default computed, for the provided inputs, arough estimate of how many lines of code would be needed to write thesame code in a hypothetical third-generation computer language.To produce this output one must now use the --3 switch.

The biggest flaw with this approach is that gearing ratiosare defined for logical lines of source code not physical lines (which cloc counts).The values in cloc's 'scale' and '3rd gen. equiv.' columns should be taken with a large grain of salt.

Identifying comments within source code is trickier than one might expect.Many languages would need a complete parser to be counted correctly.cloc does not attempt to parse any of the languages it aims to count and therefore is an imperfect tool.The following are known problems:

If cloc does not recognize a language you are interested in counting,post the following information to a Feature Requestat cloc's SourceForge page:

  1. File extensions associated with the language. If the language doesnot rely on file extensions and instead works with fixed file names orwith #! style program invocations, explain what those are.
  2. A description of how comments are defined.
  3. Links to sample code.

cloc is a command-line-based tool. It counts the blank lines, comment lines, actual code lines written in many programming languages. cloc is completely written in the Perl language, and it has no external dependencies. cloc can run on many operating systems like Linux, macOS, Windows, OpenBSD and many more.

I encountered the same problem on a debian:stretch-based container running on Docker for Windows, where the volume cloc was running against was a local directory. The solution was to add --follow-links to cloc:

760c119bf3
Reply all
Reply to author
Forward
0 new messages