chiark / gitweb /
Prep v239: path-util.[hc] - Masked path_simplify_and_warn() - Nowhere needed.
[elogind.git] / tools / check-includes.pl
1 #!/usr/bin/env perl
2 #
3 # checkincludes: Find files included more than once in (other) files.
4 # Copyright abandoned, 2000, Niels Kristian Bech Jensen <nkbj@image.dk>.
5
6 #if 0 // 5 errors and 2 warnings are inaccaptable for elogind - See PerlCritic.
7 # foreach $file (@ARGV) {
8 #       open(FILE, $file) or die "Cannot open $file: $!.\n";
9
10 #       my %includedfiles = ();
11
12 #       while (<FILE>) {
13 #               if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
14 #                       ++$includedfiles{$1};
15 #               }
16 #       }
17 #       foreach $filename (keys %includedfiles) {
18 #               if ($includedfiles{$filename} > 1) {
19 #                       print "$file: $filename is included more than once.\n";
20 #               }
21 #       }
22
23 #       close(FILE);
24 # }
25 #else
26 use strict;
27 use warnings;
28
29 foreach my $file (@ARGV) {
30         my %includedfiles = ();
31
32         open(my $FILE, "<", $file) or die "Cannot open $file: $!.\n";
33         while (<$FILE>) {
34                 if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
35                         ++$includedfiles{$1};
36                 }
37         }
38         close($FILE);
39
40         foreach my $filename (keys %includedfiles) {
41                 if ($includedfiles{$filename} > 1) {
42                         print "$file: $filename is included more than once.\n";
43                 }
44         }
45 }
46 #endif // 0