merge_copyrights 5.69 KB
Newer Older
Bob Halley's avatar
update    
Bob Halley committed
1
#!/usr/local/bin/perl -w
Bob Halley's avatar
Bob Halley committed
2
#
3
# Copyright (C) 1998-2001, 2003-2007, 2009-2017  Internet Systems Consortium, Inc. ("ISC")
Mark Andrews's avatar
Mark Andrews committed
4
#
5
6
7
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
Bob Halley's avatar
Bob Halley committed
8

9
10
11
12
13
use strict;

my %file_types = ();
my %file_years = ();
my %exists = ();
Bob Halley's avatar
Bob Halley committed
14

15
open(COPYRIGHTS, "<util/copyrights") || die "can't open ./util/copyrights: $!";
Bob Halley's avatar
Bob Halley committed
16
17
while (<COPYRIGHTS>) {
    chomp;
18
    my ($file, $type, $years) = split;
Bob Halley's avatar
Bob Halley committed
19
20
    $file_types{$file} = $type;
    $file_years{$file} = $years;
Bob Halley's avatar
Bob Halley committed
21
}
Bob Halley's avatar
Bob Halley committed
22
23
close(COPYRIGHTS);

Mark Andrews's avatar
Mark Andrews committed
24
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time());
25
$sec = $min = $hour = $mday = $mon = $wday = $yday = $isdst = 0;
Bob Halley's avatar
Bob Halley committed
26
$year += 1900;
Bob Halley's avatar
Bob Halley committed
27

28
open(FILES, "git ls-files | sed 's;^;./;' |") || die "git ls-files: $!";
Bob Halley's avatar
Bob Halley committed
29
30
while (<FILES>) {
    chomp;
31
32
33
34
35
36
37
38
39
40
    $exists{$_} = 1;
}
close(FILES);

open(CHANGES, "sh util/recent_changes.sh |") || die "recent_changes.sh: $!";
while (<CHANGES>) {
    chomp;

    # this file isn't in the repository now
    next unless ($exists{$_});
41
42

    next if (m%/\.\# |		# CVS old conflict file
Mark Andrews's avatar
add MKD    
Mark Andrews committed
43
44
45
46
47
48
49
	       /CVS/ |		# CVS directory
	       /.git/ |		# git directory
	       util/newcopyrights | # our output
	       \.bak$ |		# created by update_copyrights
	       /(dnssafe|openssl)/.*\.[ch]$ |	# imported
	       doc/(draft|expired|rfc)/		# imported
	     %x);
50

Bob Halley's avatar
Bob Halley committed
51
    if (!$file_types{$_}) {
52
53
	# Strip any .in extension to find out the file's real type.
	# .in files are processed by configure to produce the target file.
54
	my $base;
55
56
	($base = $_) =~ s/\.in$//;

57
58
59
	# Contributed code should maintain its own copyright.
	if ($base =~ /\.\/contrib\//) {
	     $file_types{$_} = "X";
Mark Andrews's avatar
Mark Andrews committed
60
	} elsif ($base =~ /\.\/unit\/atf-src\//) {
61
	     $file_types{$_} = "X";
Mark Andrews's avatar
Mark Andrews committed
62
63
	} elsif ($base =~ /\/openssl-[a-z0-9.]*-patch$/) {
	    $file_types{$_} = "X";
64
	} elsif ($base =~ /\.(c|h|css)$/) {
Bob Halley's avatar
Bob Halley committed
65
	    $file_types{$_} = "C";
Mark Andrews's avatar
add MKD    
Mark Andrews committed
66
	} elsif ($base =~ /\.y$/) {
67
	    $file_types{$_} = "YACC";
Mark Andrews's avatar
add MKD    
Mark Andrews committed
68
	} elsif ($base =~ /\.pl$/i) {
69
	    $file_types{$_} = "PERL";
Mark Andrews's avatar
add MKD    
Mark Andrews committed
70
	} elsif ($base =~ /\.py$/i) {
Mark Andrews's avatar
Mark Andrews committed
71
	    $file_types{$_} = "PYTHON";
Mark Andrews's avatar
add MKD    
Mark Andrews committed
72
	} elsif ($base =~ /\.sh$/) {
73
	    $file_types{$_} = "SH";
Mark Andrews's avatar
add MKD    
Mark Andrews committed
74
	} elsif ($base =~ /\.docbook$/ ||
Mark Andrews's avatar
Mark Andrews committed
75
76
		 $base =~ /.xsl$/ ||
		 $base =~ /.xml$/) {
Mark Andrews's avatar
Mark Andrews committed
77
	    $file_types{$_} = "SGML";
Mark Andrews's avatar
add MKD    
Mark Andrews committed
78
	} elsif ($base =~ /doc\/arm\/.*\.html$/) {
Mark Andrews's avatar
Mark Andrews committed
79
	    $file_types{$_} = "X";
80
81
	} elsif ($base =~ /\.(sty|pdf|eps)$/) {
	    $file_types{$_} = "X";
Mark Andrews's avatar
add MKD    
Mark Andrews committed
82
	} elsif ($base =~ /\.html$/) {
83
	    $file_types{$_} = "HTML";
84
85
	    $base =~ s/\.html$//;
	    $base = $base . ".docbook";
Mark Andrews's avatar
add MKD    
Mark Andrews committed
86
	} elsif ($base =~ /\.(man|[0-9])$/) {
87
	    $file_types{$_} = "MAN";
88
89
	    $base =~ s/\.[0-9]$//;
	    $base = $base . ".docbook";
90
	} elsif ($base =~ /\/Makefile$/) {
Michael Graff's avatar
Michael Graff committed
91
	    $file_types{$_} = "MAKE";
Mark Andrews's avatar
Mark Andrews committed
92
	} elsif ($base =~ /\/(named|rndc|good|bad).{0,2}\.conf$/) {
93
	    $file_types{$_} = "CONF-C";
94
95
	} elsif ($base =~ /\/checkconf\/(good|bad)-.*\.conf$/) {
	    $file_types{$_} = "CONF-C";
96
97
98
	} elsif ($base =~ /\/resolv.?\.conf$/) {
	    $file_types{$_} = "CONF-SH";
	} elsif ($base =~ /\.(db|hint)$/) {
99
	    $file_types{$_} = "ZONE";
Mark Andrews's avatar
Mark Andrews committed
100
	} elsif ($base =~ /\.md$/) {
Mark Andrews's avatar
add MKD    
Mark Andrews committed
101
	    $file_types{$_} = "MKD";
Mark Andrews's avatar
Mark Andrews committed
102
	} elsif ($base =~ /(\/\.(gitignore|gitattributes)|Atffile|Kyuafile|\.(gif|jpg))$/i) {
103
104
105
106
	    $file_types{$_} = "X";
	} elsif ($base =~ /\.(def|dep|dsp|dsw|mak|sln)$/i) {
	    $file_types{$_} = "X";
	} elsif ($base =~ /\.(vcxproj(|\.(user|filters)))$/i) {
Bob Halley's avatar
Bob Halley committed
107
	    $file_types{$_} = "X";
Mark Andrews's avatar
Mark Andrews committed
108
	} elsif ($base =~ /\.rnc$/i) {
Mark Andrews's avatar
Mark Andrews committed
109
	    $file_types{$_} = "RNC";
Mark Andrews's avatar
Mark Andrews committed
110
111
	} elsif ($base =~ /^\.\/EXCLUDED$/i) {
	    $file_types{$_} = "X";
Mark Andrews's avatar
add BAT    
Mark Andrews committed
112
113
	} elsif ($base =~ /\.bat$/i) {
	    $file_types{$_} = "BAT";
Mark Andrews's avatar
Mark Andrews committed
114
115
	} elsif ($base =~ /\.(key|private)$/i) {
	    $file_types{$_} = "X";
Mark Andrews's avatar
Mark Andrews committed
116
	} elsif ($base =~ /\/named\d{0,2}\.args$/i) {
Mark Andrews's avatar
Mark Andrews committed
117
	    $file_types{$_} = "X";
Mark Andrews's avatar
Mark Andrews committed
118
119
	} elsif ($base =~ /\/named\.port$/i) {
	    $file_types{$_} = "X";
120
121
122
123
	} elsif ($base =~ /\/named\.dropedns$/i) {
	    $file_types{$_} = "X";
	} elsif ($base =~ /\/named\.notcp$/i) {
	    $file_types{$_} = "X";
Mark Andrews's avatar
Mark Andrews committed
124
125
	} elsif ($base =~ /\/doc\/misc\/[-a-z]*\.zoneopt$/i) {
	    $file_types{$_} = "X";
Mark Andrews's avatar
Mark Andrews committed
126
127
	} elsif ($base =~ /\/README$/i) {
	    $file_types{$_} = "TXT.BRIEF";
Bob Halley's avatar
Bob Halley committed
128
129
130
	} else {
	    $file_types{$_} = "?";
	}
131
	my $m_year = int(`sh util/file_year.sh $_`);
132
	if (($file_types{$_} eq "MAN" || $file_types{$_} eq "HTML") &&
133
	    $base =~ /\.docbook$/ && -e $base) {
134
135
	   $file_years{$_} = "DOCBOOK";
	} elsif ($m_year != $year) {
Bob Halley's avatar
Bob Halley committed
136
137
138
139
140
141
	    print "$_: must set copyright year(s) manually\n";
	    $file_years{$_} = "????";
	} else {
	    $file_years{$_} = "$year";
	}
    } else {
Mark Andrews's avatar
add MKD    
Mark Andrews committed
142
143
	if (! defined($file_years{$_}) || $file_years{$_} eq "????") {
	    print "$_: must set copyright year(s) manually\n";
144
	    $file_years{$_} = "????";
Mark Andrews's avatar
add MKD    
Mark Andrews committed
145
146
	    next;
	}
147

148
149
150
	# track the modification years even if we are not going to be
	# updating the copyrights.
	# next if $file_types{$_} eq "X";
151
152
	next if ($file_years{$_} =~ /^PARENT:/);
	next if ($file_years{$_} eq "DOCBOOK");
153

154
155
156
	my @years = split(/,/, $file_years{$_});
	my $has_current = 0;
	foreach my $fyear (@years) {
Bob Halley's avatar
Bob Halley committed
157
158
159
160
161
	    if ($fyear == $year) {
		$has_current = 1;
	    }
	}
	if (!$has_current) {
162
	    $file_years{$_} .= ",$year";
Bob Halley's avatar
Bob Halley committed
163
164
165
	}
    }
}
166
close(CHANGES);
Bob Halley's avatar
Bob Halley committed
167
168
169

open(NEWCOPYRIGHTS, ">util/newcopyrights") ||
    die "can't open newcopyrights: $!";
170
foreach my $file (sort(keys(%file_types))) {
Bob Halley's avatar
Bob Halley committed
171
    print NEWCOPYRIGHTS "$file";
172
173
    my $len = length($file);
    my $tabs = 0;
Bob Halley's avatar
Bob Halley committed
174
175
176
    if ($len >= 48) {
	$tabs = 1;
    } else {
177
	my $needed = int (48 - $len);
Bob Halley's avatar
Bob Halley committed
178
179
180
181
182
	$tabs = int ($needed / 8);
	if ($needed % 8 != 0) {
	    $tabs++;
	}
    }
183
    for (my $i = 0; $i < $tabs; $i++) {
Bob Halley's avatar
Bob Halley committed
184
185
186
	printf NEWCOPYRIGHTS "\t";
    }
    printf NEWCOPYRIGHTS "%s\t%s\n", $file_types{$file}, $file_years{$file};
187
188

    if (($file_years{$file} eq "????") || ($file_types{$file} eq "?")) {
Mark Andrews's avatar
add MKD    
Mark Andrews committed
189
	print "Unknown file type or year: $file\n";
190
    }
Bob Halley's avatar
Bob Halley committed
191
192
}
close(NEWCOPYRIGHTS);