2011-01-04 18:50:23 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# Missing comments (it is a good idea to write a comment before a variable declaration)
|
|
|
|
# usage:
|
|
|
|
# scripts/comment.pl lib/checkstl.cpp
|
|
|
|
sub checkfile
|
|
|
|
{
|
|
|
|
my $filename = $_[0];
|
|
|
|
|
|
|
|
# parse file
|
|
|
|
open(FILE, $filename);
|
|
|
|
my @lines = <FILE>;
|
|
|
|
close(FILE);
|
|
|
|
|
|
|
|
# check comments..
|
|
|
|
my $comment = false;
|
|
|
|
my $linenr = 0;
|
|
|
|
foreach $line (@lines)
|
|
|
|
{
|
|
|
|
$linenr = $linenr + 1;
|
|
|
|
|
|
|
|
# missing comment before variable declaration?
|
|
|
|
if (($comment == 0) &&
|
|
|
|
($line =~ /^\s+([a-z]+)? [a-z]+(\s)+[a-z][a-z0-9]*\s*[;=]/) &&
|
2011-01-06 12:42:02 +01:00
|
|
|
(!($line =~ /return|delete|operator/)))
|
2011-01-04 18:50:23 +01:00
|
|
|
{
|
|
|
|
print "[$filename:$linenr] No comment before variable declaration\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
# set comment variable
|
|
|
|
if ($line =~ /\/\//)
|
|
|
|
{
|
|
|
|
$comment = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$comment = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach $filename (@ARGV)
|
|
|
|
{
|
|
|
|
checkfile($filename)
|
|
|
|
}
|
|
|
|
|
|
|
|
|