-#!/usr/bin/rc
+#!/usr/bin/perl
## DOC: cran2deb copy_find path
## DOC: a tool for finding (heuristically) some copyright notices.
## DOC:
-kwords='copyright|warranty|redistribution|modification|patent|trademark|licen[cs]e|permission'
-nl=`` () {printf '\n'}
-ifs=$nl {
- files=`{find $1 ! -path '*debian*' -type f}
- lines=()
- for (file in $files) {
- notices=`{grep -H '(C)' $file}
- notices=($notices `{grep -HEi $kwords $file})
- lines=($lines `{{for (notice in $notices) echo $notice} | sort -u})
+
+use warnings;
+use strict;
+
+use File::Find qw(find);
+
+my $keywords='\(C\)|©|copyright|warranty|redistribution|modification|patent|trademark|licen[cs]e|permission';
+my @files;
+
+find(sub {if (-f $File::Find::name && $File::Find::name !~ /debian/) {push @files,$File::Find::name} },@ARGV);
+
+my @missing_copyright;
+my %copyright_notices;
+for my $file (@files) {
+ my $fh = IO::File->new($file,'r') or die "Unable to open '$file' for reading: $!";
+ my $has_copyright = 0;
+ my $lines=0;
+ my $chars=0;
+ while (<$fh>) {
+ $chars+=length($_);
+ $lines++;
+ chomp;
+ if (/\Q$keywords\E/) {
+ $copyright_notices{$_} = $_;
+ $has_copyright = 1;
+ }
}
- # let's hope no file has a : in it
- ifs=() { seen_files=`{{for (line in $lines) echo $line} | cut -d: -f1} }
- missing_copyright=()
- for (file in $files) {
- if (echo -n $seen_files | grep -q '^'^$file^'$') {
- } else {
- missing_copyright=($missing_copyright $file)
- }
- }
- echo 'Suspect copyright notices:'
- for (line in $lines) echo ' '$line
- echo 'Files without *suspect* copyright notices:'
- for (missing in $missing_copyright) {
- echo ' '$missing
- echo ' type: '`{file $missing}
- echo ' chars: '`{wc -c $missing | awk '{print $1}'}
- echo ' lines: '`{wc -l $missing | awk '{print $1}'}
+ if (not $has_copyright) {
+ push @missing_copyright,[$file,$lines,$chars];
}
}
+print "Suspect copyright notices:\n";
+for my $notice (keys %copyright_notices) {
+ print ' '.$copyright_notices{$notice}."\n";
+}
+print "Files without *suspect* copyright notices:\n";
+for my $fr (@missing_copyright) {
+ print ' '.$fr->[0]."\n";
+ print ' '.call_file($fr->[0])."\n";
+ print ' chars:'.$fr->[1]."\n";
+ print ' lines:'.$fr->[2]."\n";
+}
+
+sub call_file{
+ my ($file) = @_;
+ my $file_fh;
+ my $result;
+ open($file_fh,"-|",'file',$file);
+ local $\;
+ $result = <$file_fh>;
+ chomp $result;
+ return $result;
+}