summaryrefslogtreecommitdiffstats
path: root/bin/chkcopyright
blob: c217743d4fa6c5672cfb01a70fdd772215dbe49e (plain)
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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#! /bin/sh
##
## Copyright by the Board of Trustees of the University of Illinois.
## All rights reserved.
##
## This file is part of HDF5.  The full HDF5 copyright notice, including
## terms governing use, modification, and redistribution, is contained in
## the files COPYING and Copyright.html.  COPYING can be found at the root
## of the source code distribution tree; Copyright.html can be found at the
## root level of an installed copy of the electronic HDF5 document set and
## is linked from the top-level documents page.  It can also be found at
## http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have
## access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu.
##

# Check Copyright notice.
# Check that all the files have the proper copyright notice.
# It goes down directories recursively.
#
# Programmer: Albert Cheng
# Created Data: 2003/07/22

PROGNAME=$0
DIFF="diff"
COPYRIGHTFILE=/tmp/copy.$$
EXTRACTEDFILE=/tmp/extracted.$$
VERBOSE=		# default no
DIRS=.			# default current directory


USAGE()
{
    cat <<EOF
Usage: $PROGNAME [-h | -help] [-fname name-patter] [-v | -v9] [dir1 dir2 ...]
    Check copyright notices of files in [dir1 dir2 ...}.
    Default is to check files in current directory.
    -h | -help
	show this page.
    -fname name-pattern
        limit to files of name-pattern
    -v
	verbose mode
    -v9
	highly verbose
EOF
}


# Parse Options
#
PARSE_OPTION()
{
    while test $# -gt 0 ; do
	case "$1" in
	-h | -help )
	    USAGE
	    exit 0
	    ;;
	-fname )
	    shift
	    FNAME="$1"
	    ;;
	-v* )
	    VERBOSE=yes
	    if test X$1 = X-v9; then
		set -x
	    fi
	    ;;
	-* )
	    echo "***Unknown option ($1)"
	    USAGE
	    exit 1
	    ;;
	* )
	    DIRS=$*
	    break
	    ;;
	esac
	shift
    done
}


# Check C and C++ source files
#
C_SOURCE()
{
    f=$1
    cat > ${COPYRIGHTFILE} << \EOF
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have     *
 * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
EOF
    # Must use stdin for wc to prevent filename from popping up.
    nlines=`wc -l < ${COPYRIGHTFILE}| tr -d ' '`
    head -${nlines} $f | $DIFF - ${COPYRIGHTFILE} >/dev/null 2>&1
    if test $? -ne 0; then
	# show the difference
	echo ${f}:
	head -${nlines} $f | $DIFF - ${COPYRIGHTFILE}
    fi
}


# Check Fortran90 source files
#
FORTRAN_SOURCE()
{
    f=$1
    cat > ${COPYRIGHTFILE} << \EOF
! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
!   Copyright by the Board of Trustees of the University of Illinois.         *
!   All rights reserved.                                                      *
!                                                                             *
!   This file is part of HDF5.  The full HDF5 copyright notice, including     *
!   terms governing use, modification, and redistribution, is contained in    *
!   the files COPYING and Copyright.html.  COPYING can be found at the root   *
!   of the source code distribution tree; Copyright.html can be found at the  *
!   root level of an installed copy of the electronic HDF5 document set and   *
!   is linked from the top-level documents page.  It can also be found at     *
!   http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have     *
!   access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
! * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
EOF
    # Must use stdin for wc to prevent filename from popping up.
    nlines=`wc -l < ${COPYRIGHTFILE}| tr -d ' '`
    head -${nlines} $f | $DIFF - ${COPYRIGHTFILE} >/dev/null 2>&1
    if test $? -ne 0; then
	# show the differences
	echo ${f}:
	head -${nlines} $f | $DIFF - ${COPYRIGHTFILE}
    fi
}


# Check HTML Files
#
HTML_FILE()
{
    f=$1
    cat > ${COPYRIGHTFILE} << \EOF
<!--
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  * Copyright by the Board of Trustees of the University of Illinois.         *
  * All rights reserved.                                                      *
  *                                                                           *
  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
  * terms governing use, modification, and redistribution, is contained in    *
  * the files COPYING and Copyright.html.  COPYING can be found at the root   *
  * of the source code distribution tree; Copyright.html can be found at the  *
  * root level of an installed copy of the electronic HDF5 document set and   *
  * is linked from the top-level documents page.  It can also be found at     *
  * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have     *
  * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 -->
EOF
    # Must use stdin for wc to prevent filename from popping up.
    nlines=`wc -l < ${COPYRIGHTFILE}| tr -d ' '`
    sed -n -e '/^<!--$/,/^ -->$/p' < $f | head -${nlines} > ${EXTRACTEDFILE}
    $DIFF ${EXTRACTEDFILE} ${COPYRIGHTFILE} >/dev/null 2>&1
    if test $? -ne 0; then
	# show the differences
	echo ${f}:
	$DIFF ${EXTRACTEDFILE} ${COPYRIGHTFILE}
    fi
}


# Check Shell script files
#
SHELL_FILE()
{
    f=$1
    cat > ${COPYRIGHTFILE} << \EOF
#! /bin/sh
##
## Copyright by the Board of Trustees of the University of Illinois.
## All rights reserved.
##
## This file is part of HDF5.  The full HDF5 copyright notice, including
## terms governing use, modification, and redistribution, is contained in
## the files COPYING and Copyright.html.  COPYING can be found at the root
## of the source code distribution tree; Copyright.html can be found at the
## root level of an installed copy of the electronic HDF5 document set and
## is linked from the top-level documents page.  It can also be found at
## http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have
## access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu.
##
EOF
    # Must use stdin for wc to prevent filename from popping up.
    nlines=`wc -l < ${COPYRIGHTFILE}| tr -d ' '`
    head -${nlines} $f | $DIFF - ${COPYRIGHTFILE} >/dev/null 2>&1
    if test $? -ne 0; then
	# show the differences
	echo ${f}:
	head -${nlines} $f | $DIFF - ${COPYRIGHTFILE}
    fi
}


# Check Makefile 
#
MAKE_FILE()
{
    f=$1
    cat > ${COPYRIGHTFILE} << \EOF
##
## Copyright by the Board of Trustees of the University of Illinois.
## All rights reserved.
##
## This file is part of HDF5.  The full HDF5 copyright notice, including
## terms governing use, modification, and redistribution, is contained in
## the files COPYING and Copyright.html.  COPYING can be found at the root
## of the source code distribution tree; Copyright.html can be found at the
## root level of an installed copy of the electronic HDF5 document set and
## is linked from the top-level documents page.  It can also be found at
## http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have
## access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu.
##
EOF
    # Must use stdin for wc to prevent filename from popping up.
    nlines=`wc -l < ${COPYRIGHTFILE}| tr -d ' '`
    head -${nlines} $f | $DIFF - ${COPYRIGHTFILE} >/dev/null 2>&1
    if test $? -ne 0; then
	# show the differences
	echo ${f}:
	head -${nlines} $f | $DIFF - ${COPYRIGHTFILE}
    fi
}


#
# Main body

PARSE_OPTION "$@"

# use find to list all those file names and process them
# one by one.
(
if test -z "$FNAME" ; then
    find $DIRS -type f -print
else
    find $DIRS -type f -name "${FNAME}" -print 
fi
) |
while read file; do
    if test X-$VERBOSE = X-yes; then
	echo checking ${file}...
    fi
    case ${file} in
    *.c | *.h | *.cpp )
	C_SOURCE ${file}
	;;
    *.f90 )
	FORTRAN_SOURCE ${file}
	;;
    *.htm | *.html )
        HTML_FILE ${file}
	;;
    *.sh | *.sh.in )
	SHELL_FILE ${file}
	;;
    *Makefile | *Makefile.in )
	MAKE_FILE ${file}
	;;
    *CVS/* )
	# Skip
	continue
	;;
    *)
	echo "Unknown file type (${file})"
	;;
    esac
done

# Cleanup
rm -f ${EXTRACTEDFILE} ${COPYRIGHTFILE}