#!/usr/bin/perl -w

# Given a 3-column list "sloc build-directory-name spec-filename",
# output a 4-column list which appends the license.
# You'll need to fix this up afterwards.

$specdir = "/usr/src/redhat/SPECS";
$garbage = "";

while (<>) {
 ($sloc, $buildname, $specname, $garbage) = split;
 chomp($specname);
 print "$sloc $buildname $specname ";

 if (! (-f "$specdir/$specname")) {
    die "ERROR.  Cound not find spec file $specname\n";
 }


 # Get "Copyright:" or "License:"
 $license = "";
 $summary = "";
 open(SPECFILE, "<$specdir/$specname") || die "Can't open $specname\n";
 while (<SPECFILE>) {
   # print;
   if (m/^Summary\:(.*)/i) { $summary = $1; }
   if (m/^License\:(.*)/i) { $license = $1; }
   if ((! $license) && (m/^Copyright\:(.*)/i)) { $license = $1; }
 }
 close(SPECFILE);
 
 if ($license) {print "$license";}
 else          {print "?";}

 # print "\t";
 # print $summary;

 print "\n";
 
}
