Newer
Older
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
#!/usr/bin/perl
# update copyright messgage in source file, sandwiched by CVS operations
# *Please* do this with no files active from cvs and a clean build expected
# mh17 03 Mar 2010
# Copyright(c) 2010 Genome Research Limited
# test data in CopyRight.txt, copy to a header first the run over it (the other file)
# to use on ZMap try:
#
# find ~/zmap/ZMap/src -name "*.c" -exec ./CopyRight \{\} \;
# find ~/zmap/ZMap/src -name "*.h" -exec ./CopyRight \{\} \;
#
use warnings;
my ($file, $date_found, $date_changed,$file_date,$new_date);
my ($ofile);
my ($year_now);
my $CVS = 1; # use the CVS
my $many = 0; # change more than one: good for testing
sub change_date
{
for(@_) # process our one argument directly
{
# our copyright? let's enforce nice capitalised words
if(/Copyright/ && /Genome/)
{
if(m/(\d+)[- ]+(\d+)/)
{
$date_found = 1;
$file_date = $1. '-' .$2;
if($2 != $year_now)
{
s/(\d+)[- ]+(\d+)/$1-$year_now/;
$date_changed = 1;
$new_date = "$1-$year_now";
}
}
elsif(m/(\d+)/)
{
$date_found = 1;
$file_date = $1;
if($1 != $year_now)
{
s/(\d+)/$1-$year_now/;
$date_changed = 1;
}
$new_date = "$1-$year_now";
}
if($date_changed)
{
print "Date changed from $file_date to $new_date\n";
}
}
}
}
$file = shift @ARGV; # we take one arg only
if(!$file)
{
print "No file!\n";
exit;
}
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
print "$file: ";
@time = localtime;
$new_date = $year_now = $time[5] + 1900;
$file_date = "??";
$date_found = 0;
$date_changed = 0;
$lineno = 0;
if($CVS)
{
@args = ("cvs", "edit", $file);
system(@args) or die("Cannot checkout $file from CVS\n");
}
open(IFILE,$file) or die("cannot open $file\n");
$ofile = $file . ".tmp"; # make tmp file in same directory
$year_now = 2010;
open(OFILE,"> ".$ofile) or die("cannot open $ofile\n");
while($line = <IFILE>)
{
$lineno++;
if($lineno < 50 && (!$date_found || $many))
{
change_date($line);
}
print OFILE $line;
}
close $ofile;
if(!$date_found)
{
print "No copyright date found\n";
}
if($date_changed)
{
unlink $file or die ("Can't remove old file\n");
rename($ofile,$file) or die("Can't update file\n");
if($CVS)
{
@args = ("cvs", "commit", "-m", "CopyRight date set", $file);
system(@args) or die("Copyright date set but cannot commit $file to CVS\n");
}
}
else
{
if($date_found)
{
print "Copyright date was $file_date: not changed\n";
}
unlink $ofile;
if($CVS)
{
@args = ("cvs", "unedit", $file);
system(@args) or die("Can't CVS unedit file\n");
}
}