2008-05-05 Paolo Borelli <pborelli@katamail.com>
[nautilus.git] / check-config-h.pl
blobe4668203a968f435bf8a908523bd688a2af54931
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, 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.
29 use diagnostics;
30 use strict;
32 use Getopt::Long;
34 my $edit = 0;
35 &GetOptions("edit" => \$edit);
37 # default to all the files starting from the current directory
38 if (!@ARGV)
40 @ARGV = `find . -name '*.c' -print`;
43 # locate all of the target lines
44 my @missing_files;
45 FILE: foreach my $file (@ARGV)
47 chomp $file;
48 open FILE, $file or die "can't open $file";
49 while (<FILE>)
51 next FILE if /generated by/;
52 next FILE if /^\s*\#\s*include\s*[<\"]config\.h[>\"]/;
54 close FILE;
55 push @missing_files, $file;
58 if (@missing_files)
60 print "\n", scalar(@missing_files), " C files don't have <config.h> includes:\n\n";
61 if (!$edit)
63 print join("\n", @missing_files), "\n";
65 else
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";
71 while (<OLD>)
73 if (/^\s*\#\s*include\s/)
75 print NEW "$&<config.h>\n";
76 print NEW;
77 last;
79 print NEW;
81 print NEW <OLD>;
82 close NEW;
83 close OLD;
84 rename "$file.new", $file or die "can't rename $file";
85 print "edited $file\n";