/
update_header.sh
67 lines (61 loc) · 2.47 KB
/
update_header.sh
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
# Copyright (C) 2012,2013,2014 Olaf Lenz
#
# This file is part of ESPResSo.
#
# ESPResSo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Add current year to copyright header
#
# 1. Find files that do have copyright disclaimers
# 1.1. Find files that do not have the current year in the disclaimer
# 1.1.1. Find files that have "The ESPResSo project" in the line
# 1.1.1.1. Append 2012 to the years
# 1.1.2. Insert new line "Copyright (C) <current_year> The ESPResSo
# project" before the copyright disclaimer
#
files=`sh maintainer/files_with_header.sh`
num_files=`echo $files | wc -w`
current_year=`date +%Y`
echo "Examining $num_files files."
echo "Files with copyright disclaimer(s)..."
files=`egrep -l "Copyright" $files`
num_files=`echo $files | wc -w`
echo " $num_files files."
echo "Files that are missing the current year ($current_year) in the copyright disclaimer(s)..."
files=`egrep -L "Copyright.*$current_year" $files`
for file in $files; do
echo " $file"
done
noyear_files=`egrep -l "Copyright.*The ESPResSo project" $files`
echo " Adding current year to project copyright disclaimer..."
echo " \"$current_year\""
tmpfile=`mktemp`
for file in $noyear_files; do
echo " $file"
perl -pe "if (!\$done) { s/(Copyright\s+(?:\(C\)\s+)?\d+(?:\s*,\s*\d+)*)(\s+The ESPResSo project)/\1,$current_year\2/ and \$done=1; }" $file > $tmpfile
cat $tmpfile > $file
done
noproject_files=`egrep -L "Copyright.*The ESPResSo project" $files`
echo "Files that are missing the project copyright disclaimer..."
num_files=`echo $noproject_files | wc -w`
echo " $num_files files."
echo " Adding project copyright disclaimer..."
disclaimer="Copyright (C) $current_year The ESPResSo project"
echo " \"$disclaimer\""
for file in $noproject_files; do
echo " $file"
perl -pe "if (!\$done) { s/^(.*)Copyright/\1$disclaimer\n\1Copyright/ and \$done=1; }" $file > $tmpfile
cat $tmpfile > $file
done
rm $tmpfile