-
Notifications
You must be signed in to change notification settings - Fork 84
/
add_copyright
executable file
·42 lines (38 loc) · 803 Bytes
/
add_copyright
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/perl
use strict;
# usage: add_copyright file... dir
my $dir = pop @ARGV;
if (not -d $dir) {
print "$dir is not a directory\n";
exit 1;
}
my $copyright = `cat copyright`;
my $copyright_oneline = `grep '(C)' copyright`;
$copyright_oneline =~ s/^\s*\*\s*//;
$copyright_oneline =~ s/[\r\n]//g;
foreach my $in (@ARGV) {
my $out = "$dir/$in";
if (not open IN, $in) {
print "cannot open $in: $!\n";
next;
}
if (not open OUT, ">$out") {
print "cannot create $out: $!\n";
close IN;
next
}
while (<IN>) {
if (/\@\@copyright\@\@/) {
print OUT $copyright;
} elsif (/\@\@copyright_oneline\@\@/) {
s/\@\@copyright_oneline\@\@/$copyright_oneline/;
print OUT;
} else {
print OUT;
}
}
close OUT;
close IN;
my $mode = (-x $in) ? 0555 : 0444;
chmod $mode, $out;
}