.gnumeric: For clipboards, send also result values.
[gnumeric.git] / tools / check-unreferenced
blobccf45aaa87f963325ab0c691df1d6132dd55f289
1 #!/usr/bin/perl -w
3 # Gnumeric
5 # Copyright (C) 2011 Morten Welinder.
7 # This program is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU General Public License as
9 # published by the Free Software Foundation; either version 2 of the
10 # License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this library; if not, see <https://www.gnu.org/licenses/>.
20 # Author: Morten Welinder <terra@gnome.org>
22 # NOTES:
23 # 1. This depends heavily on nm's output format.
24 # 2. We search for .o files. Things should be freshly compiled and there
25 # should be no old ones lying around.
26 # 3. Symbols used within the file that holds their definition might be
27 # shown as not used at all.
29 use strict;
31 my $exitcode = 0;
33 die "$0: must be run from top-level directory.\n"
34 unless (-r "configure.ac" &&
35 -r 'ChangeLog' &&
36 -d 'src');
38 my %base_exceptions =
39 ();
41 my %exceptions =
42 ();
44 my $DEFINED = 1;
45 my $USED = 2;
47 my %symbols = ('main' => $USED);
49 &read_object_files ("src", 0);
50 &read_object_files ("plugins", 1);
51 &read_object_files ("component", 1);
53 foreach my $sym (sort keys %symbols) {
54 my $info = $symbols{$sym};
55 if (($info & ($DEFINED|$USED)) == $DEFINED) {
56 print STDERR "$sym -- defined, but not used.\n";
60 exit $exitcode;
62 sub read_object_files {
63 my ($dir,$ignore_definitions) = @_;
65 local (*FIND);
66 open (*FIND, "find $dir '(' -type f -name '*.o' -print ')' -o '(' -type d '(' -name intl -o -name macros -o -name .git -o -name win32 ')' -prune ')' |")
67 or die "$0: cannot execute find: $!\n";
68 FILE:
69 foreach my $filename (<FIND>) {
70 chomp $filename;
71 $filename =~ s|^\./||;
73 next if $exceptions{$filename};
74 my $basename = $filename;
75 $basename =~ s|^.*/||;
76 next if $base_exceptions{$basename};
78 local (*NM);
79 open (*NM, "nm $filename |")
80 or die "$0: cannot execute nm: $1\n";
81 foreach my $line (<NM>) {
82 chomp $line;
83 if ($line =~ /^\S+\s+T\s+(\S+)$/) {
84 $symbols{$1} |= $DEFINED
85 unless $ignore_definitions;
86 } elsif ($line =~ /^\s+U\s+(\S+)$/) {
87 $symbols{$1} |= $USED;
90 close (*NM);
92 close (*FIND);