Repository navigation
Expand file tree
/
Copy pathheader_script
More file actions
executable file
·158 lines (150 loc) · 4.89 KB
/
Copy pathheader_script
File metadata and controls
executable file
·158 lines (150 loc) · 4.89 KB
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
#!/bin/bash -e
#
# Haddock checker and license changing script
# for the Hets repository
#
# c.prodescu@jacobs-university.de
#
NEW_LICENSE='GPLv2 or higher'
EMPTY_HADDOCK_HEADER=./utils/header_script/empty_header
EMPTY_HEADER_MARK='$EmptyHeader$'
START_HADDOCK_HEADER='{- |'
END_HADDOCK_HEADER='-}'
SECTIONS='Module Description Copyright License Maintainer Stability Portability'
FILEFORMATS=".hs .haskell "
LOGFILE=$PWD/script_log
#testing if empty_header is available
while [ 1 ]
do
if [ -e $EMPTY_HADDOCK_HEADER ];
then
echo Using haddock template header from $EMPTY_HADDOCK_HEADER
break
else
echo Provide path to empty haddock header:
read EMPTY_HADDOCK_HEADER
if [ -e $EMPTY_HADDOCK_HEADER ];
then
break
fi
fi
done
#printing the time stamp in the log file
$(date > $LOGFILE)
while [ 1 ]
do
#reading filename
read filename
#testing if filename exists
if [ -e $filename ];
then
#testing if filename defines a directory instead of a file
if [ -d $filename ];
then
echo "Skipping directory $filename"
else
#checking if the file format is proper
THISFORMAT=`echo $filename | grep -o '\.[^.]*$'`
if [[ "$FILEFORMATS" =~ "$THISFORMAT " ]]; ##REGEXP requieres bash instead of sh
then
#testing if file has write permissions
if [ -w $filename ];
then
#checking file for proper haddock header
#determining the start and end of the haddock header
START=`fgrep -n -i -e "$START_HADDOCK_HEADER" $filename | head -n 1`
#checking if any header exists
if [ -z "$START" ];
then
#no haddock header found, inserting default one
echo "$filename: NO HEADER FOUND. Inserting blank header"
cat $EMPTY_HADDOCK_HEADER $filename > /tmp/sed_script_tmp
cat /tmp/sed_script_tmp > $filename
echo "$filename:" >> $LOGFILE
echo " :: Empty haddock header" >> $LOGFILE
echo >> $LOGFILE
else
START=${START%%:*}
LENGTH=`cat $filename | tail -n +$START | grep -n -i -e "$END_HADDOCK_HEADER" | head -n 1`
if [ -z "$LENGTH" ];
then
echo "$filename: ERROR - broken haddock header"
echo "$filename: ERROR - broken haddock header" >> $LOGFILE
continue
else
echo "$filename:"
fi
LENGTH=${LENGTH%%:*}
END=`expr $START + $LENGTH - 1`
echo " :: Haddock header successfully parsed (lines $START to $END)"
#testing if header is not just a blank template
if cat $filename | tail -n +$START | head -n $LENGTH | grep -q -i -e module;
then
MODULEHEADER="`cat $filename | tail -n +$START | head -n $LENGTH | grep -i -e module`"
if [[ "$MODULEHEADER" =~ "$EMPTY_HEADER_MARK" ]];
then
echo " :: Empty haddock template"
echo "$filename" >> $LOGFILE
echo " :: Empty haddock template" >> $LOGFILE
echo >> $LOGFILE
continue
else
echo " :: Testing sections..."
fi
#testing if proper sections are available in the header
SECTIONSOK=1
for section in $SECTIONS
do
#testing if current section is present in the header
THISSECTION=`cat $filename | tail -n +$START | head -n $LENGTH | grep -i -e $section | head -c 1`
if [ -z "$THISSECTION" ];
then
if [ $SECTIONSOK -eq 1 ];
then
echo "$filename:" >>$LOGFILE
SECTIONSOK=0
fi
echo " :: $section missing" >>$LOGFILE
else
echo " :: $section found"
fi
done
if [ $SECTIONSOK -eq 1 ];
then
echo " :: Changing License for $filename"
else
echo " :: Changing License for $filename"
echo >> $LOGFILE
fi
#changing license to $NEW_LICENSE
cat $filename > /tmp/sed_script_tmp
cat /tmp/sed_script_tmp \
| sed "s/similar\ to\ LGPL,\ see\ HetCATS\/LICENSE.txt\ or\ LIZENZ.txt/$NEW_LICENSE/g" \
| sed "s/similar to LGPL, see HetCATS\/LICENCE.txt or LIZENZ.txt/$NEW_LICENSE/g" \
| sed "s/Similar\ to\ LGPL,\ see\ HetCATS\/LICENSE.txt\ or\ LIZENZ.txt/$NEW_LICENSE/g" \
| sed "s/similar\ to\ LGPL,\ see\ LICENSE.txt\ or\ LIZENZ.txt/$NEW_LICENSE/g" \
| sed "s/similar\ to\ LGPL,\ see HetCATS\/LICENSE.txt/$NEW_LICENSE/g" \
| sed "s/similar\ to\ LGPL,\ see LICENSE.txt/$NEW_LICENSE/g" \
| sed "s/similar\ to\ LGPL,\ see HetCATS\/LICENSE.txt\ or\ LIZENZ.txt/$NEW_LICENSE/g" \
| sed "s/similar\ to\ LGPL,\ see Hets\/LICENSE.txt/$NEW_LICENSE/g" \
| sed "s/LGPL,\ see\ LICENSE.txt\ or\ LIZENZ.txt/$NEW_LICENSE/g" \
| sed "s/AGPLv2\ or\ higher/$NEW_LICENSE/g" \
> $filename
else
echo "$filename:" >> $LOGFILE
echo " :: Broken haddock header - no Module entry" >> $LOGFILE
echo >> $LOGFILE
echo " :: Broken haddock header - no Module entry"
fi
fi
else
echo "No write permissions for $filename"
fi
else
echo "Skipping non haskell $filename"
fi
fi
else
echo "$filename: ERROR - invalid file name"
fi
done