summaryrefslogtreecommitdiff
path: root/pkgtools/pkglint/files/plist-clash.pl
blob: 4e3b70ba06d7d02ff7a897590eeab0270e60f4f3 (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
#! @PERL@
# $NetBSD: plist-clash.pl,v 1.5 2005/11/10 14:30:56 rillig Exp $
#
# Scan all PLIST files given on the command line and report all lines
# that appear more than once.

my %files = ();

sub read_PLIST($) {
	my ($fname) = @_;

	if (!open(F, "<", $fname)) {
		warn "$!\n";
		return undef;
	}

	my $lineno = 0;
	foreach my $line (<F>) {
		chomp($line);
		$lineno++;

		# Ignore comments and commands
		next if ($line =~ qr"^@");

		# Ignore filenames with embedded variables
		next if ($line =~ qr"\$");
		
		if ($line =~ qr"^[A-Za-z0-9].*") {
			if (!exists($files{$line})) {
				$files{$line} = [];
			}
			push(@{$files{$line}}, "$fname:$lineno");

		} else {
			warn("ERROR: $fname:$lineno: Unknown line type\n");
		}
	}
	close(F);
}

sub main() {
	if (@ARGV == 0) {
		die("usage: $0 <plist>...\n");
	}

	foreach my $plist (@ARGV) {
		read_PLIST($plist);
	}

	foreach my $file (sort keys %files) {
		my $srcs = $files{$file};
		if (@{$srcs} != 1) {
			foreach my $src (@{$srcs}) {
				print "$src: $file\n";
			}
		}
	}
}

main();