bfb35cfda11d529f02c698e87ae298309a776305Karel Zak#!/usr/bin/perl
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak#
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak# checkincludes: Find files included more than once in (other) files.
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak# Copyright abandoned, 2000, Niels Kristian Bech Jensen <nkbj@image.dk>.
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak
bfb35cfda11d529f02c698e87ae298309a776305Karel Zakforeach $file (@ARGV) {
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak open(FILE, $file) or die "Cannot open $file: $!.\n";
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak my %includedfiles = ();
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak while (<FILE>) {
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak ++$includedfiles{$1};
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak }
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak }
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak foreach $filename (keys %includedfiles) {
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak if ($includedfiles{$filename} > 1) {
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak print "$file: $filename is included more than once.\n";
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak }
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak }
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak close(FILE);
bfb35cfda11d529f02c698e87ae298309a776305Karel Zak}