fix the links in the exit-list notice we give out to users.
[tor/rransom.git] / contrib / checkSpace.pl
blob37f079c52b0f4f5039b3a90a6a73d2f6feb7106c
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 $lastline = "";
13 $incomment = 0;
14 while (<F>) {
15 ## Warn about windows-style newlines.
16 if (/\r/) {
17 print " CR:$fn:$.\n";
19 ## Warn about tabs.
20 if (/\t/) {
21 print " TAB:$fn:$.\n";
23 ## Warn about trailing whitespace.
24 if (/ +$/) {
25 print "Space\@EOL:$fn:$.\n";
27 ## Warn about control keywords without following space.
28 if ($C && /\s(?:if|while|for|switch)\(/) {
29 print " KW(:$fn:$.\n";
31 ## Warn about #else #if instead of #elif.
32 if (($lastline =~ /^\# *else/) and ($_ =~ /^\# *if/)) {
33 print " #else#if:$fn:$.\n";
35 $lastline = $_;
36 ## Warn about multiple empty lines.
37 if ($lastnil && /^$/) {
38 print " DoubleNL:$fn:$.\n";
39 } elsif (/^$/) {
40 $lastnil = 1;
41 } else {
42 $lastnil = 0;
44 ## Terminals are still 80 columns wide in my world. I refuse to
45 ## accept double-line lines. Except, of course, svn Id tags
46 ## can make us go long.
47 if (/^.{80}/ && !/\$Id: /) {
48 print " Wide:$fn:$.\n";
50 ### Juju to skip over comments and strings, since the tests
51 ### we're about to do are okay there.
52 if ($C) {
53 if ($incomment) {
54 if (m!\*/!) {
55 s!.*?\*/!!;
56 $incomment = 0;
57 } else {
58 next;
61 if (m!/\*.*?\*/!) {
62 s!\s*/\*.*?\*/!!;
63 } elsif (m!/\*!) {
64 s!\s*/\*!!;
65 $incomment = 1;
66 next;
68 s!"(?:[^\"]+|\\.)*"!"X"!g;
69 next if /^\#/;
70 ## Warn about C++-style comments.
71 if (m!//!) {
72 # print " //:$fn:$.\n";
73 s!//.*!!;
75 ## Warn about unquoted braces preceded by non-space.
76 if (/([^\s'])\{/) {
77 print " $1\{:$fn:$.\n";
79 ## Warn about multiple internal spaces.
80 #if (/[^\s,:]\s{2,}[^\s\\=]/) {
81 # print " X X:$fn:$.\n";
83 ## Warn about { with stuff after.
84 #s/\s+$//;
85 #if (/\{[^\}\\]+$/) {
86 # print " {X:$fn:$.\n";
88 ## Warn about function calls with space before parens.
89 if (/(\w+)\s\(([A-Z]*)/) {
90 if ($1 ne "if" and $1 ne "while" and $1 ne "for" and
91 $1 ne "switch" and $1 ne "return" and $1 ne "int" and
92 $1 ne "elsif" and $1 ne "WINAPI" and $2 ne "WINAPI" and
93 $1 ne "void" and $1 ne "__attribute__") {
94 print " fn ():$fn:$.\n";
97 ## Warn about functions not declared at start of line.
98 if ($in_func_head ||
99 ($fn !~ /\.h$/ && /^[a-zA-Z0-9_]/ &&
100 ! /^(?:const |static )*(?:typedef|struct|union)[^\(]*$/ &&
101 ! /= *\{$/ && ! /;$/)) {
102 if (/.\{$/){
103 print "fn() {:$fn:$.\n";
104 $in_func_head = 0;
105 } elsif (/^\S[^\(]* +\**[a-zA-Z0-9_]+\(/) {
106 $in_func_head = -1; # started with tp fn
107 } elsif (/;$/) {
108 $in_func_head = 0;
109 } elsif (/\{/) {
110 if ($in_func_head == -1) {
111 print "tp fn():$fn:$.\n";
113 $in_func_head = 0;
118 if (! $lastnil) {
119 print " EOL\@EOF:$fn:$.\n";
121 close(F);