Fix bug 44: on HUP, if descriptor building fails (say, because router_get_my_address...
[tor.git] / contrib / checkSpace.pl
blob8724250bc2e8ae3cf8bf7d207fcb683ca15fdfe8
1 #!/usr/bin/perl -w
3 for $fn (@ARGV) {
4 open(F, "$fn");
5 $lastnil = 0;
6 $incomment = 0;
7 while (<F>) {
8 ## Warn about windows-style newlines.
9 if (/\r/) {
10 print " CR:$fn:$.\n";
12 ## Warn about tabs.
13 if (/\t/) {
14 print " TAB:$fn:$.\n";
16 ## Warn about trailing whitespace.
17 if (/ +$/) {
18 print "Space\@EOL:$fn:$.\n";
20 ## Warn about control keywords without following space.
21 if (/\s(?:if|while|for|switch)\(/) {
22 print " KW(:$fn:$.\n";
24 ## Warn about multiple empty lines.
25 if ($lastnil && /^$/) {
26 print " DoubleNL:$fn:$.\n";
27 } elsif (/^$/) {
28 $lastnil = 1;
29 } else {
30 $lastnil = 0;
32 ### Juju to skip over comments and strings, since the tests
33 ### we're about to do are okay there.
34 if ($incomment) {
35 if (m!\*/!) {
36 s!.*?\*/!!;
37 $incomment = 0;
38 } else {
39 next;
42 if (m!/\*.*?\*/!) {
43 s!\s*/\*.*?\*/!!;
44 } elsif (m!/\*!) {
45 s!\s*/\*!!;
46 $incomment = 1;
47 next;
49 s!"(?:[^\"]+|\\.)*"!"X"!g;
50 next if /^\#/;
51 ## Warn about C++-style comments.
52 if (m!//!) {
53 # print " //:$fn:$.\n";
54 s!//.*!!;
56 ## Warn about braces preceded by non-space.
57 if (/([^\s])\{/) {
58 print " $1\{:$fn:$.\n";
60 ## Warn about multiple internal spaces.
61 #if (/[^\s,:]\s{2,}[^\s\\=]/) {
62 # print " X X:$fn:$.\n";
64 ## Warn about { with stuff after.
65 #s/\s+$//;
66 #if (/\{[^\}\\]+$/) {
67 # print " {X:$fn:$.\n";
69 ## Warn about function calls with space before parens.
70 if (/(\w+)\s\(/) {
71 if ($1 ne "if" and $1 ne "while" and $1 ne "for" and
72 $1 ne "switch" and $1 ne "return" and $1 ne "int" and
73 $1 ne "void" and $1 ne "__attribute__") {
74 print " fn ():$fn:$.\n";
78 close(F);