Avoid spurious re-launch of first pending requested descriptor
[tor.git] / contrib / checkSpace.pl
blobe0b9d6b93bb53f21c7d666fab5058ca741ac03f7
1 #!/usr/bin/perl -w
3 if ($ARGV[0] =~ /^-/) {
4 $lang = shift @ARGV;
5 $C = ($lang eq '-C');
6 # $TXT = ($lang eq '-txt');
9 for $fn (@ARGV) {
10 open(F, "$fn");
11 $lastnil = 0;
12 $incomment = 0;
13 while (<F>) {
14 ## Warn about windows-style newlines.
15 if (/\r/) {
16 print " CR:$fn:$.\n";
18 ## Warn about tabs.
19 if (/\t/) {
20 print " TAB:$fn:$.\n";
22 ## Warn about trailing whitespace.
23 if (/ +$/) {
24 print "Space\@EOL:$fn:$.\n";
26 ## Warn about control keywords without following space.
27 if ($C && /\s(?:if|while|for|switch)\(/) {
28 print " KW(:$fn:$.\n";
30 ## Warn about multiple empty lines.
31 if ($lastnil && /^$/) {
32 print " DoubleNL:$fn:$.\n";
33 } elsif (/^$/) {
34 $lastnil = 1;
35 } else {
36 $lastnil = 0;
38 ### Juju to skip over comments and strings, since the tests
39 ### we're about to do are okay there.
40 if ($C) {
41 if ($incomment) {
42 if (m!\*/!) {
43 s!.*?\*/!!;
44 $incomment = 0;
45 } else {
46 next;
49 if (m!/\*.*?\*/!) {
50 s!\s*/\*.*?\*/!!;
51 } elsif (m!/\*!) {
52 s!\s*/\*!!;
53 $incomment = 1;
54 next;
56 s!"(?:[^\"]+|\\.)*"!"X"!g;
57 next if /^\#/;
58 ## Warn about C++-style comments.
59 if (m!//!) {
60 # print " //:$fn:$.\n";
61 s!//.*!!;
63 ## Warn about braces preceded by non-space.
64 if (/([^\s])\{/) {
65 print " $1\{:$fn:$.\n";
67 ## Warn about multiple internal spaces.
68 #if (/[^\s,:]\s{2,}[^\s\\=]/) {
69 # print " X X:$fn:$.\n";
71 ## Warn about { with stuff after.
72 #s/\s+$//;
73 #if (/\{[^\}\\]+$/) {
74 # print " {X:$fn:$.\n";
76 ## Warn about function calls with space before parens.
77 if (/(\w+)\s\(/) {
78 if ($1 ne "if" and $1 ne "while" and $1 ne "for" and
79 $1 ne "switch" and $1 ne "return" and $1 ne "int" and
80 $1 ne "void" and $1 ne "__attribute__") {
81 print " fn ():$fn:$.\n";
84 ## Warn about functions not declared at start of line.
85 if ($in_func_head ||
86 ($fn !~ /\.h$/ && /^[a-zA-Z0-9_]/ &&
87 ! /^(?:static )?(?:typedef|struct|union)[^\(]*$/ &&
88 ! /= *\{$/ && ! /;$/)) {
90 if (/.\{$/){
91 print "fn() {:$fn:$.\n";
92 $in_func_head = 0;
93 } elsif (/^\S[^\(]* +\**[a-zA-Z0-9_]+\(/) {
94 $in_func_head = -1; # started with tp fn
95 } elsif (/;$/) {
96 $in_func_head = 0;
97 } elsif (/\{/) {
98 if ($in_func_head == -1) {
99 print "tp fn():$fn:$.\n";
101 $in_func_head = 0;
106 if (! $lastnil) {
107 print " EOL\@EOF:$fn:$.\n";
109 close(F);