123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- use strict;
- use File::Find;
- use Data::Dumper;
- use constant YELLOW => "\033[33m";
- use constant RED => "\033[31m";
- use constant CLEAR => "\033[0m";
- our %totals;
- find(\&test, "../../OpenSim");
- print Dumper(\%totals);
- sub test {
- my $file = $File::Find::name;
- my $dir = $File::Find::dir;
- $file =~ s{^../../}{};
- $dir =~ s{^../../}{};
-
- return if ($file !~ /\.cs$/);
- return if ($file =~ /AssemblyInfo\.cs$/);
- print "Processing File: $file\n";
- my $namespace = find_namespace($_);
- my $class = find_class($_);
-
- if(cmp_namespace($namespace, $dir) == 1) {
- $totals{goodns}++;
- } else {
- $totals{badns}++;
- }
-
- if(cmp_class($namespace, $class, $file) == 1) {
- $totals{goodclass}++;
- } else {
- $totals{badclass}++;
- }
- print "\n";
- }
- sub find_class {
- my $file = shift;
- my $content = slurp($file);
- if ($content =~ /\n\s*(public|private|protected)?\s*(class|interface)\s+(\S+)/) {
- return $3;
- }
- return "";
- }
- sub find_namespace {
- my $file = shift;
- my $content = slurp($file);
-
- if ($content =~ /\bnamespace\s+(\S+)/s) {
- return $1;
- }
- return "";
- }
- sub slurp {
- my $file = shift;
- local(*IN);
- local $/ = undef;
-
- open(IN, "$file") or die "Can't open '$file': $!";
- my $content = <IN>;
- close(IN);
-
- return $content;
- }
- sub cmp_class {
- my ($ns, $class, $file) = @_;
- $class = "$ns.$class";
- my $classtrans = $class;
- $classtrans =~ s{\.}{/}g;
- $classtrans .= ".cs";
-
- if($classtrans ne $file) {
- error(YELLOW, "CLASS: $class != $file");
- return -1;
- }
- return 1;
- }
- sub cmp_namespace {
- my ($ns, $dir) = @_;
- my $nstrans = $ns;
- $nstrans =~ s{\.}{/}g;
- if($nstrans ne $dir) {
- error(RED, "NS: $ns != $dir");
- return -1;
- }
- return 1;
- }
-
- sub error {
- print @_, CLEAR, "\n";
- }
|