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, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 # Author: Darin Adler <darin@bentspoon.com>,
26 # check-config-h.pl: Search for .c files where someone forgot to
27 # put an include for <config.h> in.
35 &GetOptions
("edit" => \
$edit);
37 # default to all the files starting from the current directory
40 @ARGV = `find . -name '*.c' -print`;
43 # locate all of the target lines
45 FILE
: foreach my $file (@ARGV)
48 open FILE
, $file or die "can't open $file";
51 next FILE
if /generated by/;
52 next FILE
if /^\s*\#\s*include\s*[<\"]config\.h[>\"]/;
55 push @missing_files, $file;
60 print "\n", scalar(@missing_files), " C files don't have <config.h> includes:\n\n";
63 print join("\n", @missing_files), "\n";
67 foreach my $file (@missing_files)
69 open OLD
, $file or die "can't open $file";
70 open NEW
, "> $file.new" or die "can't open $file.new";
73 if (/^\s*\#\s*include\s/)
75 print NEW
"$&<config.h>\n";
84 rename "$file.new", $file or die "can't rename $file";
85 print "edited $file\n";