#!/usr/bin/perl -w
#
#  Gnumeric
#
#  Copyright (C) 2008 Morten Welinder.
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as
#  published by the Free Software Foundation; either version 2 of the
#  License, or (at your option) any later version.
#
#  This library is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this library; if not, see <https://www.gnu.org/licenses/>.
#
#  Author: Morten Welinder <terra@gnome.org>

use strict;

my $exitcode = 0;
my $verbose = 0;
my $strict = 0;

warn "$0: should be run from top-level directory.\n"
    unless -r "configure.ac" && -r 'ChangeLog';

my %base_exceptions =
    ();

my %exceptions =
    ();

{
    local (*FIND);
    open (*FIND, "find . '(' -type f -name '*.[ch]' -print ')' -o '(' -type d '(' -name intl -o -name macros -o -name .git -o -name win32 ')' -prune ')' |")
	or die "$0: cannot execute find: $!\n";
  FILE:
    foreach my $filename (<FIND>) {
	chomp $filename;
	$filename =~ s|^\./||;

	next if $exceptions{$filename};
	my $basename = $filename;
	$basename =~ s|^.*/||;
	next if $base_exceptions{$basename};

	local (*FIL);
	if (open (*FIL, "< $filename")) {
	    # print STDERR "Checking $filename...\n";
	    my $lineno = 0;
	    my @lines;
	  LINE:
	    while (<FIL>) {
		$lineno++;

		if (m'^\s*\#\s*include\s+(<gtk/gtk[a-z].*>)') {
		    $exitcode = 1;
		    print STDERR "$0: $filename includes $1\n";
		}
	    }
	    close (*FIL);
	} else {
	    print STDERR "$0: Cannot read `$filename': $!\b";
	    $exitcode = 1;
	}
    }
    close (*FIND);
}

exit $exitcode;
