Dear team,

Please find attached patches for licensecheck ('jessie' branch).
I expect them to be self-explanatory but if any doubts I'll be happy to answer 
your questions.

More changes to come.

Shall we change license names for compliance with 
copyright-format-1.0: 

        "BSD (3 clause)"    --> "BSD-3-clause"
        "GPL (v2 or later)" --> "GPL-2+"
etc.?
I hope everybody would agree with that.

-- 
Regards,
Dmitry.
From 30f82ca38ac85230ecc2457f18463a892bf4b6e0 Mon Sep 17 00:00:00 2001
From: Dmitry Smirnov <[email protected]>
Date: Thu, 11 Oct 2012 04:34:16 +1100
Subject: [PATCH 1/5] fix BSD-3-clause detection

 #688843
---
 scripts/licensecheck.pl |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/licensecheck.pl b/scripts/licensecheck.pl
index b4a86f3..815b507 100755
--- a/scripts/licensecheck.pl
+++ b/scripts/licensecheck.pl
@@ -467,11 +467,11 @@ sub parselicense($) {
     }
 
     if ($licensetext =~ /THIS SOFTWARE IS PROVIDED .*AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY/) {
 	if ($licensetext =~ /All advertising materials mentioning features or use of this software must display the following acknowledge?ment.*This product includes software developed by/i) {
 	    $license = "BSD (4 clause) $license";
-	} elsif ($licensetext =~ /(The name .*? may not|Neither the names? .*? nor the names of (its|their) contributors may) be used to endorse or promote products derived from this software/i) {
+	} elsif ($licensetext =~ /(The name .*? may not|Neither the names? .*? nor the names of (its|their|other) contributors may) be used to endorse or promote products derived from this software/i) {
 	    $license = "BSD (3 clause) $license";
 	} elsif ($licensetext =~ /Redistributions of source code must retain the above copyright notice/i) {
 	    $license = "BSD (2 clause) $license";
 	} else {
 	    $license = "BSD $license";
-- 
1.7.10.4

From 076dd160ae78fc1b7211e29f8fda0a639db02ae5 Mon Sep 17 00:00:00 2001
From: Dmitry Smirnov <[email protected]>
Date: Wed, 10 Oct 2012 16:18:51 +1100
Subject: [PATCH 4/5] GetOptions is done right

---
 scripts/licensecheck.pl |   88 +++++++++++++++++++++++++----------------------
 1 file changed, 47 insertions(+), 41 deletions(-)

diff --git a/scripts/licensecheck.pl b/scripts/licensecheck.pl
index f8cc890..46d2039 100755
--- a/scripts/licensecheck.pl
+++ b/scripts/licensecheck.pl
@@ -161,16 +161,21 @@ $default_ignore_regex =~ s/\n//sg;
 
 my $default_check_regex = '\.(c(c|pp|xx)?|h(h|pp|xx)?|f(77|90)?|p(l|m)|xs|sh|php|py(|x)|rb|java|vala|el|sc(i|e)|cs|pas|inc|dtd|xsl|mod|m|tex|mli?)$';
 
 my $modified_conf_msg;
 
-my ($opt_verbose, $opt_lines, $opt_noconf, $opt_ignore_regex, $opt_check_regex)
-  = ('', '', '', '', '');
-my $opt_recursive = 0;
-my $opt_copyright = 0;
-my $opt_machine = 0;
-my ($opt_help, $opt_version);
+my %OPT=(
+    verbose        => '',
+    lines          => '',
+    noconf         => '',
+    ignore_regex   => '',
+    check_regex    => '',
+    recursive      => 0,
+    copyright      => 0,
+    machine        => 0,
+);
+
 my $def_lines = 60;
 
 # Read configuration files and then command line
 # This is boilerplate
 
@@ -209,47 +214,48 @@ if (@ARGV and $ARGV[0] =~ /^--no-?conf$/) {
 	}
     }
     $modified_conf_msg ||= "  (none)\n";
     chomp $modified_conf_msg;
 
-    $opt_verbose = $config_vars{'LICENSECHECK_VERBOSE'} eq 'yes' ? 1 : 0;
-    $opt_lines = $config_vars{'LICENSECHECK_PARSELINES'};
+    $OPT{'verbose'} = $config_vars{'LICENSECHECK_VERBOSE'} eq 'yes' ? 1 : 0;
+    $OPT{'lines'} = $config_vars{'LICENSECHECK_PARSELINES'};
 }
 
-GetOptions("help|h" => \$opt_help,
-	   "version|v" => \$opt_version,
-	   "verbose!" => \$opt_verbose,
-	   "lines|l=i" => \$opt_lines,
-	   "ignore|i=s" => \$opt_ignore_regex,
-	   "recursive|r" => \$opt_recursive,
-	   "check|c=s" => \$opt_check_regex,
-	   "copyright" => \$opt_copyright,
-	   "machine|m" => \$opt_machine,
-	   "noconf" => \$opt_noconf,
-	   "no-conf" => \$opt_noconf,
-	   )
-    or die "Usage: $progname [options] filelist\nRun $progname --help for more details\n";
-
-$opt_lines = $def_lines if $opt_lines !~ /^[1-9][0-9]*$/;
-$opt_ignore_regex = $default_ignore_regex if ! length $opt_ignore_regex;
-$opt_check_regex = $default_check_regex if ! length $opt_check_regex;
-
-if ($opt_noconf) {
+GetOptions(\%OPT,
+           "help|h",
+           "check|c=s",
+           "copyright",
+           "ignore|i=s",
+           "lines|l=i",
+           "machine|m",
+           "noconf|no-conf",
+           "print-defaults",
+           "recursive|r",
+           "tests",
+           "verbose!",
+           "version|v",
+) or die "Usage: $progname [options] filelist\nRun $progname --help for more details\n";
+
+$OPT{'lines'} = $def_lines if $OPT{'lines'} !~ /^[1-9][0-9]*$/;
+$OPT{'ignore_regex'} = $default_ignore_regex if ! length $OPT{'ignore_regex'};
+$OPT{'check_regex'} = $default_check_regex if ! length $OPT{'check_regex'};
+
+if ($OPT{'noconf'}) {
     fatal("--no-conf is only acceptable as the first command-line option!");
 }
-if ($opt_help) { help(); exit 0; }
-if ($opt_version) { version(); exit 0; }
+if ($OPT{'help'}) { help(); exit 0; }
+if ($OPT{'version'}) { version(); exit 0; }
 
 die "Usage: $progname [options] filelist\nRun $progname --help for more details\n" unless @ARGV;
 
-$opt_lines = $def_lines if not defined $opt_lines;
+$OPT{'lines'} = $def_lines if not defined $OPT{'lines'};
 
 my @files = ();
 my @find_args = ();
 my $files_count = @ARGV;
 
-push @find_args, qw(-maxdepth 1) unless $opt_recursive;
+push @find_args, qw(-maxdepth 1) unless $OPT{'recursive'};
 push @find_args, qw(-follow -type f -print);
 
 while (@ARGV) {
     my $file = shift @ARGV;
 
@@ -257,19 +263,19 @@ while (@ARGV) {
 	open my $FIND, '-|', 'find', $file, @find_args
 	    or die "$progname: couldn't exec find: $!\n";
 
 	while (<$FIND>) {
 	    chomp;
-	    next unless m%$opt_check_regex%;
+	    next unless m%$OPT{'check_regex'}%;
 	    # Skip empty files
 	    next if (-z $_);
-	    push @files, $_ unless m%$opt_ignore_regex%;
+	    push @files, $_ unless m%$OPT{'ignore_regex'}%;
 	}
 	close $FIND;
     } else {
-	next unless ($files_count == 1) or $file =~ m%$opt_check_regex%;
-	push @files, $file unless $file =~ m%$opt_ignore_regex%;
+	next unless ($files_count == 1) or $file =~ m%$OPT{'check_regex'}%;
+	push @files, $file unless $file =~ m%$OPT{'ignore_regex'}%;
     }
 }
 
 while (@files) {
     my $file = shift @files;
@@ -279,11 +285,11 @@ while (@files) {
     my $license = '';
     my %copyrights;
 
     open (my $F, '<' ,$file) or die "Unable to access $file\n";
     while (<$F>) {
-        last if ($. > $opt_lines);
+        last if ($. > $OPT{'lines'});
         $content .= $_;
 	$copyright_match = parse_copyright($_);
 	if ($copyright_match) {
 	    $copyrights{lc("$copyright_match")} = "$copyright_match";
 	}
@@ -291,31 +297,31 @@ while (@files) {
     close($F);
 
     $copyright = join(" / ", values %copyrights);
 
     print qq(----- $file header -----\n$content----- end header -----\n\n)
-	if $opt_verbose;
+	if $OPT{'verbose'};
 
     $content =~ tr/\t\r\n/ /;
     # Remove C / C++ comments
     $content =~ s#(\*/|/[/*])##g;
     $content =~ tr% A-Za-z.,@;0-9\(\)/-%%cd;
     $content =~ s/ c //g; # Remove fortran comments
     $content =~ tr/ //s;
 
     $license = parselicense($content);
-    if ($opt_machine) {
+    if ($OPT{'machine'}) {
 	print "$file\t$license";
-	print "\t" . ($copyright or "*No copyright*") if $opt_copyright;
+	print "\t" . ($copyright or "*No copyright*") if $OPT{'copyright'};
 	print "\n";
     } else {
 	print "$file: ";
 	print "*No copyright* " unless $copyright;
 	print $license . "\n";
 	print "  [Copyright: " . $copyright . "]\n"
-	  if $copyright and $opt_copyright;
-	print "\n" if $opt_copyright;
+	  if $copyright and $OPT{'copyright'};
+	print "\n" if $OPT{'copyright'};
     }
 }
 
 sub parse_copyright {
     my $copyright = '';
-- 
1.7.10.4

From ea1ec0d1d3b14b334801ad4660a41c76f7bfd437 Mon Sep 17 00:00:00 2001
From: Dmitry Smirnov <[email protected]>
Date: Wed, 10 Oct 2012 17:56:45 +1100
Subject: [PATCH 5/5] comments cleaning to dedicated function + code to remove
 any regular comments pattern

---
 scripts/licensecheck.pl |   37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/scripts/licensecheck.pl b/scripts/licensecheck.pl
index 46d2039..c345e73 100755
--- a/scripts/licensecheck.pl
+++ b/scripts/licensecheck.pl
@@ -299,18 +299,12 @@ while (@files) {
     $copyright = join(" / ", values %copyrights);
 
     print qq(----- $file header -----\n$content----- end header -----\n\n)
 	if $OPT{'verbose'};
 
-    $content =~ tr/\t\r\n/ /;
-    # Remove C / C++ comments
-    $content =~ s#(\*/|/[/*])##g;
-    $content =~ tr% A-Za-z.,@;0-9\(\)/-%%cd;
-    $content =~ s/ c //g; # Remove fortran comments
-    $content =~ tr/ //s;
+    $license = parselicense(clean_comments($content));
 
-    $license = parselicense($content);
     if ($OPT{'machine'}) {
 	print "$file\t$license";
 	print "\t" . ($copyright or "*No copyright*") if $OPT{'copyright'};
 	print "\n";
     } else {
@@ -356,10 +350,39 @@ sub parse_copyright {
     }
 
     return $copyright;
 }
 
+sub clean_comments {
+    local $_=shift or return q{};
+
+    # remove generic comments: look for 4 or more lines beginning with
+    # regular comment pattern and trim it. Fall back to old algorithm
+    # if no such pattern found.
+    if( 4 <= scalar(()=m{ ^\s*
+                           ([^a-zA-Z0-9\s]{1,3})
+                           \s\w
+                       }xmg)
+    ){
+        my $comment_length=length($1);
+        my $comment_re=qr{\s*  [$1]{${comment_length}}  \s*}x;
+        s/^$comment_re//mg;
+    }
+
+    # Remove Fortran comments
+    s/^[cC] //gm;
+    tr/\t\r\n/ /;
+
+    # Remove C / C++ comments
+    s#(\*/|/[/*])##g;
+    tr% A-Za-z.,@;0-9\(\)/-%%cd;
+    tr/ //s;
+
+return $_;
+}
+
+
 sub help {
    print <<"EOF";
 Usage: $progname [options] filename [filename ...]
 Valid options are:
    --help, -h             Display this message
-- 
1.7.10.4

From bec4a69cfa7d7c55940a20de9a761c63f343ac7c Mon Sep 17 00:00:00 2001
From: Dmitry Smirnov <[email protected]>
Date: Tue, 9 Oct 2012 03:24:20 +1100
Subject: [PATCH 2/5] licensecheck: removing function prototypes [perl best
 practice]

---
 scripts/licensecheck.pl |   12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/scripts/licensecheck.pl b/scripts/licensecheck.pl
index 815b507..10546d8 100755
--- a/scripts/licensecheck.pl
+++ b/scripts/licensecheck.pl
@@ -134,14 +134,10 @@ Adam D. Barratt <[email protected]>
 use strict;
 use warnings;
 use Getopt::Long qw(:config gnu_getopt);
 use File::Basename;
 
-sub fatal($);
-sub parse_copyright($);
-sub parselicense($);
-
 my $progname = basename($0);
 
 # From dpkg-source
 my $default_ignore_regex = '
 # Ignore general backup files
@@ -236,11 +232,11 @@ GetOptions("help|h" => \$opt_help,
 $opt_lines = $def_lines if $opt_lines !~ /^[1-9][0-9]*$/;
 $opt_ignore_regex = $default_ignore_regex if ! length $opt_ignore_regex;
 $opt_check_regex = $default_check_regex if ! length $opt_check_regex;
 
 if ($opt_noconf) {
-    fatal "--no-conf is only acceptable as the first command-line option!";
+    fatal("--no-conf is only acceptable as the first command-line option!");
 }
 if ($opt_help) { help(); exit 0; }
 if ($opt_version) { version(); exit 0; }
 
 die "Usage: $progname [options] filelist\nRun $progname --help for more details\n" unless @ARGV;
@@ -319,11 +315,11 @@ while (@files) {
 	  if $copyright and $opt_copyright;
 	print "\n" if $opt_copyright;
     }
 }
 
-sub parse_copyright($) {
+sub parse_copyright {
     my $copyright = '';
     my $match;
 
     my $copyright_indicator_regex = '
 	(?:copyright	# The full word
@@ -396,11 +392,11 @@ You are free to redistribute this code under the terms of the
 GNU General Public License, version 2, or (at your option) any
 later version.
 EOF
 }
 
-sub parselicense($) {
+sub parselicense {
     my ($licensetext) = @_;
 
     my $gplver = "";
     my $extrainfo = "";
     my $license = "";
@@ -564,11 +560,11 @@ sub parselicense($) {
     $license =~ s/\s+$//;
 
     return $license;
 }
 
-sub fatal($) {
+sub fatal {
     my ($pack,$file,$line);
     ($pack,$file,$line) = caller();
     (my $msg = "$progname: fatal error at line $line:\n@_\n") =~ tr/\0//d;
     $msg =~ s/\n\n$/\n/;
     die $msg;
-- 
1.7.10.4

From 9fd72c3a79eb487975b3582ae19d12fb79ae92f8 Mon Sep 17 00:00:00 2001
From: Dmitry Smirnov <[email protected]>
Date: Wed, 10 Oct 2012 18:12:29 +1100
Subject: [PATCH 3/5] bugfix: detect GPL license version

---
 scripts/licensecheck.pl |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/licensecheck.pl b/scripts/licensecheck.pl
index 10546d8..f8cc890 100755
--- a/scripts/licensecheck.pl
+++ b/scripts/licensecheck.pl
@@ -400,11 +400,11 @@ sub parselicense {
     my $gplver = "";
     my $extrainfo = "";
     my $license = "";
 
     if ($licensetext =~ /version ([^, ]+?)[.,]? (?:\(?only\)?.? )?(?:of the GNU (Affero )?(Lesser |Library )?General Public License )?(as )?published by the Free Software Foundation/i or
-	$licensetext =~ /GNU (?:Affero )?(?:Lesser |Library )?General Public License (?:as )?published by the Free Software Foundation; version ([^, ]+?)[.,]? /i) {
+	$licensetext =~ /GNU (?:Affero )?(?:Lesser |Library )?General Public License (?:as )?published by the Free Software Foundation[;,] version ([^, ]+?)[.,]? /i) {
 
 	$gplver = " (v$1)";
     } elsif ($licensetext =~ /GNU (?:Affero )?(?:Lesser |Library )?General Public License, version (\d+(?:\.\d+)?)[ \.]/) {
 	$gplver = " (v$1)";
     } elsif ($licensetext =~ /either version ([^ ]+)(?: of the License)?, or \(at your option\) any later version/) {
-- 
1.7.10.4

_______________________________________________
devscripts-devel mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/devscripts-devel

Reply via email to