File: licensecheck2dep5

package info (click to toggle)
cdbs 0.4.130
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,348 kB
  • sloc: sh: 4,534; xml: 2,159; makefile: 178; perl: 138; python: 94; ansic: 7; java: 5
file content (83 lines) | stat: -rwxr-xr-x 3,609 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl -w
# -*- mode: cperl; coding: utf-8 -*-
# Copyright © 2005-2012 Jonas Smedegaard <dr@jones.dk>
# Description: Reformat licencecheck output to copyright file format
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

my $whitespace_list_delimiter = $ENV{'whitespace_list_delimiter'} || "\n ";
my $rfc822_list_delimiter = $ENV{'rfc822_list_delimiter'} || "\n  ";
my $merge_same_license = $ENV{'merge_same_license'} || "";

print "Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/\n";
print "Upstream-Name: FIXME\n";
print "Upstream-Contact: FIXME\n";
print "Source: FIXME\n";
print "Disclaimer: Autogenerated by CDBS\n\n";
$n=0; while (<>) {
	if (/^([^:\s][^:]+):[\s]+(\S.*?)\s*$/) {
		$files[$n]{name}=$1;
		$files[$n]{license}=$2;
	};
	if (/^\s*\[Copyright:\s*(\S.*?)\s*\]/) {
		$files[$n]{copyright}=$1;
	};
	/^$/ and $n++;
};
foreach $file (@files) {
	$file->{name} =~ s/([*?\\])/\\$1/g;
	$file->{license} =~ s/\s*\(unversioned\/unknown version\)//;
	$file->{license} =~ s/\s*\(with incorrect FSF address\)//;
	$file->{license} =~ s/\s+\(v([^)]+) or later\)/-$1+/;
	$file->{license} =~ s/\s+\(v([^)]+)\)/-$1/;
	$file->{license} =~ s/\s*(\*No copyright\*)\s*// and $file->{copyright} = $1;
	$file->{license} =~ s/^\s*(GENERATED FILE)/UNKNOWN/;
	$file->{license} =~ s/\s+(GENERATED FILE)//;
	$file->{license} =~ s/^\s*zlib\/libpng$/Zlib/;
	$file->{license} =~ s/^\s*MIT\/X11 \(BSD like\)$/Expat/;
	$file->{license} =~ s/^\s*BSD \((\d) clause\)$/BSD-$1-clause/;
	$file->{copyright} =~ s/^&copy;\s*//;
	$file->{copyright} =~ s/(?<=(\b\d{4}))(?{$y=$^N})\s*[,-]\s*((??{$y+1}))\b/-$2/g;
	$file->{copyright} =~ s/(?<=\b\d{4})\s*-\s*\d{4}(?=\s*-\s*(\d{4})\b)//g;
	$file->{copyright} =~ s/\b(\d{4}),?\s+([\S^\d])/$1, $2/g;
	my @ownerlines = grep {/\w\w/} split /\s\/\s/, $file->{copyright};
	my @ownerlines_clean = ();
	my %owneryears = ();
	my $owneryears_seem_correct = 1;
	for $ownerline ( @ownerlines ) {
		my ($owneryear, $owner) = $ownerline =~ /^([\d\-,\s]*)\s*+(.*)/;
		$owneryears_seem_correct = 0 unless ($owneryear);
		$owner =~ s/^by\s+//;
		$owner =~ s/,?\s+All Rights Reserved\.?//gi;
		push @ownerlines_clean, "$owneryear$owner";
		push @{ $owneryears{"$owner"} }, $owneryear;
	};
	my @owners = sort keys %owneryears;
	@owners = () if ($merge_same_license and $owneryears_seem_correct);
	my $pattern = join ("\n", $file->{license}, @owners);
	push @{ $patternfiles{"$pattern"} }, $file->{name};
	push @{ $patternownerlines{"$pattern"} }, @ownerlines_clean;
	$patternlicense{"$pattern"} = $file->{license};
};
foreach $pattern ( sort {
			@{$patternfiles{$b}} <=> @{$patternfiles{$a}}
			||
			$a cmp $b
		} keys %patternfiles ) {
	my $prev;
	@ownerlines_unique = grep((!defined $prev || $_ ne $prev) && (($prev) = $_), sort @{ $patternownerlines{$pattern} });
	print "Files: ", join($whitespace_list_delimiter, sort @{ $patternfiles{$pattern} }), "\n";
	print "Copyright: ", join($rfc822_list_delimiter, @ownerlines_unique), "\n";
	print "License: $patternlicense{$pattern}\n FIXME\n\n";
};