summaryrefslogtreecommitdiffstats
path: root/debian/tests/find_unused_functions
blob: bd31d453c1ee8253794d24a45a6e98d631b33a1f (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
#! /usr/bin/perl -w

use autouse Data::Dumper, qw{Dumper};

# Script to find the unused shell functions in slapd.scripts-common

our @code;

# Get all shell code from maintainer scripts

foreach my $file ((<slapd.*rm>, <slapd.*inst>, <slapd.config>, 
	<slapd.scripts-common>)) {
	open SCRIPT, "<$file" or
		die "Can't open $file: $!";
	push @code, <SCRIPT>;
	close SCRIPT;
}

# Find all function declarations

our @functions = map { /^(\w+)\s*\(\).*$/;  } @code;

# Find unused functions

foreach $function (@functions) {
	@occurences  = grep /$function/, @code;
	@invocations = grep { !/^$function\s*\(\)/ and !/#.*$function/ }
				@occurences;
	print "$function\n" if @invocations == 0;
}