-
Notifications
You must be signed in to change notification settings - Fork 33
/
copydate
executable file
·84 lines (74 loc) · 1.45 KB
/
copydate
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/local/bin/perl
use File::Find;
use Time::Local;
my $year = (gmtime)[5];
my $yt = timegm(0,0,0,1,0,$year);
$year += 1900;
my $last = $year-1;
warn "This is $year\n";
# $expr = shift;
sub match
{
if (/Copyright/i && /Nick/ && !/$year/)
{
print "$File::Find::dir/$file:$.:$_"
}
return 0;
}
sub wanted
{
my $write = -w $_;
$File::Find::prune = 0;
if (-T $_ && !/[%~]$/ && !/\.bak/ && (stat($_))[9] >= $yt)
{
if (/\.c$/)
{
my $xs = $_;
$xs =~ s/\.c$/.xs/;
return if -f $xs;
}
local $file = ($_);
local ($_);
@ARGV = ($file);
my $changed = 0;
$^I = '.bak';
while (<>)
{
if (/Copyright/i && /Nick/ && s/--$year/-$year/)
{
warn "$File::Find::name:$.:$_";
$changed++;
}
if (/Copyright/i && /Nick/ && /(199|200)[0-9]/ && !/$year/)
{
$changed++;
unless (s/((199|200)[0-9]-)(199|200)[0-9]/$1$year/)
{
unless (s/$last/$last-$year/)
{
unless (s/((199|200)[0-9])/$1-$year/)
{
die "$File::Find::name:$.:$_"
}
}
}
warn "$File::Find::name:$.:$_"
}
print;
}
if ($changed)
{
print "p4 edit $File::Find::name\n";
}
else
{
rename("$file.bak",$file) || die "Cannot rename $file.bak to $file:$!";
}
}
elsif (-d $_)
{
# $File::Find::prune = 1 if ($_ eq 'mTk');
}
}
@ARGV = '.' unless (@ARGV);
find(\&wanted,@ARGV);