Czech translation
[gnumeric.git] / tools / check-gfrees
blob69a5e2e367239c6604495954e684300a6f57e7bf
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, write to the Free Software
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 # Author: Morten Welinder <terra@gnome.org>
23 use strict;
25 my $exitcode = 0;
26 my $verbose = 0;
27 my $strict = 0;
29 warn "$0: should be run from top-level directory.\n"
30 unless -r "configure.ac" && -r 'ChangeLog';
32 my %base_exceptions =
33 ();
35 my %exceptions =
36 ();
39 local (*FIND);
40 open (*FIND, "find . '(' -type f -name '*.c' -print ')' -o '(' -type d '(' -name CVS -o -name intl -o -name macros -o -name .git -o -name win32 ')' -prune ')' |")
41 or die "$0: cannot execute find: $!\n";
42 FILE:
43 foreach my $filename (<FIND>) {
44 chomp $filename;
45 $filename =~ s|^\./||;
47 next if $exceptions{$filename};
48 my $basename = $filename;
49 $basename =~ s|^.*/||;
50 next if $base_exceptions{$basename};
52 local (*FIL);
53 if (open (*FIL, "< $filename")) {
54 # print STDERR "Checking $filename...\n";
55 my $lineno = 0;
56 my @lines;
57 LINE:
58 while (<FIL>) {
59 $lineno++;
61 push @lines, $_;
63 if ($lineno >= 2 &&
64 ($lines[-2] . $lines[-1]) =~
65 /^\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*;/) {
66 print STDERR "$0: Checked $4 at $filename:$lineno\n";
67 next LINE;
70 if ($lineno >= 4 &&
71 ($lines[-4] . $lines[-3] . $lines[-2] . $lines[-1] ) =~
72 /^\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*}/) {
73 print STDERR "$0: Checked $4 at $filename:$lineno\n";
74 next LINE;
77 if ($lineno >= 3 &&
78 ($lines[-3] . $lines[-2] . $lines[-1]) =~
79 /^[^\n]*([^ ()]+)(\s*!=\s*NULL)?\s*\?\s*(g_strdup|value_dup)\s*\(\s*\1\s*\)\s*:\s*NULL/) {
80 print STDERR "$0: Checked $3 at $filename:$lineno\n";
81 next LINE;
84 if ($lineno >= 3 &&
85 ($lines[-3] . $lines[-2] . $lines[-1]) =~
86 /^[^\n]*(\s*NULL\s*!=\s*)([^ ()]+)\s*\?\s*(g_strdup|value_dup)\s*\(\s*\2\s*\)\s*:\s*NULL/) {
87 print STDERR "$0: Checked $3 at $filename:$lineno\n";
88 next LINE;
91 close (*FIL);
92 } else {
93 print STDERR "$0: Cannot read `$filename': $!\b";
94 $exitcode = 1;
97 close (*FIND);
100 exit $exitcode;