216
217
$modified_conf_msg ||= " (none)\n";
217
218
chomp $modified_conf_msg;
219
$opt_verbose = $config_vars{'LICENSECHECK_VERBOSE'} eq 'yes' ? 1 : 0;
220
$opt_lines = $config_vars{'LICENSECHECK_PARSELINES'};
223
GetOptions("help|h" => \$opt_help,
224
"version|v" => \$opt_version,
225
"verbose!" => \$opt_verbose,
226
"lines|l=i" => \$opt_lines,
227
"ignore|i=s" => \$opt_ignore_regex,
228
"recursive|r" => \$opt_recursive,
229
"check|c=s" => \$opt_check_regex,
230
"copyright" => \$opt_copyright,
231
"machine|m" => \$opt_machine,
232
"noconf" => \$opt_noconf,
233
"no-conf" => \$opt_noconf,
235
or die "Usage: $progname [options] filelist\nRun $progname --help for more details\n";
237
$opt_lines = $def_lines if $opt_lines !~ /^[1-9][0-9]*$/;
238
$opt_ignore_regex = $default_ignore_regex if ! length $opt_ignore_regex;
239
$opt_check_regex = $default_check_regex if ! length $opt_check_regex;
242
fatal "--no-conf is only acceptable as the first command-line option!";
244
if ($opt_help) { help(); exit 0; }
245
if ($opt_version) { version(); exit 0; }
220
$OPT{'verbose'} = $config_vars{'LICENSECHECK_VERBOSE'} eq 'yes' ? 1 : 0;
221
$OPT{'lines'} = $config_vars{'LICENSECHECK_PARSELINES'};
235
) or die "Usage: $progname [options] filelist\nRun $progname --help for more details\n";
237
$OPT{'lines'} = $def_lines if $OPT{'lines'} !~ /^[1-9][0-9]*$/;
238
$OPT{'ignore'} = $default_ignore_regex if ! length $OPT{'ignore'};
239
$OPT{'check'} = $default_check_regex if ! length $OPT{'check'};
241
if ($OPT{'noconf'}) {
242
fatal("--no-conf is only acceptable as the first command-line option!");
244
if ($OPT{'help'}) { help(); exit 0; }
245
if ($OPT{'version'}) { version(); exit 0; }
247
247
die "Usage: $progname [options] filelist\nRun $progname --help for more details\n" unless @ARGV;
249
$opt_lines = $def_lines if not defined $opt_lines;
249
$OPT{'lines'} = $def_lines if not defined $OPT{'lines'};
252
252
my @find_args = ();
253
253
my $files_count = @ARGV;
255
push @find_args, qw(-maxdepth 1) unless $opt_recursive;
255
push @find_args, qw(-maxdepth 1) unless $OPT{'recursive'};
256
256
push @find_args, qw(-follow -type f -print);
259
259
my $file = shift @ARGV;
262
open FIND, '-|', 'find', $file, @find_args
262
open my $FIND, '-|', 'find', $file, @find_args
263
263
or die "$progname: couldn't exec find: $!\n";
267
next unless m%$opt_check_regex%;
267
next unless m%$OPT{'check'}%;
268
268
# Skip empty files
270
push @files, $_ unless m%$opt_ignore_regex%;
270
push @files, $_ unless m%$OPT{'ignore'}%;
274
next unless ($files_count == 1) or $file =~ m%$opt_check_regex%;
275
push @files, $file unless $file =~ m%$opt_ignore_regex%;
274
next unless ($files_count == 1) or $file =~ m%$OPT{'check'}%;
275
push @files, $file unless $file =~ m%$OPT{'ignore'}%;
284
284
my $license = '';
287
open (F, "<$file") or die "Unable to access $file\n";
289
last if ($. > $opt_lines);
287
open (my $F, '<' ,$file) or die "Unable to access $file\n";
289
last if ($. > $OPT{'lines'});
291
291
$copyright_match = parse_copyright($_);
292
292
if ($copyright_match) {
293
293
$copyrights{lc("$copyright_match")} = "$copyright_match";
298
298
$copyright = join(" / ", values %copyrights);
300
300
print qq(----- $file header -----\n$content----- end header -----\n\n)
303
# Remove Fortran comments
304
$content =~ s/^[cC] //gm;
305
$content =~ tr/\t\r\n/ /;
306
# Remove C / C++ comments
307
$content =~ s#(\*/|/[/*])##g;
308
$content =~ tr% A-Za-z.,@;0-9\(\)/-%%cd;
311
$license = parselicense($content);
303
$license = parselicense(clean_comments($content));
305
if ($OPT{'machine'}) {
313
306
print "$file\t$license";
314
print "\t" . ($copyright or "*No copyright*") if $opt_copyright;
307
print "\t" . ($copyright or "*No copyright*") if $OPT{'copyright'};
318
311
print "*No copyright* " unless $copyright;
319
312
print $license . "\n";
320
313
print " [Copyright: " . $copyright . "]\n"
321
if $copyright and $opt_copyright;
322
print "\n" if $opt_copyright;
314
if $copyright and $OPT{'copyright'};
315
print "\n" if $OPT{'copyright'};
326
sub parse_copyright($) {
319
sub parse_copyright {
327
320
my $copyright = '';
358
351
return $copyright;
355
local $_ = shift or return q{};
357
# Remove generic comments: look for 4 or more lines beginning with
358
# regular comment pattern and trim it. Fall back to old algorithm
359
# if no such pattern found.
360
if( 4 <= scalar(()=m{ ^\s*
361
([^a-zA-Z0-9\s]{1,3})
365
my $comment_length=length($1);
366
my $comment_re=qr{\s* [$1]{${comment_length}} \s*}x;
370
# Remove Fortran comments
374
# Remove C / C++ comments
376
tr% A-Za-z.,@;0-9\(\)/-%%cd;
363
384
Usage: $progname [options] filename [filename ...]
408
429
my $license = "";
410
431
if ($licensetext =~ /version ([^, ]+?)[.,]? (?:\(?only\)?.? )?(?:of the GNU (Affero )?(Lesser |Library )?General Public License )?(as )?published by the Free Software Foundation/i or
411
$licensetext =~ /GNU (?:Affero )?(?:Lesser |Library )?General Public License (?:as )?published by the Free Software Foundation; version ([^, ]+?)[.,]? /i) {
432
$licensetext =~ /GNU (?:Affero )?(?:Lesser |Library )?General Public License (?:as )?published by the Free Software Foundation[;,] version ([^, ]+?)[.,]? /i) {
413
434
$gplver = " (v$1)";
414
435
} elsif ($licensetext =~ /GNU (?:Affero )?(?:Lesser |Library )?General Public License, version (\d+(?:\.\d+)?)[ \.]/) {
471
492
if ($licensetext =~ /THIS SOFTWARE IS PROVIDED .*AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY/) {
472
493
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) {
473
494
$license = "BSD (4 clause) $license";
474
} 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) {
495
} 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) {
475
496
$license = "BSD (3 clause) $license";
476
497
} elsif ($licensetext =~ /Redistributions of source code must retain the above copyright notice/i) {
477
498
$license = "BSD (2 clause) $license";