r2931 - in people/goneri: . tools

Gonéri Le Bouder goneri-guest at alioth.debian.org
Tue Jun 12 23:03:39 UTC 2007


Author: goneri-guest
Date: 2007-06-12 23:03:38 +0000 (Tue, 12 Jun 2007)
New Revision: 2931

Added:
   people/goneri/tools/
   people/goneri/tools/find-copyright-status.pl
Log:
initial import


Added: people/goneri/tools/find-copyright-status.pl
===================================================================
--- people/goneri/tools/find-copyright-status.pl	                        (rev 0)
+++ people/goneri/tools/find-copyright-status.pl	2007-06-12 23:03:38 UTC (rev 2931)
@@ -0,0 +1,157 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use File::Find;
+use File::Basename;
+
+use Data::Dumper;
+
+my $authors;
+my $dirs;
+my $licenses;
+
+
+sub detechLicense {
+
+	my $lines = shift;
+	my $licenses = { 
+		"aladdin-zlib" =>
+			[ 
+			"This software is provided 'as-is', without any express or implied",
+		"warranty.  In no event will the authors be held liable for any damages",
+		"arising from the use of this software.",
+		"Permission is granted to anyone to use this software for any purpose,",
+		"including commercial applications, and to alter it and redistribute it",
+		"freely, subject to the following restrictions:",
+		"1. The origin of this software must not be misrepresented; you must not",
+		"   claim that you wrote the original software. If you use this software",
+		"   in a product, an acknowledgment in the product documentation would be",
+		"   appreciated but is not required.",
+		"2. Altered source versions must be plainly marked as such, and must not be",
+		"   misrepresented as being the original software.",
+		"3. This notice may not be removed or altered from any source distribution."],
+		'GPLv2+' => [
+		"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",
+#		"of the License, 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",
+		],
+
+	};
+
+foreach my $license (keys %{$licenses}) {
+		 my $ok = 0;
+		 foreach my $line (@{$licenses->{$license}}) {
+			 foreach (@$lines) {
+				 $ok++ if /$line/;
+			 }
+
+		 }
+#		 print STDERR $ok.'-'.@{$licenses->{$license}}."\n";
+		 return $license if $ok == @{$licenses->{$license}};
+	 }
+
+	 return "unknow";
+
+}
+
+sub whichLicense {
+	my $licenses = shift;
+
+	my $ret = "unknow";
+	my $t = 0;
+	foreach (keys %$licenses) {
+		if ($licenses->{$_} > $t) {
+			$ret = $_;
+			$t = $licenses->{$_};
+		}
+	}
+
+	$ret = "GPLv2+" if ($ret eq 'GPLv2' && $licenses->{'GPLv2+'} && (($licenses->{'GPLv2'} / $licenses->{'GPLv2+'}) > 3));
+
+	$ret;
+}
+
+sub scanSrc {
+
+	my $file = shift;
+	open FILE, "<$file" or die "Can't open $file: $!";
+	my @lines = <FILE>;
+	close FILE;
+	my $license = detechLicense(\@lines);
+	foreach my $line (@lines) {
+		chomp;
+
+		if ($line =~ s/copyright//i) {
+			$line =~ s/\(c\)//i;
+
+		my @year;
+
+
+		while ($line =~ /\d\d\d\d/) {
+			if ($line =~ s/(\d\d\d\d)\ {0,1}-\ {0,1}(\d\d\d\d)//) {
+				my $begin = $1;
+			my $end = $2;
+			while ($begin < $end) {
+				push @year, $begin;
+				$begin++;
+			}
+		}
+
+		if ($line =~ s/(\d\d\d\d)//) {
+			push @year, $1;
+		}
+		$line =~ s/by authors//;
+
+
+		}
+		$line =~ s/^(\s|,|\*|\.)+//;
+		$line =~ s/(\s|,|\*|\.)+$//;
+
+
+		foreach (@year) {
+			$authors->{$line}{$File::Find::dir}{$file}{year}{$_} = 1;
+			$dirs->{$File::Find::dir}{$file}{$line}{year}{$_} = 1;
+		}
+	}
+	$dirs->{$File::Find::dir}{$file}{license} = $license;
+	}
+
+}
+sub findFile { 
+	return unless -f;
+
+	my $basename = basename($_);
+	return if /\.(so|o|i386|sln|swp|lib)/;
+	return if $basename =~ /^makefile/i;
+	return if $basename =~ /^(license|copying|gnu\.txt)$/i;
+	if ($basename =~ /\.(cpp|h|c)$/) {
+		scanSrc ($_);
+	} else {
+#scanOther ($_);	
+	}
+
+}
+
+finddepth(\&findFile, '.');
+
+my $globallicense = whichLicense ($licenses);
+
+#####
+print "SOFTWARE is released under the $globallicense\n";
+foreach my $dir (sort keys %$dirs) {
+
+	print "[".$dir."]\n";
+	foreach my $file (keys %{$dirs->{$dir}}) {
+		print ($dirs->{$dir}{$file}{license});
+		print " -> ".$file."\n";
+	}
+
+
+}




More information about the Pkg-games-commits mailing list