copyright-extractor revision 19125
10017N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10017N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
use strict;
use warnings;
use Cwd;
my %blurbs;
my @files_omitted;
my $arg = shift;
my $fname = shift;
if ($fname =~ /([~]$|\/(ChangeLog|configure\.in|Makefile|ltmain\.sh|README|NEWS|INSTALL|HACKING|configure$|config\.)$)/) {
return FTYPE_IGNORE;
return FTYPE_IGNORE;
return FTYPE_C;
return FTYPE_PERL;
return FTYPE_PYTHON;
return FTYPE_SHELL;
return FTYPE_JAVA;
return FTYPE_IGNORE;
my $str = shift;
if ($str =~ /(licen[cs]|legal|terms|condition|copyright|rights|\(c\)|copying|usage|binary|distribut|gpl)/) {
my $fname = shift;
my $blurb;
my $line;
$line =~ s/^\s*-\*-.*-\*-\s*$//;
my $fname = shift;
my $blurb;
my $in_comment_block = 0;
my $line;
$line =~ s/\*\/.*//;
$in_comment_block = 0;
$line =~ s/^\/\///;
$in_comment_block = 1;
$line =~ s/^\s*\/\*//;
$line =~ s/^\s*\/\///;
last;
$line =~ s/^\s*-\*-.*-\*-\s*$//;
$line =~ s/^\s*\**\s*\@-type\@\s*$//;
my $fname = shift;
my $blurb;
my $in_comment_block = 0;
my $line;
$in_comment_block = 0;
$in_comment_block = 1;
} elsif ($line eq '') {
$line =~ s/^\s*-\*-.*-\*-\s*$//;
$line =~ s/^\s*vim(:\S+=\S+)+\s*$//;
$line =~ s/^\s\$Id:.*\$\s*$//;
chomp ($line);
if (defined $blurb) {
} elsif ($line ne '') {
$line = undef;
my $fname = shift;
if (-d $fname) {
} elsif (-f $fname) {
return if $ftype == FTYPE_IGNORE;
if ($ftype == FTYPE_C) {
extract_comments_c ($fname);
} elsif ($ftype == FTYPE_PERL) {
extract_comments_shell ($fname);
} elsif ($ftype == FTYPE_SHELL) {
extract_comments_shell ($fname);
} elsif ($ftype == FTYPE_PYTHON) {
extract_comments_python ($fname);
} elsif ($ftype == FTYPE_JAVA) {
extract_comments_c ($fname);
my $prev;
my @uniq_list = ($prev);
foreach my $str (@list) {
push (@uniq_list, $str);
my $str = shift;
return ($str =~ tr/\n//) + 1;
my $str = shift;
if ($str eq $s) {
my $ml1_ref = shift;
my $l1_ref = shift;
my $nl1_ref = shift;
my $l2_ref = shift;
my $nl2_ref = shift;
my @mlines1 = @$ml1_ref;
my @lines1 = @$l1_ref;
my @norm_lines1 = @$nl1_ref;
my @lines2 = @$l2_ref;
my @norm_lines2 = @$nl2_ref;
my $line1;
my $norm_line1;
my $line2;
my $norm_line2;
if ($debug > 2) {
$line1 = shift (@lines1);
$norm_line1 = shift (@norm_lines1);
if (($norm_line1 ne '') and
is_member ($norm_line1, @norm_lines2)) {
push (@mlines1, $line1);
push (@nmlines1, $norm_line1);
$line2 = shift (@lines2);
$norm_line2 = shift (@norm_lines2);
if ($norm_line2 ne $norm_line1) {
push (@mlines2, $line2);
push (@nmlines2, $line2);
if ($norm_line1 eq $norm_line2) {
if ($debug > 3) {
@common_lines = ($line1);
@ncommon_lines = ($norm_line2);
$line1 = shift (@lines1);
$norm_line1 = shift (@norm_lines1);
$line2 = shift (@lines2);
$norm_line2 = shift (@norm_lines2);
if ($norm_line1 ne $norm_line2) {
if ($debug > 3) {
unshift (@lines1, $line1);
unshift (@norm_lines1, $norm_line1);
unshift (@lines2, $line2);
unshift (@norm_lines2, $norm_line2);
if ($debug > 3) {
push (@common_lines, $line1);
push (@ncommon_lines, $norm_line1);
# only merge if the number of common lines is at least $min_merge
if (($#common_lines >= $min_merge) or
if ($debug > 1) {
my $str1 = shift;
my $str2 = shift;
my @lines1 = split /\n/, $str1;
my @lines2 = split /\n/, $str2;
foreach my $l0 (@lines1) {
$l1 =~ s/\s+/ /g;
$l1 =~ s/^ //g;
chomp ($l1);
$l1 =~ s/ $//g;
push (@norm_lines1, $l1);
foreach my $l0 (@lines2) {
$l2 =~ s/\s+/ /g;
$l2 =~ s/^ //g;
chomp ($l2);
$l2 =~ s/ $//g;
push (@norm_lines2, $l2);
my $merged_str;
if ($copyright_first) {
foreach my $line (@merged_lines) {
if ($line =~ /^\s*(copyright|\(c\)|©|author:|all rights reserved)/i) {
push (@copyright_lines, $line);
push (@non_cr_lines, $line);
return $merged_str;
foreach my $fname (keys %blurbs) {
if ($blurbs{$fname} =~ /\b(gpl|lgpl|gnu\s+(library\s+|lesser\s+|)general\s+public\s+license)\b/si) {
$gpl_found = 1;
my $did_merge = 0;
my $c1 = $temp_all_comments[$i];
my $c2 = $temp_all_comments[$j];
my $c12_merged = merge_comments ($c1, $c2);
my $c12_lc = line_count ($c12_merged);
if ($debug > 0) {
$temp_all_comments[$j] = $c12_merged;
$did_merge = 1;
if (not $did_merge) {
push (@all_comments, $c1);
if ($gpl_found and $gpl_disclaimer) {
foreach my $comment (@all_comments) {
print $comment;
my $srcdir;
foreach my $srcdir (@dirs) {
if ($srcdir =~ /^\./) {
$srcdir = getcwd();
extract_comments ($srcdir);
if (not $dumb_mode) {
if ($print_omitted and @files_omitted) {
foreach my $fname (@files_omitted) {