2004-11-09 21:04:00 +01:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
2005-06-11 20:52:37 +02:00
|
|
|
if ($ARGV[0] =~ /^-/) {
|
|
|
|
$lang = shift @ARGV;
|
|
|
|
$C = ($lang eq '-C');
|
|
|
|
# $TXT = ($lang eq '-txt');
|
|
|
|
}
|
|
|
|
|
2004-11-09 21:04:00 +01:00
|
|
|
for $fn (@ARGV) {
|
|
|
|
open(F, "$fn");
|
|
|
|
$lastnil = 0;
|
2004-11-23 00:28:54 +01:00
|
|
|
$incomment = 0;
|
2004-11-09 21:04:00 +01:00
|
|
|
while (<F>) {
|
2004-11-23 00:28:54 +01:00
|
|
|
## Warn about windows-style newlines.
|
2004-11-10 02:20:17 +01:00
|
|
|
if (/\r/) {
|
|
|
|
print " CR:$fn:$.\n";
|
|
|
|
}
|
2004-11-23 00:28:54 +01:00
|
|
|
## Warn about tabs.
|
2004-11-10 02:20:17 +01:00
|
|
|
if (/\t/) {
|
|
|
|
print " TAB:$fn:$.\n";
|
|
|
|
}
|
2004-11-23 00:28:54 +01:00
|
|
|
## Warn about trailing whitespace.
|
2004-11-10 02:20:17 +01:00
|
|
|
if (/ +$/) {
|
|
|
|
print "Space\@EOL:$fn:$.\n";
|
|
|
|
}
|
2004-11-23 00:28:54 +01:00
|
|
|
## Warn about control keywords without following space.
|
2005-06-11 20:52:37 +02:00
|
|
|
if ($C && /\s(?:if|while|for|switch)\(/) {
|
2004-11-28 10:05:49 +01:00
|
|
|
print " KW(:$fn:$.\n";
|
|
|
|
}
|
2004-11-23 00:28:54 +01:00
|
|
|
## Warn about multiple empty lines.
|
2004-11-10 02:20:17 +01:00
|
|
|
if ($lastnil && /^$/) {
|
|
|
|
print " DoubleNL:$fn:$.\n";
|
|
|
|
} elsif (/^$/) {
|
|
|
|
$lastnil = 1;
|
|
|
|
} else {
|
|
|
|
$lastnil = 0;
|
|
|
|
}
|
2005-12-09 06:37:26 +01:00
|
|
|
## Terminals are still 80 columns wide in my world. I refuse to
|
2006-07-26 00:30:50 +02:00
|
|
|
## accept double-line lines. Except, of course, svn Id tags
|
|
|
|
## can make us go long.
|
|
|
|
if (/^.{80}/ && !/\$Id: /) {
|
2005-12-09 06:37:26 +01:00
|
|
|
print " Wide:$fn:$.\n";
|
|
|
|
}
|
2004-11-23 00:28:54 +01:00
|
|
|
### Juju to skip over comments and strings, since the tests
|
|
|
|
### we're about to do are okay there.
|
2005-06-11 20:52:37 +02:00
|
|
|
if ($C) {
|
|
|
|
if ($incomment) {
|
|
|
|
if (m!\*/!) {
|
|
|
|
s!.*?\*/!!;
|
|
|
|
$incomment = 0;
|
|
|
|
} else {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m!/\*.*?\*/!) {
|
|
|
|
s!\s*/\*.*?\*/!!;
|
|
|
|
} elsif (m!/\*!) {
|
|
|
|
s!\s*/\*!!;
|
|
|
|
$incomment = 1;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
s!"(?:[^\"]+|\\.)*"!"X"!g;
|
|
|
|
next if /^\#/;
|
|
|
|
## Warn about C++-style comments.
|
|
|
|
if (m!//!) {
|
|
|
|
# print " //:$fn:$.\n";
|
|
|
|
s!//.*!!;
|
|
|
|
}
|
|
|
|
## Warn about braces preceded by non-space.
|
|
|
|
if (/([^\s])\{/) {
|
|
|
|
print " $1\{:$fn:$.\n";
|
|
|
|
}
|
|
|
|
## Warn about multiple internal spaces.
|
|
|
|
#if (/[^\s,:]\s{2,}[^\s\\=]/) {
|
|
|
|
# print " X X:$fn:$.\n";
|
|
|
|
#}
|
|
|
|
## Warn about { with stuff after.
|
|
|
|
#s/\s+$//;
|
|
|
|
#if (/\{[^\}\\]+$/) {
|
|
|
|
# print " {X:$fn:$.\n";
|
|
|
|
#}
|
|
|
|
## Warn about function calls with space before parens.
|
|
|
|
if (/(\w+)\s\(/) {
|
|
|
|
if ($1 ne "if" and $1 ne "while" and $1 ne "for" and
|
|
|
|
$1 ne "switch" and $1 ne "return" and $1 ne "int" and
|
|
|
|
$1 ne "void" and $1 ne "__attribute__") {
|
|
|
|
print " fn ():$fn:$.\n";
|
|
|
|
}
|
|
|
|
}
|
2005-09-30 03:07:55 +02:00
|
|
|
## Warn about functions not declared at start of line.
|
2006-07-26 00:30:50 +02:00
|
|
|
if ($in_func_head ||
|
2005-09-30 03:39:24 +02:00
|
|
|
($fn !~ /\.h$/ && /^[a-zA-Z0-9_]/ &&
|
|
|
|
! /^(?:static )?(?:typedef|struct|union)[^\(]*$/ &&
|
|
|
|
! /= *\{$/ && ! /;$/)) {
|
2005-09-30 03:07:55 +02:00
|
|
|
if (/.\{$/){
|
|
|
|
print "fn() {:$fn:$.\n";
|
|
|
|
$in_func_head = 0;
|
2005-09-30 03:39:24 +02:00
|
|
|
} elsif (/^\S[^\(]* +\**[a-zA-Z0-9_]+\(/) {
|
2005-09-30 03:07:55 +02:00
|
|
|
$in_func_head = -1; # started with tp fn
|
|
|
|
} elsif (/;$/) {
|
|
|
|
$in_func_head = 0;
|
|
|
|
} elsif (/\{/) {
|
|
|
|
if ($in_func_head == -1) {
|
|
|
|
print "tp fn():$fn:$.\n";
|
|
|
|
}
|
|
|
|
$in_func_head = 0;
|
|
|
|
}
|
|
|
|
}
|
2005-06-11 20:52:37 +02:00
|
|
|
}
|
2004-11-09 21:04:00 +01:00
|
|
|
}
|
2005-06-09 21:03:31 +02:00
|
|
|
if (! $lastnil) {
|
2005-06-09 18:46:51 +02:00
|
|
|
print " EOL\@EOF:$fn:$.\n";
|
|
|
|
}
|
2004-11-09 21:04:00 +01:00
|
|
|
close(F);
|
|
|
|
}
|