update-copyright 2.28 KB
Newer Older
Per Cederqvist's avatar
Per Cederqvist committed
1
#!/bin/bash
Per Cederqvist's avatar
Per Cederqvist committed
2
3
# $Id: update-copyright,v 1.9 2003/08/23 13:39:59 ceder Exp $
# Copyright (C) 1994-1996, 1999, 2003  Lysator Academic Computer Association.
Per Cederqvist's avatar
Per Cederqvist committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#
# This program 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 2, or (at your option)
# any later version.
#
# This program 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, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
Per Cederqvist's avatar
Per Cederqvist committed
19
# Please report bugs at http://bugzilla.lysator.liu.se/.
Per Cederqvist's avatar
Per Cederqvist committed
20
21
22
23
24

# This file updates the copyright lines found in the programs, making
# sure that every year that the file is edited appears in the
# copyright line.

Per Cederqvist's avatar
Per Cederqvist committed
25
26
while read file
do
Per Cederqvist's avatar
Per Cederqvist committed
27
28
29
30
    if grep '[C]opyright' $file > /tmp/$$.yc ; then : ; 
    else echo "$file:1: no Copy"right" line found" >&2 ; continue;
    fi
    tr , '\012' < /tmp/$$.yc \
31
32
33
34
	| sed -n \
	   -e 's/.*\([12][0-9][0-9][0-9]\)-\([12][0-9][0-9][0-9]\).*/\1 \2/p' \
	   -e 's/.*\([12][0-9][0-9][0-9]\).*/\1/p' \
	| awk 'NF == 2 { for(i=$1; i<=$2; ++i) print i } NF == 1' \
Per Cederqvist's avatar
Per Cederqvist committed
35
	> /tmp/$$.year
Per Cederqvist's avatar
Per Cederqvist committed
36
37
38
39
    if cvs log $file > /tmp/$$.yc ; then : ;
    else echo "$file:1: cvs log failed" >&2 ; continue;
    fi
    cat /tmp/$$.yc \
Per Cederqvist's avatar
Per Cederqvist committed
40
41
	| sed -n 's/^date: \([0-9][0-9][0-9][0-9]\).*author.*state.*$/\1/p' \
	| sort | uniq >> /tmp/$$.year
Per Cederqvist's avatar
Per Cederqvist committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
    y=`sort /tmp/$$.year \
	| uniq \
	| (read first ; echo -n $first; next=\`expr $first + 1\`; rest=; \
	   while read second; \
	   do \
		if [ $second = $next ]; \
		then \
		    rest="-$next"; \
		else \
		    echo -n $rest, $second; \
		    rest=; \
		fi; \
		next=\`expr $second + 1\`; \
	   done; \
	   echo -n $rest)`
    sed 's/\([C]opyright[^0-9]*\)[---0-9 ,]*[0-9]\([^0-9]*\)/\1'"$y"'\2/' \
Per Cederqvist's avatar
Per Cederqvist committed
58
	< $file > /tmp/$$.file
Per Cederqvist's avatar
Per Cederqvist committed
59
60
    cmp /tmp/$$.file $file >/dev/null
    if [ $? = 1 ]; then
Per Cederqvist's avatar
Per Cederqvist committed
61
62
63
64
65
66
	if [ -x $file ]; then
	    cat /tmp/$$.file > $file;
	    chmod +x $file
	else
	    cat /tmp/$$.file > $file;
	fi
Per Cederqvist's avatar
Per Cederqvist committed
67
68
	echo $file updated
    fi
Per Cederqvist's avatar
Per Cederqvist committed
69
    rm /tmp/$$.file /tmp/$$.yc /tmp/$$.year
Per Cederqvist's avatar
Per Cederqvist committed
70
done