-
Notifications
You must be signed in to change notification settings - Fork 0
/
addcopyheaders.rle
executable file
·66 lines (65 loc) · 1.89 KB
/
addcopyheaders.rle
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
#!/bin/sh
set -e
## Arguments:
# 1) Package directory name (optional).
pkg=${1:-.}
cd "$pkg"
pkgname=`cat DESCRIPTION | egrep '^ *Package:' | sed 's/Package: //'`
copyyears=`cat inst/COPYRIGHT | egrep 'Copyright [0-9]{4}-[0-9]{4}' | sed 's/Copyright //'`
find R src tests man inst \( -iname '*.r' -or -iname '*.c' -or -iname '*.rd' -or -iname '*.h' \) | while read file
do
echo -n $file ':'
case `echo "$file" | tr '[:upper:]' '[:lower:]' | egrep -o '[a-z]+$'` in
h|c)
echo C
start='/*'
startRE='/\*'
cont=' *'
contRE=' \*'
end=' */'
endRE=' \*/'
;;
r)
echo R
start='#'
startRE="$start"
cont='#'
contRE="$cont"
end='#######################################################################'
endRE="$end"
;;
rd)
echo -n Rd
if grep -Fq '% Generated by roxygen2: do not edit by hand' "$file"
then
echo "; Managed by roxygen2; skipping."
continue
else
echo
fi
start='%'
startRE="$start"
cont='%'
contRE="$cont"
end='%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'
endRE="$end"
;;
*)
continue
esac
echo \
"$start File $file in package $pkgname, currently hosted at https://github.com/statnet/rle .
$cont
$cont This software is distributed under the GNU General Public License Version 3 or later.
$cont A copy of this license may be found at https://www.gnu.org/licenses/gpl-3.0.en.html .
$cont
$cont Copyright $copyyears Pavel N. Krivitsky and others (see inst/COPYRIGHT).
$end" >> ${file}.tmp
# The following code (which requires pcregrep), strips out
# text that follows the general pattern of a block of
# commented out lines the first of which begins with "File",
# the penultimate of which has a copyright statement, and the
# last of which is a line of comment characters.
cat ${file} | pcregrep -vx -M "^$startRE File .*\n(^$contRE.*\n)*?$endRE" >> ${file}.tmp
mv ${file}.tmp ${file}
done