MUNIT: return right error for size 0<n<1.
[gnumeric.git] / tools / check-config-h.pl
blob024651269be6bc895fba6e4a89e62b30da7390d0
1 #!/usr/bin/perl -w
2 # -*- Mode: perl; indent-tabs-mode: nil -*-
5 # Nautilus
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.
29 use diagnostics;
30 use strict;
32 use Getopt::Long;
34 my $exitcode = 0;
35 my $configfile = &guess_config_file ();
36 my $configfileregexp = '[' . join ('][', split (//, $configfile)) . ']';
38 my %exceptions =
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
57 my $edit = 0;
58 my $verbose = 0;
59 &GetOptions("edit" => \$edit, 'verbose' => \$verbose);
61 # default to all the files starting from the current directory
62 if (!@ARGV) {
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
68 my @missing_files;
69 FILE: foreach my $file (@ARGV) {
70 next if $exceptions{$file};
72 print "Checking $file\n" if $verbose;
74 local (*FILE);
75 open FILE, "< $file" or die "can't open $file: $!\n";
76 while (<FILE>) {
77 next FILE if /generated by/i || /automatically generated/i;
78 next FILE if /^\s*\#\s*include\s*[<\"]$configfileregexp[>\"]/;
80 close FILE;
81 push @missing_files, $file;
84 if (@missing_files) {
85 print "\n", scalar (@missing_files), " C files don't have <$configfile> includes:\n\n";
86 if (!$edit) {
87 print join("\n", @missing_files), "\n";
88 $exitcode = 1;
89 } else {
90 foreach my $file (@missing_files) {
91 local (*OLD);
92 local (*NEW);
94 open OLD, "< $file" or die "can't open $file: $!\n";
95 open NEW, "> $file.new" or die "can't open $file.new: $!\n";
96 while (<OLD>) {
97 if (/^\s*\#\s*include\s*/) {
98 print NEW "$&<$configfile>\n";
99 print NEW;
100 last;
102 print NEW;
104 print NEW <OLD>;
105 close NEW;
106 close OLD;
107 rename "$file.new", $file or die "can't rename $file: $!\n";
108 print "Edited $file\n";
113 exit $exitcode;
115 # -----------------------------------------------------------------------------
117 sub guess_config_file {
118 local (*FIL);
119 $configfile = "config.h";
120 open (*FIL, "<configure.ac") || return $configfile;
121 while (<FIL>) {
122 if (/^AM_CONFIG_HEADER\((.*)\)/) {
123 $configfile = $1;
124 $configfile =~ s/^\[(.*)\]$/$1/;
125 } elsif (/^AC_CONFIG_HEADERS\((.*)\)/) {
126 $configfile = $1;
127 $configfile =~ s/^\[(.*)\]$/$1/;
128 last;
131 close (FIL);
132 return $configfile;
135 # -----------------------------------------------------------------------------