App-cloc
view release on metacpan or search on metacpan
next if $sec =~ /SUM:/;
$res .= "$sec\n";
foreach (@rows) {
$res .= sprintf(" %-18s %14s %14s %14s %14s\n",
$_, $HoH{$sec}{"${_}${dl}${cols[0]}"},
$HoH{$sec}{"${_}${dl}${cols[1]}"},
$HoH{$sec}{"${_}${dl}${cols[2]}"},
$HoH{$sec}{"${_}${dl}${cols[3]}"});
}
}
$res .= sprintf("%s\n", "-" x $width);
my $sec = 'SUM:';
$res .= "$sec\n";
foreach (@rows) {
$res .= sprintf(" %-18s %14s %14s %14s %14s\n",
$_, $HoH{$sec}{"${_}${dl}${cols[0]}"},
$HoH{$sec}{"${_}${dl}${cols[1]}"},
$HoH{$sec}{"${_}${dl}${cols[2]}"},
$HoH{$sec}{"${_}${dl}${cols[3]}"});
}
$res .= sprintf("%s\n", "-" x $width);
return $res;
} # 1}}}
sub get_time { # {{{1
if ($HAVE_Time_HiRes) {
return Time::HiRes::time();
} else {
return time();
}
} # 1}}}
sub really_is_D { # {{{1
# Ref bug 131, files ending with .d could be init.d scripts
# instead of D language source files.
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> really_is_D($file)\n" if $opt_v > 2;
my $possible_script = peek_at_first_line($file, $rh_Err, $raa_errors);
print "<- really_is_D($file)\n" if $opt_v > 2;
return $possible_script; # null string if D, otherwise a language
} # 1}}}
sub no_autogen_files { # {{{1
# ref https://github.com/AlDanial/cloc/issues/151
my ($print,) = @_;
print "-> no_autogen($print)\n" if $opt_v > 2;
# These sometimes created manually?
# acinclude.m4
# configure.ac
# Makefile.am
my @files = qw (
aclocal.m4
announce-gen
autogen.sh
bootstrap
compile
config.guess
config.h.in
config.rpath
config.status
config.sub
configure
configure.in
depcomp
gendocs.sh
gitlog-to-changelog
git-version-gen
gnupload
gnu-web-doc-update
install-sh
libtool
libtool.m4
link-warning.h
ltmain.sh
lt~obsolete.m4
ltoptions.m4
ltsugar.m4
ltversion.in
ltversion.m4
Makefile.in
mdate-sh
missing
mkinstalldirs
test-driver
texinfo.tex
update-copyright
useless-if-before-free
vc-list-files
ylwrap
);
if ($print) {
printf "cloc will ignore these %d files with --no-autogen:\n", scalar @files;
foreach my $F (@files) {
print " $F\n";
}
print "Additionally, Go files with '// Code generated by .* DO NOT EDIT.'\n";
print "on the first line are ignored.\n";
}
print "<- no_autogen()\n" if $opt_v > 2;
return @files;
} # 1}}}
# subroutines copied from SLOCCount
my %lex_files = (); # really_is_lex()
my %expect_files = (); # really_is_expect()
my %php_files = (); # really_is_php()
sub really_is_lex { # {{{1
# Given filename, returns TRUE if its contents really is lex.
# lex file must have "%%", "%{", and "%}".
# In theory, a lex file doesn't need "%{" and "%}", but in practice
# they all have them, and requiring them avoid mislabeling a
# non-lexfile as a lex file.
my $filename = shift;
chomp($filename);
my $is_lex = 0; # Value to determine.
# 1. has "load_lib" command and either "#" comments or {}.
# 2. {, }, and one of: proc, if, [...], expect
my $is_expect = 0; # Value to determine.
my $begin_brace = 0; # Lines that begin with curly braces.
my $end_brace = 0; # Lines that begin with curly braces.
my $load_lib = 0; # Lines with the Load_lib command.
my $found_proc = 0;
my $found_if = 0;
my $found_brackets = 0;
my $found_expect = 0;
my $found_pound = 0;
# Return cached result, if available:
if ($expect_files{$filename}) { return expect_files{$filename};}
open(EXPECT_FILE, "<$filename") ||
die "Can't open $filename to determine if it's expect.\n";
while(<EXPECT_FILE>) {
if (m/#/) {$found_pound++; s/#.*//;}
if (m/^\s*\{/) { $begin_brace++;}
if (m/\{\s*$/) { $begin_brace++;}
if (m/^\s*\}/) { $end_brace++;}
if (m/\};?\s*$/) { $end_brace++;}
if (m/^\s*load_lib\s+\S/) { $load_lib++;}
if (m/^\s*proc\s/) { $found_proc++;}
if (m/^\s*if\s/) { $found_if++;}
if (m/\[.*\]/) { $found_brackets++;}
if (m/^\s*expect\s/) { $found_expect++;}
}
close(EXPECT_FILE);
if ($load_lib && ($found_pound || ($begin_brace && $end_brace)))
{$is_expect = 1;}
if ( $begin_brace && $end_brace &&
($found_proc || $found_if || $found_brackets || $found_expect))
{$is_expect = 1;}
$expect_files{$filename} = $is_expect; # Store result in cache.
return $is_expect;
} # 1}}}
sub really_is_pascal { # {{{1
# Given filename, returns TRUE if its contents really are Pascal.
# This isn't as obvious as it seems.
# Many ".p" files are Perl files
# (such as /usr/src/redhat/BUILD/ispell-3.1/dicts/czech/glob.p),
# others are C extractions
# (such as /usr/src/redhat/BUILD/linux/include/linux/umsdos_fs.p
# and some files in linuxconf).
# However, test files in "p2c" really are Pascal, for example.
# Note that /usr/src/redhat/BUILD/ucd-snmp-4.1.1/ov/bitmaps/UCD.20.p
# is actually C code. The heuristics determine that they're not Pascal,
# but because it ends in ".p" it's not counted as C code either.
# I believe this is actually correct behavior, because frankly it
# looks like it's automatically generated (it's a bitmap expressed as code).
# Rather than guess otherwise, we don't include it in a list of
# source files. Let's face it, someone who creates C files ending in ".p"
# and expects them to be counted by default as C files in SLOCCount needs
# their head examined. I suggest examining their head
# with a sucker rod (see syslogd(8) for more on sucker rods).
# This heuristic counts as Pascal such files such as:
# /usr/src/redhat/BUILD/teTeX-1.0/texk/web2c/tangleboot.p
# Which is hand-generated. We don't count woven documents now anyway,
# so this is justifiable.
my $filename = shift;
chomp($filename);
# The heuristic is as follows: it's Pascal _IF_ it has all of the following
# (ignoring {...} and (*...*) comments):
# 1. "^..program NAME" or "^..unit NAME",
# 2. "procedure", "function", "^..interface", or "^..implementation",
# 3. a "begin", and
# 4. it ends with "end.",
#
# Or it has all of the following:
# 1. "^..module NAME" and
# 2. it ends with "end.".
#
# Or it has all of the following:
# 1. "^..program NAME",
# 2. a "begin", and
# 3. it ends with "end.".
#
# The "end." requirements in particular filter out non-Pascal.
#
# Note (jgb): this does not detect Pascal main files in fpc, like
# fpc-1.0.4/api/test/testterminfo.pas, which does not have "program" in
# it
my $is_pascal = 0; # Value to determine.
my $has_program = 0;
my $has_unit = 0;
my $has_module = 0;
my $has_procedure_or_function = 0;
my $found_begin = 0;
my $found_terminating_end = 0;
my $has_begin = 0;
open(PASCAL_FILE, "<$filename") ||
die "Can't open $filename to determine if it's pascal.\n";
while(<PASCAL_FILE>) {
s/\{.*?\}//g; # Ignore {...} comments on this line; imperfect, but effective.
s/\(\*.*?\*\)//g; # Ignore (*...*) comments on this line; imperfect, but effective.
if (m/\bprogram\s+[A-Za-z]/i) {$has_program=1;}
if (m/\bunit\s+[A-Za-z]/i) {$has_unit=1;}
if (m/\bmodule\s+[A-Za-z]/i) {$has_module=1;}
if (m/\bprocedure\b/i) { $has_procedure_or_function = 1; }
if (m/\bfunction\b/i) { $has_procedure_or_function = 1; }
if (m/^\s*interface\s+/i) { $has_procedure_or_function = 1; }
if (m/^\s*implementation\s+/i) { $has_procedure_or_function = 1; }
if (m/\bbegin\b/i) { $has_begin = 1; }
# Originally I said:
# "This heuristic fails if there are multi-line comments after
( run in 2.170 seconds using v1.01-cache-2.11-cpan-6fb7bf0f510 )