Package: devscripts
Version: 2.10.28
Severity: normal
File: /usr/bin/licensecheck
Tags: patch

The 'licensecheck' program has a parser for finding copyright notices 
in files, and can display notices found. The parser has some checks to 
avoid false positives.

The program will also show a "*No copyright*" warning for files that 
are judged to not contain a copyright notice. However, this check is
*not* done with the same copyright-notice parser; instead, this check 
is simply done with a dumb match of the text 'copyright' against the 
entire file.

Thus, some files that contain the word "copyright" can cause the "*No  
copyright* warning to be omitted, even though the copyright-notice 
parser will determine there is no actual copyright notice.

The attached patch refactors the copyright-notice parsing into a 
'parse_copyright' function, and uses this parser to determine whether 
or not to show the "*No copyright*" warning. This makes the warning 
consistent with the result of the copyright-notice parser.
=== modified file 'scripts/licensecheck.pl'
--- scripts/licensecheck.pl     2008-04-25 05:52:30 +0000
+++ scripts/licensecheck.pl     2008-06-12 23:13:27 +0000
@@ -125,6 +125,7 @@
 use File::Basename;
 
 sub fatal($);
+sub parse_copyright($);
 sub parselicense($);
 
 my $progname = basename($0);
@@ -260,28 +261,19 @@
 while (@files) {
     my $file = shift @files;
     my $content = '';
+    my $copyright_match;
     my $copyright = '';
+    my $license = '';
     my %copyrights;
-    my $match;
 
     open (F, "<$file") or die "Unable to access $file\n";
     while (<F>) {
         last if ($. > $opt_lines);
         $content .= $_;
-       if (m%copyright(?::\s*|\s+)(\S.*)$%i) {
-           $match = $1;
-           # Ignore lines matching "see foo for copyright information"
-           if ($match !~ m%^\s*info(rmation)?\.?\s*$%i) {
-               # De-cruft
-               $match =~ s/([,.])?\s*$//;
-               $match =~ s/(\(C\)|\x{00a9})//i;
-               $match =~ s/^\s+//;
-               $match =~ s/\s{2,}/ /g;
-               $match =~ s/\\@/@/g;
-
-               $copyrights{lc("$match")} = "$match";
-           }
-       }
+        $copyright_match = parse_copyright($_);
+        if ($copyright_match) {
+            $copyrights{lc("$copyright_match")} = "$copyright_match";
+        }
     }
     close(F);
 
@@ -295,12 +287,37 @@
     $content =~ s#//##g;
     $content =~ tr/ //s;
 
-    print "$file: " . parselicense($content) . "\n";
+    $license = parselicense($content);
+    print "$file: ";
+    print "*No copyright* " unless $copyright;
+    print $license . "\n";
     print "  [Copyright: " . $copyright . "]\n"
       if $copyright and $opt_copyright;
     print "\n" if $opt_copyright;
 }
 
+sub parse_copyright($) {
+    my $copyright = '';
+    my $match;
+
+    if (m%copyright(?::\s*|\s+)(\S.*)$%i) {
+        $match = $1;
+        # Ignore lines matching "see foo for copyright information"
+        if ($match !~ m%^\s*info(rmation)?\.?\s*$%i) {
+           # De-cruft
+            $match =~ s/([,.])?\s*$//;
+            $match =~ s/(\(C\)|\x{00a9})//i;
+            $match =~ s/^\s+//;
+            $match =~ s/\s{2,}/ /g;
+            $match =~ s/\\@/@/g;
+
+            $copyright = $match;
+        }
+    }
+
+    return $copyright;
+}
+
 sub help {
    print <<"EOF";
 Usage: $progname [options] filename [filename ...]
@@ -433,10 +450,6 @@
 
     $license = "UNKNOWN" if (!length($license));
 
-    if ($licensetext !~ /copyright/i) {
-       $license = "*No copyright* $license";
-    }
-
     return $license;
 }
 

Reply via email to