PathJoin: Fix dropping of path component on failed lookup.
[gemrb.git] / admin / check_copyright.pl
blobcc31e56f2c2ca96411d8a9793e22e240e9e87ff8
1 #!/usr/bin/perl -w
2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003 The GemRB Project
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 use strict;
23 my $TGT_DIR = "gemrb";
25 # TODO: use list of exceptions, i.e. pairs file, boilerplate to use
29 my $copyright_cpp = <<EOT;
30 /\\* GemRB \\- Infinity Engine Emulator
31 \\* Copyright \\(C\\) 2003 The GemRB Project
32 \\*
33 \\* This program is free software; you can redistribute it and/or
34 \\* modify it under the terms of the GNU General Public License
35 \\* as published by the Free Software Foundation; either version 2
36 \\* of the License, or \\(at your option\\) any later version\\.
38 \\* This program is distributed in the hope that it will be useful,
39 \\* but WITHOUT ANY WARRANTY; without even the implied warranty of
40 \\* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\\. See the
41 \\* GNU General Public License for more details\\.
43 \\* You should have received a copy of the GNU General Public License
44 \\* along with this program; if not, write to the Free Software
45 \\* Foundation, Inc\\., 51 Franklin Street, Fifth Floor, Boston, MA 02110\\-1301, USA\\.
46 \\*
47 \\* \\\$[I]d:.* \\\$
48 \\*
49 \\*/
51 /\\*\\*
52 \\* \@file .*
53 \\* .*
54 \\* \@author The GemRB Project
55 \\*/
56 EOT
58 my $copyright_py = <<EOT;
59 # \\-\\*\\-python\\-\\*\\-
60 # GemRB \\- Infinity Engine Emulator
61 # Copyright \\(C\\) 2003 The GemRB Project
63 # This program is free software; you can redistribute it and/or
64 # modify it under the terms of the GNU General Public License
65 # as published by the Free Software Foundation; either version 2
66 # of the License, or \\(at your option\\) any later version\\.
68 # This program is distributed in the hope that it will be useful,
69 # but WITHOUT ANY WARRANTY; without even the implied warranty of
70 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\\. See the
71 # GNU General Public License for more details\\.
73 # You should have received a copy of the GNU General Public License
74 # along with this program; if not, write to the Free Software
75 # Foundation, Inc\\., 51 Franklin Street, Fifth Floor, Boston, MA 02110\\-1301, USA\\.
77 # \\\$[I]d: .* \\\$
78 EOT
82 my @copyright_cpp = split (/\n/, $copyright_cpp);
83 my @copyright_py = split (/\n/, $copyright_py);
85 my @filetypes = (
86 [ '/\\.#', 'ignore'],
87 [ '~$', 'ignore'],
88 [ '\\.(pyc|lo)$', 'ignore'],
89 [ '\\.(h|cpp)$', \@copyright_cpp ],
90 [ '\\.py$', \@copyright_py ],
91 [ '.', 'ignore' ],
95 sub get_filetype {
96 my ($filename) = @_;
97 foreach my $rec (@filetypes) {
98 my $re = $$rec[0];
99 if ($filename =~ /$re/) {
100 return $$rec[1];
103 return undef;
106 sub check_file {
107 my ($filename) = @_;
109 my $copyright = &get_filetype ($filename);
110 if (! defined ($copyright)) {
111 print "? $filename\n";
112 return;
115 if ($copyright eq 'ignore') {
116 return;
119 my $num_lines = scalar (@{$copyright});
122 open (SRC, "< $filename") || die "Can't open file $filename: $!\n";
124 my $index = 0;
125 while (defined (my $line = <SRC>) && ($index < $num_lines)) {
126 chomp($line);
127 my $cline = $$copyright[$index];
128 if ($line !~ /^$cline$/) {
129 $cline =~ tr/\\//d;
130 print "! $filename\n";
131 print " -: $cline\n";
132 print " +: $line\n";
133 print "\n";
134 last;
136 $index++;
139 if ($index >= $num_lines) {
140 print "= $filename\n";
143 close (SRC);
146 sub check_dir {
147 my ($dir) = @_;
148 local (*DIR);
150 opendir (DIR, $dir) || die "Can't open dir $dir: $!\n";
151 while (defined (my $file = readdir (DIR))) {
152 my $dirfile = "$dir/$file";
153 if (-f $dirfile) {
154 &check_file ($dirfile);
155 } elsif (-d $dirfile && substr($file, 0, 1) ne '.') {
156 &check_dir ($dirfile);
159 closedir (DIR);
163 if (scalar (@ARGV) != 0) {
164 $TGT_DIR = $ARGV[0];
167 &check_dir ($TGT_DIR);