summaryrefslogtreecommitdiffstats
path: root/scripts/check_licenses
blob: 6accd259c16b8774f3b9a071b9280f8e9e3d123e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/perl -w

unless (scalar(@ARGV) == 1)
{
  die "Usage: check_licenses directory";
}

my $gpl = 'General Public License';
my $gp2 = 'This is free software; it comes under the GNU';
my $gp3 = 'License: GPL with the following explicit clarification';
my $x11 = 'TORT OR OTHERWISE';
my $bsd = 'INCLUDING NEGLIGENCE OR OTHERWISE';
my $gen = 'generated';

sub nameok()
{
  my $f = shift;

  if ($f =~ /\.C$/ or $f =~ /\.cpp$/ or $f =~ /\.c$/ or $f =~ /\.h$/)
  {
    if ($f =~ /\.cpp$/)
    {
      if
        (
              $f !~ /meta_unload\.cpp$/
         and  $f !~ /_stub\.cpp/
         and  $f !~ /_skel.cpp/
         and  $f !~ /_closure\.cpp/
         and  $f !~ /moc\.cpp/
        )
      {
        return 1;
      }
      else
      {
        return 0;
      }
    }
    else
    {
      return 1;
    }
  }
  else
  {
    return 0;
  }
}

sub recursive_check()
{
  my $dir = shift;

  opendir (DIR, $dir) or die "Can't open $dir";

  my @filenames = grep { /^[^\.]/ } readdir(DIR);

  for my $f (@filenames)
  {
    my $filename = "$dir/$f";

    if (-d $filename)
    {
      &recursive_check($filename);
    }
    elsif (-f $filename and &nameok($filename))
    {
      open (IN, "<$filename") or die "Can't open $filename";

      my $license = "!";

      while (<IN>)
      {
        if (/$gpl/) { $license = "G"; last; }
        if (/$gp2/) { $license = "G"; last; }
        if (/$gp3/) { $license = "G"; last; }
        if (/$x11/) { $license = "X"; last; }
        if (/$bsd/) { $license = "B"; last; }
        if (/$gen/) { $license = "g"; last; }
      }

      print "$license $filename\n";
    }
  }
}

&recursive_check($ARGV[0]);