mirror of https://github.com/perkeep/perkeep.git
69 lines
2.0 KiB
Perl
Executable File
69 lines
2.0 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
#
|
|
# Copyright 2010 Google Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
#
|
|
#
|
|
# This script adds copyright headers to files.
|
|
|
|
use strict;
|
|
my $header = do { local $/; <DATA> };
|
|
$header =~ s!\s+$!\n!;
|
|
my $yyyy = (localtime())[5] + 1900;
|
|
$header =~ s/YYYY/$yyyy/ or die;
|
|
|
|
unless (@ARGV == 1) {
|
|
die "Usage: copyrightify <filename>\n";
|
|
}
|
|
|
|
my $file = shift;
|
|
open(my $fh, $file) or die "Open $file error: $!\n";
|
|
my $source = do { local $/; <$fh> };
|
|
close($fh);
|
|
if ($source =~ /Copyright \d\d\d\d/) {
|
|
print STDERR "# $file - OK\n";
|
|
exit;
|
|
}
|
|
|
|
my $newsource = $source;
|
|
if ($file =~ /\.go$/) {
|
|
$header = "/*\n$header*/\n\n";
|
|
$newsource = $header . $source;
|
|
} elsif ($file =~ /\.py$/) {
|
|
$header = join("", map { "# $_\n" } split(/\n/, $header));
|
|
$newsource = $header . $source;
|
|
} else {
|
|
die "File type not supported.";
|
|
}
|
|
|
|
|
|
open(my $fh, ">$file") or die "Open $file error: $!\n";
|
|
print $fh $newsource;
|
|
close($fh) or die;
|
|
|
|
__END__
|
|
Copyright YYYY Google Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|