#!/usr/bin/perl

use File::Find;
use strict;

# not bool, false, true, 
my @keywords = qw (
asm         dynamic_cast  namespace  reinterpret_cast  try
explicit      new        static_cast       typeid
catch       operator   template          typename
class       friend        private    this              using
const_cast  inline        public     throw             virtual
delete      mutable       protected  wchar_t
and      bitand   compl   not_eq   or_eq   xor_eq
and_eq   bitor    not     or       xor
);

my @files;
my $wanted = sub 
{
	push(@files,$File::Find::name) if $File::Find::name =~ /\.h$/ && -f $_;
};

File::Find::find({wanted=>$wanted},"src");

my $regex_str = '\b(' . join('|',@keywords) . ')\b';
my $regex = qr/$regex_str/;

foreach my $file(@files)
{
	local $/ = undef;
	open (my $handle, $file) || die "opening $file: $!";
	my $contents = <$handle>;
	close($handle);
	# knock out comments, DATA lines and quoted strings
	$contents =~ s!/\*.*?\*/!!gs;
	$contents =~ s/^DATA.*\n$//mg;
	$contents =~ s/".*?"//sg;
	# get a list of unique keywords found per file 
	my @found_kw = ($contents =~ /$regex/g);
	my %found_map = map {$_ => 1} @found_kw;
	# show list if any found
	if (@found_kw)
	{
		print "found ",join(', ', keys %found_map)," in $file\n";
	}		  
}
