ftp://ftp.redhat.com/pub/redhat/linux/rawhide/SRPMS/SRPMS/gnome-vfs2-2.3.8-1.src.rpm
[gnome-vfs-httpcaptive.git] / libgnomevfs / check-headers.pl
1 #!/usr/bin/perl -w
2 # -*- Mode: perl; indent-tabs-mode: nil -*-
3
4 use diagnostics;
5 use strict;
6
7 my $DEBUG = 0;
8
9 my %public_headers;
10 my %module_headers;
11 my %private_headers;
12
13 my $current_hash;
14 my $current_hash_name;
15
16 my $current_header;
17 my $included_header;
18
19 my $exit_code = 0;
20
21 open MAKEFILE_AM, "<./Makefile.am";
22
23 while (<MAKEFILE_AM>) {
24     if (/libgnomevfsinclude_HEADERS/) {
25         $current_hash = \%public_headers
26     } elsif (/libgnomevfsmoduleinclude_HEADERS/) {
27         $current_hash = \%module_headers
28     } elsif (/noinst_HEADERS/) {
29         $current_hash = \%private_headers
30     } elsif (/\$\(NULL\)/ || ! /\\/) {
31         $current_hash = 0;
32     }
33
34     if (/.*\.h[ \t]/) {
35         chomp;
36         $current_header = $_;
37         $current_header =~ s/[ \t]*(.*\.h)[ \t]*.*/$1/;
38         
39         if ($current_hash) {
40             $$current_hash{$current_header} = 1;
41         }
42     }
43 }
44
45 close MAKEFILE_AM;
46
47 for my $public_header (keys %public_headers) {
48     open HEADER, "<${public_header}";
49     while (<HEADER>) {
50         if (/\#include[ \t]+<libgnomevfs\/.*\.h>.*/) {
51             chomp;
52             $included_header = $_;
53             $included_header =~ s/\#include[ \t]+<libgnomevfs\/(.*\.h)>.*/$1/;
54
55             if ($private_headers{$included_header}) {
56                 print "Public header \"$public_header\" includes private header \"$included_header\"\n";
57                 $exit_code = 1;
58             } elsif ($module_headers{$included_header}) {
59                 print "Public header \"$public_header\" includes module API header \"$included_header\"\n";
60                 $exit_code = 1;
61             } elsif ($public_headers{$included_header}) {
62                 print "Public header \"$public_header\" includes public header \"$included_header\"\n" if $DEBUG;
63             } else {
64                 print "Public header \"$public_header\" includes unknown header \"$included_header\"\n";
65                 $exit_code = 1;
66             }
67         }
68     }
69     close HEADER;
70 }
71
72
73 for my $module_header (keys %module_headers) {
74     open HEADER, "<${module_header}";
75
76     while (<HEADER>) {
77         if (/\#include[ \t]+<libgnomevfs\/.*\.h>.*/) {
78             chomp;
79             $included_header = $_;
80             $included_header =~ s/\#include[ \t]+<libgnomevfs\/(.*\.h)>.*/$1/;
81
82             if ($private_headers{$included_header}) {
83                 print "Module API header \"$module_header\" includes private header \"$included_header\"\n";
84                 $exit_code = 1;
85             } elsif ($module_headers{$included_header}) {
86                 print "Module API header \"$module_header\" includes public header \"$included_header\"\n" if $DEBUG;
87             } elsif ($public_headers{$included_header}) {
88                 print "Module API header \"$module_header\" includes public header \"$included_header\"\n" if $DEBUG;
89             } else {
90                 print "Module API header \"$module_header\" includes unknown header \"$included_header\"\n";
91                 $exit_code = 1;
92             }
93         }
94     }
95     close HEADER;
96 }
97
98
99 for my $private_header (keys %private_headers) {
100     open HEADER, "<${private_header}";
101
102     while (<HEADER>) {
103         if (/\#include[ \t]+<libgnomevfs\/.*\.h>.*/) {
104             chomp;
105             $included_header = $_;
106             $included_header =~ s/\#include[ \t]+<libgnomevfs\/(.*\.h)>.*/$1/;
107
108             if ($private_headers{$included_header}) {
109                 print "Private header \"$private_header\" includes private header \"$included_header\"\n" if $DEBUG;
110             } elsif ($module_headers{$included_header}) {
111                 print "Private header \"$private_header\" includes module API header \"$included_header\"\n" if $DEBUG;
112             } elsif ($public_headers{$included_header}) {
113                 print "Private header \"$private_header\" includes public header \"$included_header\"\n" if $DEBUG;
114             } else {
115                 print "Private header \"$private_header\" includes unknown header \"$included_header\"\n";
116                 $exit_code = 1;
117             }
118         }
119     }
120     close HEADER;
121 }
122
123 exit $exit_code;