Add find-longlines utility (find *.[CH] files that violate 80-cols)

This commit is contained in:
Mark Olesen
2008-06-23 10:14:42 +02:00
parent 495ae48746
commit b6279461fb
2 changed files with 47 additions and 0 deletions

View File

@ -11,4 +11,5 @@ Misc Tools
1. find-templateInComments
2. find-its
3. find-junkFiles
4. find-longlines

View File

@ -0,0 +1,46 @@
#!/usr/bin/perl -w
use strict;
use File::Find ();
# -----------------------------------------------------------------------------
#
# Script
# find-longlines
#
# Description
# Search for *.[CH] files that exceed the 80-column width
#
# - print filename lineNumber and offending line (with truncation point)
#
# -----------------------------------------------------------------------------
my $maxlen = 80;
my $re_filespec = qr{^.+\.[CH]$};
my $count;
sub wanted {
unless ( lstat($_) and -f _ and -r _ and not -l _ and /$re_filespec/ ) {
return;
}
local @ARGV = $_;
while (<>) {
chomp;
s{\s+$}{}; # trim
if ( $maxlen < length ) {
$count++;
substr( $_, $maxlen, 0 ) = "||->>"; # show truncation point
print "$ARGV $. $_\n";
}
}
close ARGV;
}
## Traverse desired filesystems
for my $dir (@ARGV) {
no warnings 'File::Find';
warn "(**) checking '$dir' ...\n";
File::Find::find( { wanted => \&wanted }, $dir );
}