summaryrefslogtreecommitdiff
path: root/common/tools/check-filename
blob: 379bdac2fb5ffc8a9e84495460ed7790ce264bcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/perl
#
# Check that header guard defines and doxygen \file command are set
# appropriately.
#
use strict;
use warnings;
use File::Find;

-f 'common/tools/check-filename'
    or die "should be run from base root\n";

if ($ENV{'VIM'})
{
    print "nmap <buffer> <space> yy<cr>pkdd^df\"f\"D\n";
    print "nmap <C-N> :copen<cr>j<space>\n";
}

sub check_file
{
    my $file = shift;
    $file =~ s#^\./##;
    my $cc = $file =~ /\.[ch]\{2\}$/;
    my $filep;
    ($filep = $file) =~ s#[/.]#_#g;
    print "check $file\n";
    open FILE, "<$file";
    while (<FILE>)
    {
	chomp;
	/^#(ifndef|define) (.*_h)$/ && $2 ne $filep
	    and print "$file:$.: should be \"#$1 $filep\"\n";
	/^#(endif \/\*) (.*_h)( \*\/)$/ && $2 ne $filep
	    and print "$file:$.: should be \"#$1 $filep$3\"\n";
	m#^((?:///| \*) \\file) +(.*)$# && $2 ne $file
	    and print "$file:$.: should be \"$1    $file\"\n";
    }
    close FILE;
}

my %exclude;
@exclude{'ecos', 'obj', '.svn', 'html', 'test'} = ();

@ARGV = ('.') if !@ARGV;

for (@ARGV)
{
    if (-d $_)
    {
	find ({ no_chdir => 1, wanted => sub {
	    my $f = $_;
	    $f =~ s#.*/##;
	    exists $exclude{$f}
		and $File::Find::prune = 1
		or /\.[ch]+$/ and check_file $_;
	} }, $_);
    }
    elsif (-f $_)
    {
	check_file ($_);
    }
    else
    {
	die "$_: not a directory, nor a file, what should I do?\n";
    }
}