#!/usr/bin/perl

my $inenum = 0;
my $possibleenum = 0;
my %upper;
my %lower;
my %mixed;
my $upper = 0;
my $lower = 0;
my $mixed = 0;

my $verbose = 0;

while (<>) {
    if ($inenum) {
	if (/\}/) {
	    $inenum = 0;
	} elsif ($inenum == 2) {
	    next if /\s*\/?\*/;

	    if (/^\s*[A-Z0-9_]+(\s|,|=|$)/) {
		$upper++;
		$inenum = 1;
		$upper{$ARGV}++;
		print "$ARGV.$.: $_" if $verbose;
	    } elsif (/^\s*[a-z0-9_]+(\s|,|=|$)/) {
		$lower++;
		$inenum = 1;
		$lower{$ARGV}++;
		print "$ARGV.$.: $_" if $verbose
	    } elsif (/^\s*[A-Za-z0-9_]+(\s|,|=|$)/) {
		$mixed++;
		$inenum = 1;
		$mixed{$ARGV}++;
		print "$ARGV.$.: $_" if $verbose
	    }
	}
    } elsif ($possibleenum) {
	if (/\s*{/) {
	    $inenum = 2;
	}
	$possibleenum = 0;
    } else {
	if (/enum\s*(\w+\s*)?\{/) {
	    $inenum = 2;
	    if (/}/) {
		$inenum = 0;
	    }
	} elsif (/(^|\s)enum(\s|$)/) {
	    $possibleenum = 1;
	}
    }
}

my $upperfiles= int(keys %upper);
my $lowerfiles= int(keys %lower);
my $mixedfiles= int(keys %mixed);

print "Enum member naming\n";
if ($upper) {
    print "  Uppercase: $upper in $upperfiles files\n";
}
if ($lower) {
    print "  Lowercase: $lower in $lowerfiles files\n";
}
if ($mixed) {
    print "  Mixedcase: $mixed in $mixedfiles files\n";
}
if (!$upper && !$lower && !$mixed) {
    print "  None\n";
}
