Introspection fixes
[gnumeric.git] / tools / check-gfrees
blobedf3a88e5f462456c1d87ae4cd109f6aa1b8152c
1 #!/usr/bin/perl -w
3 # Gnumeric
5 # Copyright (C) 2006 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 use strict;
24 my $exitcode = 0;
25 my $verbose = 0;
26 my $strict = 0;
28 warn "$0: should be run from top-level directory.\n"
29 unless -r "configure.ac" && -r 'ChangeLog';
31 my %base_exceptions =
32 ();
34 my %exceptions =
35 ();
38 local (*FIND);
39 open (*FIND, "find . '(' -type f -name '*.c' -print ')' -o '(' -type d '(' -name intl -o -name macros -o -name .git -o -name win32 ')' -prune ')' |")
40 or die "$0: cannot execute find: $!\n";
41 FILE:
42 foreach my $filename (<FIND>) {
43 chomp $filename;
44 $filename =~ s|^\./||;
46 next if $exceptions{$filename};
47 my $basename = $filename;
48 $basename =~ s|^.*/||;
49 next if $base_exceptions{$basename};
51 local (*FIL);
52 if (open (*FIL, "< $filename")) {
53 # print STDERR "Checking $filename...\n";
54 my $lineno = 0;
55 my @lines;
56 LINE:
57 while (<FIL>) {
58 $lineno++;
60 push @lines, $_;
62 if ($lineno >= 2 &&
63 ($lines[-2] . $lines[-1]) =~
64 /^\s*if\s*\(\s*(NULL\s*!=\s*)?([^ ()]+)\s*(!=\s*NULL\s*)?\)\s*(g_free|g_list_free|g_slist_free|go_list_free_custom|go_slist_free_custom|go_format_unref|value_release)\s*\(\s*\2\s*\)\s*;/) {
65 print STDERR "$0: Checked $4 at $filename:$lineno\n";
66 next LINE;
69 if ($lineno >= 4 &&
70 ($lines[-4] . $lines[-3] . $lines[-2] . $lines[-1] ) =~
71 /^\s*if\s*\(\s*(NULL\s*!=\s*)?([^ ()]+)\s*(!=\s*NULL\s*)?\)\s*{\s*(g_free|g_list_free|g_slist_free|go_list_free_custom|go_slist_free_custom|go_format_unref|value_release)\s*\(\s*\2\s*\)\s*;\s*\2\s*=\s*(0|NULL)\s*;\s*}/) {
72 print STDERR "$0: Checked $4 at $filename:$lineno\n";
73 next LINE;
76 if ($lineno >= 3 &&
77 ($lines[-3] . $lines[-2] . $lines[-1]) =~
78 /^[^\n]*([^ ()]+)(\s*!=\s*NULL)?\s*\?\s*(g_strdup|value_dup)\s*\(\s*\1\s*\)\s*:\s*NULL/) {
79 print STDERR "$0: Checked $3 at $filename:$lineno\n";
80 next LINE;
83 if ($lineno >= 3 &&
84 ($lines[-3] . $lines[-2] . $lines[-1]) =~
85 /^[^\n]*(\s*NULL\s*!=\s*)([^ ()]+)\s*\?\s*(g_strdup|value_dup)\s*\(\s*\2\s*\)\s*:\s*NULL/) {
86 print STDERR "$0: Checked $3 at $filename:$lineno\n";
87 next LINE;
90 close (*FIL);
91 } else {
92 print STDERR "$0: Cannot read `$filename': $!\b";
93 $exitcode = 1;
96 close (*FIND);
99 exit $exitcode;