summaryrefslogtreecommitdiff
path: root/source4/script/find_unused_macros.pl
blob: 697afcd1a99c218936831947cf79c1d2ee77855a (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
#!/usr/bin/perl
# Script that reads in configure and outputs the names of all the defines 
# it defines that are used nowhere in the code

# Arguments: C and H files
# Copyright Jelmer Vernooij <jelmer@samba.org>, GPL

use strict;

my %defined;
my %used;
my %files;

my $tmp;
while($tmp = shift) { 
	$files{$tmp} = $tmp;
	open(FI, $tmp);
	my $ln = 0;
	while(<FI>) { 
		$ln++;
		my $line = $_;
		my $cur = "";
		if(/^#define ([A-Za-z0-9_]+)/) {
			$defined{$1} = "$tmp:$ln";
			$cur = $1;
		}

		$_ = $line;
		while(/([A-Za-z0-9_]+)/sgm) { 
			if($cur ne $1) { $used{$1} = "$tmp:$ln"; }
		}
	}
	close FI;
}

foreach(keys %defined) {
	if(!$used{$_}) { print "$defined{$_}: Macro `$_' is unused\n"; }
}