github.com/olivere/camlistore@v0.0.0-20140121221811-1b7ac2da0199/misc/copyrightifity (about) 1 #!/usr/bin/perl 2 # 3 # Copyright 2010 Google Inc. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # 17 # 18 # This script adds copyright headers to files. 19 20 use strict; 21 my $header = do { local $/; <DATA> }; 22 $header =~ s!\s+$!\n!; 23 my $yyyy = (localtime())[5] + 1900; 24 $header =~ s/YYYY/$yyyy/ or die; 25 26 unless (@ARGV == 1) { 27 die "Usage: copyrightify <filename>\n"; 28 } 29 30 my $file = shift; 31 open(my $fh, $file) or die "Open $file error: $!\n"; 32 my $source = do { local $/; <$fh> }; 33 close($fh); 34 if ($source =~ /Copyright \d\d\d\d/) { 35 print STDERR "# $file - OK\n"; 36 exit; 37 } 38 39 my $newsource = $source; 40 if ($file =~ /\.(go|java|aidl)$/) { 41 $header = "/*\n$header*/\n\n"; 42 $newsource = $header . $source; 43 } elsif ($file =~ /\.py$/) { 44 $header = join("", map { "# $_\n" } split(/\n/, $header)); 45 $newsource = $header . $source; 46 } else { 47 die "File type not supported."; 48 } 49 50 51 open(my $fh, ">$file") or die "Open $file error: $!\n"; 52 print $fh $newsource; 53 close($fh) or die; 54 55 __END__ 56 Copyright YYYY The Camlistore Authors 57 58 Licensed under the Apache License, Version 2.0 (the "License"); 59 you may not use this file except in compliance with the License. 60 You may obtain a copy of the License at 61 62 http://www.apache.org/licenses/LICENSE-2.0 63 64 Unless required by applicable law or agreed to in writing, software 65 distributed under the License is distributed on an "AS IS" BASIS, 66 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 67 See the License for the specific language governing permissions and 68 limitations under the License.