Merge branch 'master' of github.com:OpenFOAM/OpenFOAM-2.0.x
[OpenFOAM-2.0.x.git] / doc / tools / find-suspiciousTags
blobe28550df4571f061a2c34c3b1a85df6a9cc8495f
1 #!/usr/bin/perl -w
2 use strict;
3 use File::Find ();
5 # -----------------------------------------------------------------------------
7 # Script
8 # find-suspiciousTags
10 # Description
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;
34 sub wanted {
35 unless ( lstat($_) and -f _ and -r _ and not -l _ and /$re_filespec/ ) {
36 return;
39 # potential className
40 ( my $fileClass = $_ ) =~ s{\.[A-Za-z]$}{};
42 my ( $namespace, $currentClass, %classes, %found ) = ('');
44 local @ARGV = $_;
45 while (<>) {
46 my $name;
48 ## look for (class|namespace), deal with repeats
49 if ( ($name) = /^\s*class\s+(\w+)\s*/ ) {
50 $classes{$name}++;
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*/) {
58 $found{$1}++;
60 ## examine the class name
61 if (/^Class\s*$/) {
62 $_ = <>;
63 my @trailing;
64 ( $currentClass, @trailing ) = split;
65 if (@trailing) {
66 $found{-trailing}++;
69 # the next line should be blank
70 $_ = <>;
71 $_ ||= '';
73 if (not /^\s*$/) {
74 $found{-spacing}++;
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";
90 if (%classes) {
91 ## we have 'Class' tag
92 if ( defined $currentClass ) {
93 if ($namespace) {
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";
110 else {
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 );