summaryrefslogtreecommitdiffstats
path: root/debian/tests/find_unused_functions
diff options
context:
space:
mode:
Diffstat (limited to 'debian/tests/find_unused_functions')
-rwxr-xr-xdebian/tests/find_unused_functions30
1 files changed, 30 insertions, 0 deletions
diff --git a/debian/tests/find_unused_functions b/debian/tests/find_unused_functions
new file mode 100755
index 0000000..bd31d45
--- /dev/null
+++ b/debian/tests/find_unused_functions
@@ -0,0 +1,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;
+}