license_trailer: avoid bogus bare "GPL" matches
[gnulib.git] / debian / clscan / clscan
index 594452d..8aac53b 100755 (executable)
@@ -17,8 +17,24 @@ our $FILESCACHE="$CLSCANDIR/files.yaml";
 our $NEWFILES="$CLSCANDIR/new.txt";
 our $COPYRIGHTSTUB="$CLSCANDIR/copyright.in";
 
+# FIXME: add boilerplate
+our %module_licenses= (
+    "public domain" => "",
+    "unlimited" =>
+        "This file is free software; the Free Software Foundation\n" .
+        "gives unlimited permission to copy and/or distribute it,\n" .
+        "with or without modifications, as long as this notice is preserved.\n",
+    "LGPL" => "",
+    "LGPLv2+" => "",
+    "unmodifiable license text" =>
+        "Everyone is permitted to copy and distribute verbatim copies\n" .
+        "of this license document, but changing it is not allowed.\n",
+    "GPLed build tool" => "",
+    "GPL" => "",
+);
+
 our @filenames=();
-our @modules=();
+our %overrides=();
 our $files={};
 our $new={};
 
@@ -51,6 +67,7 @@ sub scan
 sub merge
 {
     merge_new();
+    load_overrides();
     save_cache();
 }
 
@@ -137,15 +154,14 @@ sub license_trailer
     };
 
     my %types_found=();
-TYPE: for my $type (reverse sort keys(%$license_data))
+    for my $type (reverse sort keys(%$license_data))
     {
        for my $license (@licenses_used)
        {
-           if($license =~ /$type(\+|\b)/i)
+           if($license =~ /$type(\+|\s|$)/i)
            {
                $types_found{$type}=1;
-               # avoid matching eg GPL-2 *and* GPL
-               next TYPE;
+               print "FOUND $type [$license]\n";
            }
        }
     }
@@ -162,10 +178,10 @@ TYPE: for my $type (reverse sort keys(%$license_data))
        # more than one, use table.
        $text .= "The complete text of standard licenses referenced above\n";
        $text .= "can be found in /usr/share/common-licenses/ as follows:\n\n";
-       $text .= sprintf("%-70s %s\n", "LICENSE", "FILE");
+       $text .= sprintf("%-60s %s\n", "LICENSE", "FILE");
        for my $type (sort keys(%types_found))
        {
-           $text .= sprintf("%-70s %s\n", $license_data->{$type}, $type);
+           $text .= sprintf("%-60s %s\n", $license_data->{$type}, $type);
        }
     }
     return $text;
@@ -275,29 +291,21 @@ sub wanted_files
 
 sub wanted_modules
 {
-    if(/^\./ || /^README$/ || /^COPYING$/)
+    if(/^\.[^\/]/ || /^README$/ || /^COPYING$/)
     {
        $File::Find::prune=1;
+       return;
     }
     elsif(-f)
     {
-       push(@modules, $File::Find::name);
-    }
-}
-
-sub load_overrides
-{
-    find(\&wanted_modules, "modules/");
-    my %modules=();
-    for my $module (@modules)
-    {
-       unless(open(MOD, $module))
+       unless(open(MOD, $File::Find::name))
        {
-           warn("$me: cannot open $module: $!\n");
-           next;
+           warn("$me: cannot open $File::Find::name: $!\n");
+           return;
        }
        my $infiles=0;
        my $inlicense=0;
+       my @files=();
        while(<MOD>)
        {
            chomp;
@@ -307,12 +315,12 @@ sub load_overrides
            }
            if($inlicense)
            {
-               $modules{$module}->{license}=$_;
+               push(@{$overrides{$_}},@files);
                $inlicense=0;
            }
            elsif($infiles)
            {
-               push(@{$modules{$module}->{files}}, $_);
+               push(@files, $_);
            }
            elsif(/^License:/)
            {
@@ -327,6 +335,17 @@ sub load_overrides
     }
 }
 
+sub load_overrides
+{
+    find({ wanted => \&wanted_modules, no_chdir => 1}, "modules/");
+    for my $license (keys(%overrides))
+    {
+#      print("License: $license\n");
+#      print("Files: \n\t");
+#      print(join("\n\t", @{$overrides{$license}}),"\n");
+    }
+}
+
 
 sub load_cache
 {