eccodes/license.pl

129 lines
3.2 KiB
Perl
Raw Normal View History

2013-03-25 12:04:10 +00:00
#!/usr/bin/perl
use strict;
my $APACHE = <<"EOF";
2018-01-02 11:31:02 +00:00
Copyright 2005-2018 ECMWF.
2013-03-25 14:23:07 +00:00
This software is licensed under the terms of the Apache Licence Version 2.0
which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
2013-03-25 12:04:10 +00:00
2013-03-25 14:23:07 +00:00
In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
2013-03-25 12:04:10 +00:00
EOF
my $LGPL = <<"EOF";
Copyright 2005-2007 ECMWF
Licensed under the GNU Lesser General Public License which
incorporates the terms and conditions of version 3 of the GNU
General Public License.
See LICENSE and gpl-3.0.txt for details.
EOF
my $GPL = <<"EOF";
Copyright 2005-2007 ECMWF
Licensed under the GNU General Public License version 3.
See LICENSE for details.
EOF
2013-03-25 14:23:07 +00:00
my $LICENSE = $APACHE;
2013-03-25 12:04:10 +00:00
my %COMMENTS = (
java => { start => "/**\n" , end => "*/\n\n" , comment => "* " },
xml => { start => "<!--\n", end => "-->\n\n" , after => "\<\?xml[^<]*\>" },
# xsd => { start => "<!--\n", end => "-->\n\n" },
# jsp => { start => "<!--\n", end => "-->\n\n" },
sh => { comment => "# ", end => "\n", after => "^#!/.*\n" },
pl => { comment => "# ", end => "\n", after => "^#!/.*\n" },
js => { start => "/**\n" , end => "*/\n\n" , comment => "* " },
c => { start => "/**\n" , end => "*/\n\n" , comment => "* " },
h => { start => "/**\n" , end => "*/\n\n" , comment => "* " },
l => { start => "/**\n" , end => "*/\n\n" , comment => "* " },
y => { start => "/**\n" , end => "*/\n\n" , comment => "* " },
css => { start => "/**\n" , end => "*/\n\n" , comment => "* " },
sql => { comment => "-- ", end => "\n" },
properties => { comment => "# ", end => "\n" },
def => { comment => "# ", end => "\n" },
F => { comment => "C ", end => "C\n\n " },
f => { comment => "C ", end => "C\n\n" },
);
foreach my $file ( @ARGV )
{
my $doit=1;
$file =~ /\.(\w+)/;
my $ext = $1;
my $c = $COMMENTS{$ext};
unless($c)
{
print "$file: unsupported extension. File ignored\n";
next;
}
open(IN,"<$file") or die "$file: $!";
my @text = <IN>;
close(IN);
if(join("",@text) =~ /Licensed under the/gs)
{
print "$file: License already stated. File ignored\n";
next;
}
open(OUT,">$file.tmp") or die "$file.tmp: $!";
if($c->{after})
{
my @x;
my $re = $c->{after};
loop: while(@text)
{
if($text[0] =~ m/$re/)
{
print OUT @x, shift @text;
@x = ();
last loop;
}
push @x,shift @text;
}
@text = (@x,@text);
}
print OUT $c->{start};
foreach my $line ( split("\n",$LICENSE) )
{
print OUT $c->{comment}, $line,"\n";
}
print OUT $c->{end};
print OUT @text;
close(OUT) or die "$file: $!";
if($doit) {
use File::Copy qw(cp);
use File::Compare qw(compare_text compare);
if(compare_text("$file.tmp",$file)) {
print "UPDATING file $file\n";
system("p4 edit $file") unless(-w $file);
cp($file,"$file.old") or die "cp($file,$file.old): $!";
cp("$file.tmp",$file) or die "cp($file.tmp,$file): $!";
}
} else {
print "IGNORING file $file\n";
}
unlink("$file.tmp");
}