5 # -----------------------------------------------------------------------------
11 # Search for *.[CH] files with 'Class' or 'Namespace' starting in the
12 # first column but without a class being defined anywhere in the file.
13 # These are probably incorrect or should be at least be
14 # changed to 'In Class' / 'In Namespace' for now.
15 # - print filename and 'InClass' or 'InNamespace'
17 # Find the namespaces used in the files and compare these to what is
18 # given on the 'Class' information
19 # - print filename and corrected Class
21 # Check for trailing garbage in the 'Class' information
22 # - print filename and 'ClassWithTrailingInformation'
24 # -----------------------------------------------------------------------------
26 my $re_filespec = qr{^.+\.[CH]$};
28 # for the convenience of &wanted calls, including -eval statements:
29 ## use vars qw( *name *dir *prune );
30 ## *name = *File::Find::name;
31 ## *dir = *File::Find::dir;
32 ## *prune = *File::Find::prune;
35 unless ( lstat($_) and -f _
and -r _
and not -l _
and /$re_filespec/ ) {
40 ( my $fileClass = $_ ) =~ s{\.[A-Za-z]$}{};
42 my ( $namespace, $currentClass, %classes, %found ) = ('');
48 ## look for (class|namespace), deal with repeats
49 if ( ($name) = /^\s*class\s+(\w+)\s*/ ) {
52 elsif ( ($name) = /^\s*namespace\s+(\w+)\s*/ ) {
53 ## reset if 'Foam' namespace appears again
54 $namespace = '' if $name eq "Foam";
55 $namespace .= $name . "::";
57 elsif (/^(Class|Namespace)\s*/) {
60 ## examine the class name
64 ( $currentClass, @trailing ) = split;
69 # the next line should be blank
80 # always report if the Class has trailing information
81 if ( delete $found{-trailing
} ) {
82 print "$File::Find::name ClassWithTrailingInformation\n";
85 # always report if the Class has spacing problem
86 if ( delete $found{-spacing
} ) {
87 print "$File::Find::name ClassWithSpacingIssue\n";
91 ## we have 'Class' tag
92 if ( defined $currentClass ) {
94 my ($currentNamespace) = $currentClass =~ m{^(.+::)};
95 $currentNamespace ||= '';
97 if ( $namespace ne $currentNamespace ) {
98 $currentClass =~ s{^(.+::)}{};
99 $currentClass ||= $fileClass;
101 print "$File::Find::name $namespace$currentClass\n";
104 elsif ( not $currentClass ) {
105 ## supply a class name
106 print "$File::Find::name $fileClass\n";
111 ## no classes, all tags are deemed suspicious
112 for ( sort keys %found ) {
113 print "$File::Find::name In$_\n";
118 ## Traverse desired filesystems
119 for my $dir (@ARGV) {
120 no warnings
'File::Find';
121 warn "(**) checking '$dir' ...\n";
122 File
::Find
::find
( { wanted
=> \
&wanted
}, $dir );