Introspection fixes
[gnumeric.git] / tools / check-trailing-commas
blob3ab41ccee2a6be0295e88958d29a25110151a9ba
1 #!/usr/bin/perl -w
3 # Gnumeric
5 # Copyright (C) 2001 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;
27 warn "$0: should be run from top-level directory.\n"
28 unless -r "configure.ac" && -r 'ChangeLog';
30 my %base_exceptions =
31 ();
33 my %exceptions =
34 ();
37 local (*FIND);
38 open (*FIND, "find . '(' -type f -name '*.[ch]' -print ')' -o '(' -type d '(' -name intl -o -name macros -o -name .git -o -name win32 ')' -prune ')' |")
39 or die "$0: cannot execute find: $!\n";
40 FILE:
41 foreach my $filename (<FIND>) {
42 chomp $filename;
43 $filename =~ s|^\./||;
45 next if $exceptions{$filename};
46 next if $filename =~ /\.glade\.h$/;
47 next if $filename =~ /\.xml\.h$/;
48 my $basename = $filename;
49 $basename =~ s|^.*/||;
50 next if $base_exceptions{$basename};
52 local (*FIL);
53 if (open (*FIL, "< $filename")) {
54 my $lineno = 0;
55 my $state = 0;
56 LINE:
57 while (<FIL>) {
58 $lineno++;
60 if ($state == 1 && /^\s*\}/) {
61 my $linenom1 = $lineno - 1;
62 print STDERR "$filename:$linenom1: Suspicious comma.\n";
65 if (/,\s*\}/) {
66 print STDERR "$filename:$lineno: Suspicious comma.\n";
67 $exitcode = 1;
70 if (/,\s*$/) {
71 $state = 1;
72 } else {
73 $state = 0;
76 close (*FIL);
77 } else {
78 print STDERR "$0: Cannot read `$filename': $!\b";
79 $exitcode = 1;
82 close (*FIND);
85 exit $exitcode;