From d6055f4c21fd4ce2462bfeed93349f49635a988d Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 18 Jan 2018 09:41:42 +0000 Subject: [PATCH] upgraded cloc to 1.75 --- codepot/etc/cloc.pl | 6041 +++++++++++++++++++++++++++++++------------ 1 file changed, 4436 insertions(+), 1605 deletions(-) diff --git a/codepot/etc/cloc.pl b/codepot/etc/cloc.pl index c82128dd..d3b9faeb 100755 --- a/codepot/etc/cloc.pl +++ b/codepot/etc/cloc.pl @@ -1,16 +1,16 @@ #!/usr/bin/env perl # cloc -- Count Lines of Code {{{1 -# Copyright (C) 2006-2014 Al Danial +# Copyright (C) 2006-2017 Al Danial # First release August 2006 # # Includes code from: -# - SLOCCount v2.26 +# - SLOCCount v2.26 # http://www.dwheeler.com/sloccount/ # by David Wheeler. -# - Regexp::Common v2.120 -# http://search.cpan.org/~abigail/Regexp-Common-2.120/lib/Regexp/Common.pm +# - Regexp::Common v2013031301 +# http://search.cpan.org/~abigail/Regexp-Common-2013031301/lib/Regexp/Common.pm # by Damian Conway and Abigail. -# - Win32::Autoglob +# - Win32::Autoglob # http://search.cpan.org/~sburke/Win32-Autoglob-1.01/Autoglob.pm # by Sean M. Burke. # - Algorithm::Diff @@ -29,12 +29,13 @@ # . # # 1}}} -my $VERSION = "1.62"; # odd number == beta; even number == stable -my $URL = "http://cloc.sourceforge.net"; +my $VERSION = "1.75"; # odd number == beta; even number == stable +my $URL = "github.com/AlDanial/cloc"; # 'https://' pushes header too wide require 5.006; # use modules {{{1 use warnings; use strict; + use Getopt::Long; use File::Basename; use File::Temp qw { tempfile tempdir }; @@ -42,7 +43,14 @@ use File::Find; use File::Path; use File::Spec; use IO::File; -use POSIX "strftime"; +use List::Util qw( min max ); +use Cwd; +use POSIX qw { strftime ceil}; + +# Parallel::ForkManager isn't in the standard distribution. +# Use it only if installed, and only if --processes=N is given. +# The module load happens in get_max_processes(). +my $HAVE_Parallel_ForkManager = 0; # Digest::MD5 isn't in the standard distribution. Use it only if installed. my $HAVE_Digest_MD5 = 0; @@ -80,6 +88,7 @@ if (defined $Algorithm::Diff::VERSION) { } # print "2 HAVE_Algorith_Diff = $HAVE_Algorith_Diff\n"; # test_alg_diff($ARGV[$#ARGV - 1], $ARGV[$#ARGV]); die; +# die "Hre=$HAVE_Rexexp_Common Had=$HAVE_Algorith_Diff"; # Uncomment next two lines when building Windows executable with perl2exe # or if running on a system that already has Regexp::Common. @@ -116,9 +125,6 @@ if (defined $Algorithm::Diff::VERSION) { use Text::Tabs qw { expand }; use Cwd qw { cwd }; use File::Glob; -my $PERL_516 = $] >= 5.016 ? 1 : 0; # 5.16 deprecates defined(@array) -no warnings 'deprecated'; # will need to comment this out to test - # each new Perl version # 1}}} # Usage information, options processing. {{{1 my $ON_WINDOWS = 0; @@ -136,8 +142,27 @@ my $NN = chr(27) . "[0m"; # normal my $BB = chr(27) . "[1m"; # bold $BB = "" if $ON_WINDOWS or !(-t STDERR); my $script = basename $0; +my $brief_usage = " + cloc -- Count Lines of Code + +Usage: + $script [options] + Count physical lines of source code and comments in the given files + (may be archives such as compressed tarballs or zip files) and/or + recursively below the given directories or git commit hashes. + Example: cloc src/ include/ main.c + + $script [options] --diff + Compute differences of physical lines of source code and comments + between any pairwise combination of directory names, archive + files or git commit hashes. + Example: cloc --diff Python-3.5.tar.xz python-3.6/ + +$script --help shows full documentation on the options. +http://$URL has numerous examples and more information. +"; my $usage = " -Usage: $script [options] | | +Usage: $script [options] | | Count, or compute differences of, physical lines of source code in the given files (may be archives such as compressed tarballs or zip files) @@ -161,27 +186,60 @@ Usage: $script [options] | | --extract-with=\"\\\"c:\\Program Files\\WinZip\\WinZip32.exe\\\" -e -o >FILE< .\" (if WinZip is installed there). --list-file= Take the list of file and/or directory names to - process from which has one file/directory - name per line. See also --exclude-list-file. + process from , which has one file/directory + name per line. Only exact matches are counted; + relative path names will be resolved starting from + the directory where cloc is invoked. + See also --exclude-list-file. + --vcs= Invoke a system call to to obtain a list of + files to work on. If is 'git', then will + invoke 'git ls-files' to get a file list and + 'git submodule status' to get a list of submodules + whose contents will be ignored. See also --git + which accepts git commit hashes and branch names. + If is 'svn' then will invoke 'svn list -R'. + The primary benefit is that cloc will then skip + files explicitly excluded by the versioning tool + in question, ie, those in .gitignore or have the + svn:ignore property. + Alternatively may be any system command + that generates a list of files. + Note: cloc must be in a directory which can read + the files as they are returned by . cloc will + not download files from remote repositories. + 'svn list -R' may refer to a remote repository + to obtain file names (and therefore may require + authentication to the remote repository), but + the files themselves must be local. --unicode Check binary files to see if they contain Unicode expanded ASCII text. This causes performance to - drop noticably. + drop noticeably. ${BB}Processing Options${NN} --autoconf Count .in files (as processed by GNU autoconf) of - recognized languages. + recognized languages. See also --no-autogen. --by-file Report results for every source file encountered. --by-file-by-lang Report results for every source file encountered in addition to reporting by language. + --count-and-diff + First perform direct code counts of source file(s) + of and separately, then perform a diff + of these. Inputs may be pairs of files, directories, + or archives. If --out or --report-file is given, + three output files will be created, one for each + of the two counts and one for the diff. See also + --diff, --diff-alignment, --diff-timeout, + --ignore-case, --ignore-whitespace. --diff Compute differences in code and comments between source file(s) of and . The inputs - may be pairs of files, directories, or archives. - Use --diff-alignment to generate a list showing - which file pairs where compared. See also - --ignore-case, --ignore-whitespace. + may be any mix of files, directories, archives, + or git commit hashes. Use --diff-alignment to + generate a list showing which file pairs where + compared. See also --count-and-diff, --diff-alignment, + --diff-timeout, --ignore-case, --ignore-whitespace. --diff-timeout Ignore files which take more than seconds to process. Default is 10 seconds. - (Large files with many repeated lines can cause + (Large files with many repeated lines can cause Algorithm::Diff::sdiff() to take hours.) --follow-links [Unix only] Follow symbolic links to directories (sym links to files are always followed). @@ -200,14 +258,27 @@ Usage: $script [options] | | See also --script-lang, --lang-no-ext. --force-lang-def= Load language processing filters from , then use these filters instead of the built-in - filters. Note: languages which map to the same + filters. Note: languages which map to the same file extension (for example: - MATLAB/Objective C/MUMPS; Pascal/PHP; - Lisp/OpenCL) will be ignored as these require - additional processing that is not expressed in - language definition files. Use --read-lang-def - to define new language filters without replacing - built-in filters (see also --write-lang-def). + MATLAB/Mathematica/Objective C/MUMPS/Mercury; + Pascal/PHP; Lisp/OpenCL; Lisp/Julia; Perl/Prolog) + will be ignored as these require additional + processing that is not expressed in language + definition files. Use --read-lang-def to define + new language filters without replacing built-in + filters (see also --write-lang-def). + --git Forces the inputs to be interpreted as git targets + (commit hashes, branch names, et cetera) if these + are not first identified as file or directory + names. This option overrides the --vcs=git logic + if this is given; in other words, --git gets its + list of files to work on directly from git using + the hash or branch name rather than from + 'git ls-files'. This option can be used with + --diff to perform line count diffs between git + commits, or between a git commit and a file, + directory, or archive. Use -v/--verbose to see + the git system commands cloc issues. --ignore-whitespace Ignore horizontal white space when comparing files with --diff. See also --ignore-case. --ignore-case Ignore changes in case; consider upper- and lower- @@ -221,21 +292,28 @@ Usage: $script [options] | | --force-lang, --script-lang. --max-file-size= Skip files larger than megabytes when traversing directories. By default, =100. - cloc's memory requirement is roughly twenty times - larger than the largest file so running with - files larger than 100 MB on a computer with less - than 2 GB of memory will cause problems. - Note: this check does not apply to files + cloc's memory requirement is roughly twenty times + larger than the largest file so running with + files larger than 100 MB on a computer with less + than 2 GB of memory will cause problems. + Note: this check does not apply to files explicitly passed as command line arguments. + --no-autogen[=list] Ignore files generated by code-production systems + such as GNU autoconf. To see a list of these files + (then exit), run with --no-autogen list + See also --autoconf. + --original-dir [Only effective in combination with + --strip-comments] Write the stripped files + to the same directory as the original files. --read-binary-files Process binary files in addition to text files. This is usually a bad idea and should only be attempted with text files that have embedded binary data. --read-lang-def= Load new language processing filters from - and merge them with those already known to cloc. - If defines a language cloc already knows - about, cloc's definition will take precedence. - Use --force-lang-def to over-ride cloc's + and merge them with those already known to cloc. + If defines a language cloc already knows + about, cloc's definition will take precedence. + Use --force-lang-def to over-ride cloc's definitions (see also --write-lang-def ). --script-lang=, Process all files that invoke as a #! scripting language with the counter for language @@ -257,23 +335,42 @@ Usage: $script [options] | | files with identical contents multiple times (if such duplicates exist). --stdin-name= Give a file name to use to determine the language - for standard input. + for standard input. (Use - as the input name to + receive source code via STDIN.) --strip-comments= For each file processed, write to the current directory a version of the file which has blank - lines and comments removed. The name of each - stripped file is the original file name with - . appended to it. It is written to the - current directory unless --original-dir is on. - --original-dir [Only effective in combination with - --strip-comments] Write the stripped files - to the same directory as the original files. + and commented lines removed (in-line comments + persist). The name of each stripped file is the + original file name with . appended to it. + It is written to the current directory unless + --original-dir is on. --sum-reports Input arguments are report files previously created with the --report-file option. Makes a cumulative set of results containing the sum of data from the individual report files. + --processes=NUM Sets the maximum number of processes that cloc + uses. If this parameter is set to 0, multi- + processing will be disabled. On Linux and MacOS + systems, cloc creates up to one process per core + by default if a recent version of the + Parallel::ForkManager module is available. + Multiprocessing is disabled by default if cloc + is unable to determine the number of CPU cores. + Multiprocessing is not supported on Windows systems + and on systems which don't have a recent version + of the Parallel::ForkManager module. --unix Override the operating system autodetection logic and run in UNIX mode. See also --windows, --show-os. + --use-sloccount If SLOCCount is installed, use its compiled + executables c_count, java_count, pascal_count, + php_count, and xml_count instead of cloc's + counters. SLOCCount's compiled counters are + substantially faster than cloc's and may give + a performance improvement when counting projects + with large files. However, these cloc-specific + features will not be available: --diff, + --count-and-diff, --strip-comments, --unicode. --windows Override the operating system autodetection logic and run in Microsoft Windows mode. See also --unix, --show-os. @@ -282,33 +379,62 @@ Usage: $script [options] | | --exclude-dir=[,D2,] Exclude the given comma separated directories D1, D2, D3, et cetera, from being scanned. For example --exclude-dir=.cache,test will skip - all files that have /.cache/ or /test/ as part - of their path. - Directories named .bzr, .cvs, .hg, .git, and - .svn are always excluded. + all files and subdirectories that have /.cache/ + or /test/ as their parent directory. + Directories named .bzr, .cvs, .hg, .git, .svn, + and .snapshot are always excluded. + This option only works with individual directory + names so including file path separators is not + allowed. Use --fullpath and --not-match-d= + to supply a regex matching multiple subdirectories. --exclude-ext=[,[...]] Do not count files having the given file name extensions. --exclude-lang=[,L2,] Exclude the given comma separated languages L1, L2, L3, et cetera, from being counted. --exclude-list-file= Ignore files and/or directories whose names - appear in . should have one entry - per line. Relative path names will be resolved - starting from the directory where cloc is - invoked. See also --list-file. + appear in . should have one file + name per line. Only exact matches are ignored; + relative path names will be resolved starting from + the directory where cloc is invoked. + See also --list-file. + --fullpath Modifies the behavior of --match-f, --not-match-f, + and --not-match-d to include the file's path + in the regex, not just the file's basename. + (This does not expand each file to include its + absolute path, instead it uses as much of + the path as is passed in to cloc.) + Note: --match-d always looks at the full + path and therefore is unaffected by --fullpath. + --include-lang=[,L2,] Count only the given comma separated languages + L1, L2, L3, et cetera. --match-d= Only count files in directories matching the Perl regex. For example --match-d='/(src|include)/' only counts files in directories containing - /src/ or /include/. + /src/ or /include/. Unlike --not-match-d, + --match-f, and --not-match-f, --match-d always + compares the fully qualified path against the + regex. --not-match-d= Count all files except those in directories - matching the Perl regex. + matching the Perl regex. Only the trailing + directory name is compared, for example, when + counting in /usr/local/lib, only 'lib' is + compared to the regex. + Add --fullpath to compare parent directories to + the regex. + Do not include file path separators at the + beginning or end of the regex. --match-f= Only count files whose basenames match the Perl regex. For example --match-f='^[Ww]idget' only counts files that start with Widget or widget. + Add --fullpath to include parent directories + in the regex instead of just the basename. --not-match-f= Count all files except those whose basenames - match the Perl regex. + match the Perl regex. Add --fullpath to include + parent directories in the regex instead of just + the basename. --skip-archive= Ignore files that end with the given Perl regular expression. For example, if given --skip-archive='(zip|tar(\.(gz|Z|bz2|xz|7z))?)' @@ -320,20 +446,20 @@ Usage: $script [options] | | ${BB}Debug Options${NN} --categorized= Save names of categorized files to . --counted= Save names of processed source files to . - --explain= Print the filters used to remove comments for - language and exit. In some cases the - filters refer to Perl subroutines rather than - regular expressions. An examination of the - source code may be needed for further explanation. --diff-alignment= Write to a list of files and file pairs showing which files were added, removed, and/or compared during a run with --diff. This switch forces the --diff mode on. + --explain= Print the filters used to remove comments for + language and exit. In some cases the + filters refer to Perl subroutines rather than + regular expressions. An examination of the + source code may be needed for further explanation. --help Print this usage information and exit. --found= Save names of every file found to . --ignored= Save names of ignored files and the reason they were ignored to . - --print-filter-stages Print processed source code before and after + --print-filter-stages Print processed source code before and after each filter is applied. --show-ext[=] Print information about all known (or just the given) file extensions and exit. @@ -342,6 +468,7 @@ Usage: $script [options] | | --show-os Print the value of the operating system mode and exit. See also --unix, --windows. -v[=] Verbose switch (optional numeric value). + -verbose[=] Long form of -v. --version Print the version of this program and exit. --write-lang-def= Writes to the language processing filters then exits. Useful as a first step to creating @@ -353,6 +480,24 @@ Usage: $script [options] | | (This option can cause report summation to fail if some reports were produced with this option while others were produced without it.) + --by-percent X Instead of comment and blank line counts, show + these values as percentages based on the value + of X in the denominator: + X = 'c' -> # lines of code + X = 'cm' -> # lines of code + comments + X = 'cb' -> # lines of code + blanks + X = 'cmb' -> # lines of code + comments + blanks + For example, if using method 'c' and your code + has twice as many lines of comments as lines + of code, the value in the comment column will + be 200%. The code column remains a line count. + --csv Write the results as comma separated values. + --csv-delimiter= Use the character as the delimiter for comma + separated files instead of ,. This switch forces + --json Write the results as JavaScript Object Notation + (JSON) formatted output. + --md Write the results as Markdown-formatted text. + --out= Synonym for --report-file=. --progress-rate= Show progress update after every files are processed (default =100). Set to 0 to suppress progress output (useful when redirecting @@ -360,19 +505,17 @@ Usage: $script [options] | | --quiet Suppress all information messages except for the final report. --report-file= Write the results to instead of STDOUT. - --out= Synonym for --report-file=. - --csv Write the results as comma separated values. - --csv-delimiter= Use the character as the delimiter for comma - separated files instead of ,. This switch forces - --csv to be on. --sql= Write results as SQL create and insert statements which can be read by a database program such as SQLite. If is -, output is sent to STDOUT. - --sql-project= Use as the project identifier for the - current run. Only valid with the --sql option. --sql-append Append SQL insert statements to the file specified by --sql and do not generate table creation statements. Only valid with the --sql option. + --sql-project= Use as the project identifier for the + current run. Only valid with the --sql option. + --sql-style=