#!/usr/bin/perl -w # # countKLOC: Count lines of code under the current directory. # # 2008-01-17: Written by Steven J. DeRose, sderose@acm.org. # 2010-09-12 sjd: Clean up. # # To do: # use strict; use Getopt::Long; my $version = "2010-09-12"; my $long = 0; my $quiet = 0; my $verbose = 0; # Process options # Getopt::Long::Configure ("ignore_case"); my $result = GetOptions( "h|help|?" => sub { system "perldoc countKLOC"; exit; }, "l!" => \$long, "q|quiet!" => \$quiet, "v|verbose+" => \$verbose, "version" => sub { die "Version of $version, by Steven J. DeRose.\n"; } ); ($result) || die "Bad options.\n"; ############################################################################### # my @exts = ( qw/ xsl xslt cc cpp c pl sh css js pm dtd end xsd / ); for my $x (@exts) { print "\nLooking for extension '$x'...\n"; my $cmd = "find . -name '*.$x' | xargs wc -l"; if (!$long) { $cmd .= " | grep ' total\$'"; } system "$cmd"; } print "\nLooking for extensionless files...\n"; my $cmd = "find . -type f -regex '.*/[^.~#]*' | xargs wc -l"; if (!$long) { $cmd .= " | grep ' total\$'"; } system "$cmd"; exit; ############################################################################### # sub showUsage() { warn " =head1 Usage countKLOC [options] [file] Count lines of code, by file extension. =head1 Options =over =item * B<-q> Suppress most messages. =item * B<-v> Add more detailed messages. =item * B<-version> Display version info and exit. =back =head1 Known bugs and limitations KLOC is not that meaningful to start with. 'Line' isn't cleverly defined either -- just using 'wc -l'. =head1 Ownership This work by Steven J. DeRose is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. For further information on this license, see http://creativecommons.org/licenses/by-sa/3.0/. The author's present email is sderose at acm.org. For the most recent version, see http://www.derose.net/steve/utilities/. =cut "; }