2 # -*- Mode: perl; indent-tabs-mode: nil -*-
7 # Copyright (C) 2000 Eazel, Inc.
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License as
11 # published by the Free Software Foundation; either version 2 of the
12 # License, or (at your option) any later version.
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this library; if not, see <https://www.gnu.org/licenses/>.
22 # Authors: Darin Adler <darin@eazel.com>
23 # Morten Welinder <terra@gnome.org>
26 # check-config-h.pl: Search for .c files where someone forgot to
27 # put an include for <gnumeric-config.h> in.
35 my $configfile = &guess_config_file
();
36 my $configfileregexp = '[' . join ('][', split (//, $configfile)) . ']';
39 ("./plugins/excel/crypt-md4.c" => 1, # Imported
40 "./plugins/excel/md5.c" => 1, # Imported
41 "./plugins/excel/rc4.c" => 1, # Imported
43 "./plugins/excel/xlsx-read-drawing.c" => 1, # Included
44 "./plugins/excel/xlsx-read-docprops.c" => 1, # Included
45 "./plugins/excel/xlsx-write-pivot.c" => 1, # Included
46 "./plugins/excel/xlsx-write-drawing.c" => 1, # Included
47 "./plugins/excel/xlsx-read-pivot.c" => 1, # Included
48 "./plugins/excel/xlsx-write-docprops.c" => 1, # Included
49 "./plugins/excel/biff-types.c" => 1, # Generated
51 "./plugins/perl-loader/xsinit.c" => 1, # Generated
53 "./tools/process-burkardt.c" => 1, # Not linked in
59 &GetOptions
("edit" => \
$edit, 'verbose' => \
$verbose);
61 # default to all the files starting from the current directory
63 @ARGV = `find . '(' -type d '(' -name intl -o -name macros -o -name .git -o -name win32 ')' -prune ')' -o '(' -name '*.c' -type f -print ')'`;
64 foreach (@ARGV) { chomp; }
67 # locate all of the target lines
69 FILE
: foreach my $file (@ARGV) {
70 next if $exceptions{$file};
72 print "Checking $file\n" if $verbose;
75 open FILE
, "< $file" or die "can't open $file: $!\n";
77 next FILE
if /generated by/i || /automatically generated/i;
78 next FILE
if /^\s*\#\s*include\s*[<\"]$configfileregexp[>\"]/;
81 push @missing_files, $file;
85 print "\n", scalar (@missing_files), " C files don't have <$configfile> includes:\n\n";
87 print join("\n", @missing_files), "\n";
90 foreach my $file (@missing_files) {
94 open OLD
, "< $file" or die "can't open $file: $!\n";
95 open NEW
, "> $file.new" or die "can't open $file.new: $!\n";
97 if (/^\s*\#\s*include\s*/) {
98 print NEW
"$&<$configfile>\n";
107 rename "$file.new", $file or die "can't rename $file: $!\n";
108 print "Edited $file\n";
115 # -----------------------------------------------------------------------------
117 sub guess_config_file
{
119 $configfile = "config.h";
120 open (*FIL
, "<configure.ac") || return $configfile;
122 if (/^AM_CONFIG_HEADER\((.*)\)/) {
124 $configfile =~ s/^\[(.*)\]$/$1/;
125 } elsif (/^AC_CONFIG_HEADERS\((.*)\)/) {
127 $configfile =~ s/^\[(.*)\]$/$1/;
135 # -----------------------------------------------------------------------------