1 | 1 |
#!/bin/bash |
2 | 2 |
|
3 | 3 |
YEAR=`date +2003-%Y` |
4 | 4 |
HGROOT=`hg root` |
5 | 5 |
|
6 | 6 |
# file enumaration modes |
7 | 7 |
|
8 | 8 |
function all_files() { |
9 | 9 |
hg status -a -m -c | |
10 | 10 |
cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' | |
11 | 11 |
while read file; do echo $HGROOT/$file; done |
12 | 12 |
} |
13 | 13 |
|
14 | 14 |
function modified_files() { |
15 | 15 |
hg status -a -m | |
16 | 16 |
cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' | |
17 | 17 |
while read file; do echo $HGROOT/$file; done |
18 | 18 |
} |
19 | 19 |
|
20 | 20 |
function changed_files() { |
21 | 21 |
{ |
22 | 22 |
if [ -n "$HG_PARENT1" ] |
23 | 23 |
then |
24 | 24 |
hg status --rev $HG_PARENT1:$HG_NODE -a -m |
25 | 25 |
fi |
26 | 26 |
if [ -n "$HG_PARENT2" ] |
27 | 27 |
then |
28 | 28 |
hg status --rev $HG_PARENT2:$HG_NODE -a -m |
29 | 29 |
fi |
30 | 30 |
} | cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' | |
31 | 31 |
sort | uniq | |
32 | 32 |
while read file; do echo $HGROOT/$file; done |
33 | 33 |
} |
34 | 34 |
|
35 | 35 |
function given_files() { |
36 | 36 |
for file in $GIVEN_FILES |
37 | 37 |
do |
38 | 38 |
echo $file |
39 | 39 |
done |
40 | 40 |
} |
41 | 41 |
|
42 | 42 |
# actions |
43 | 43 |
|
44 | 44 |
function update_action() { |
45 | 45 |
if ! diff -q $1 $2 >/dev/null |
46 | 46 |
then |
47 | 47 |
echo -n " [$3 updated]" |
48 | 48 |
rm $2 |
49 | 49 |
mv $1 $2 |
50 | 50 |
CHANGED=YES |
51 | 51 |
fi |
52 | 52 |
} |
53 | 53 |
|
54 | 54 |
function update_warning() { |
55 | 55 |
echo -n " [$2 warning]" |
56 | 56 |
WARNED=YES |
57 | 57 |
} |
58 | 58 |
|
59 | 59 |
function update_init() { |
60 | 60 |
echo Update source files... |
61 | 61 |
TOTAL_FILES=0 |
62 | 62 |
CHANGED_FILES=0 |
63 | 63 |
WARNED_FILES=0 |
64 | 64 |
} |
65 | 65 |
|
66 | 66 |
function update_done() { |
67 | 67 |
echo $CHANGED_FILES out of $TOTAL_FILES files has been changed. |
68 | 68 |
echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings. |
69 | 69 |
} |
70 | 70 |
|
71 | 71 |
function update_begin() { |
72 | 72 |
((TOTAL_FILES++)) |
73 | 73 |
CHANGED=NO |
74 | 74 |
WARNED=NO |
75 | 75 |
} |
76 | 76 |
|
77 | 77 |
function update_end() { |
78 | 78 |
if [ $CHANGED == YES ] |
79 | 79 |
then |
80 | 80 |
((++CHANGED_FILES)) |
81 | 81 |
fi |
82 | 82 |
if [ $WARNED == YES ] |
83 | 83 |
then |
84 | 84 |
((++WARNED_FILES)) |
85 | 85 |
fi |
86 | 86 |
} |
87 | 87 |
|
88 | 88 |
function check_action() { |
89 | 89 |
if [ "$3" == 'tabs' ] |
90 | 90 |
then |
91 |
|
|
91 |
if echo $2 | grep -q -v -E 'Makefile\.am$' |
|
92 |
then |
|
93 |
PATTERN=$(echo -e '\t') |
|
94 |
else |
|
95 |
PATTERN=' ' |
|
96 |
fi |
|
92 | 97 |
elif [ "$3" == 'trailing spaces' ] |
93 | 98 |
then |
94 | 99 |
PATTERN='\ +$' |
95 | 100 |
else |
96 | 101 |
PATTERN='*' |
97 | 102 |
fi |
98 | 103 |
|
99 | 104 |
if ! diff -q $1 $2 >/dev/null |
100 | 105 |
then |
101 | 106 |
if [ "$PATTERN" == '*' ] |
102 | 107 |
then |
103 | 108 |
diff $1 $2 | grep '^[0-9]' | sed "s|^\(.*\)c.*$|$2:\1: check failed: $3|g" | |
104 | 109 |
sed "s/:\([0-9]*\),\([0-9]*\):\(.*\)$/:\1:\3 (until line \2)/g" |
105 | 110 |
else |
106 | 111 |
grep -n -E "$PATTERN" $2 | sed "s|^\([0-9]*\):.*$|$2:\1: check failed: $3|g" |
107 | 112 |
fi |
108 | 113 |
FAILED=YES |
109 | 114 |
fi |
110 | 115 |
} |
111 | 116 |
|
112 | 117 |
function check_warning() { |
113 | 118 |
if [ "$2" == 'long lines' ] |
114 | 119 |
then |
115 | 120 |
grep -n -E '.{81,}' $1 | sed "s|^\([0-9]*\):.*$|$1:\1: warning: $2|g" |
116 | 121 |
else |
117 | 122 |
echo "$1: warning: $2" |
118 | 123 |
fi |
119 | 124 |
WARNED=YES |
120 | 125 |
} |
121 | 126 |
|
122 | 127 |
function check_init() { |
123 | 128 |
echo Check source files... |
124 | 129 |
FAILED_FILES=0 |
125 | 130 |
WARNED_FILES=0 |
126 | 131 |
TOTAL_FILES=0 |
127 | 132 |
} |
128 | 133 |
|
129 | 134 |
function check_done() { |
130 | 135 |
echo $FAILED_FILES out of $TOTAL_FILES files has been failed. |
131 | 136 |
echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings. |
132 | 137 |
|
133 | 138 |
if [ $WARNED_FILES -gt 0 -o $FAILED_FILES -gt 0 ] |
134 | 139 |
then |
135 | 140 |
if [ "$WARNING" == 'INTERACTIVE' ] |
136 | 141 |
then |
137 | 142 |
echo -n "Are the files with errors/warnings acceptable? (yes/no) " |
138 | 143 |
while read answer |
139 | 144 |
do |
140 | 145 |
if [ "$answer" == 'yes' ] |
141 | 146 |
then |
142 | 147 |
return 0 |
143 | 148 |
elif [ "$answer" == 'no' ] |
144 | 149 |
then |
145 | 150 |
return 1 |
146 | 151 |
fi |
147 | 152 |
echo -n "Are the files with errors/warnings acceptable? (yes/no) " |
148 | 153 |
done |
149 | 154 |
elif [ "$WARNING" == 'WERROR' ] |
150 | 155 |
then |
151 | 156 |
return 1 |
152 | 157 |
fi |
153 | 158 |
fi |
154 | 159 |
} |
155 | 160 |
|
156 | 161 |
function check_begin() { |
157 | 162 |
((TOTAL_FILES++)) |
158 | 163 |
FAILED=NO |
159 | 164 |
WARNED=NO |
160 | 165 |
} |
161 | 166 |
|
162 | 167 |
function check_end() { |
163 | 168 |
if [ $FAILED == YES ] |
164 | 169 |
then |
165 | 170 |
((++FAILED_FILES)) |
166 | 171 |
fi |
167 | 172 |
if [ $WARNED == YES ] |
168 | 173 |
then |
169 | 174 |
((++WARNED_FILES)) |
170 | 175 |
fi |
171 | 176 |
} |
172 | 177 |
|
173 | 178 |
|
174 | 179 |
|
175 | 180 |
# checks |
176 | 181 |
|
177 | 182 |
function header_check() { |
178 | 183 |
if echo $1 | grep -q -E 'Makefile\.am$' |
179 | 184 |
then |
180 | 185 |
return |
181 | 186 |
fi |
182 | 187 |
|
183 | 188 |
TMP_FILE=`mktemp` |
184 | 189 |
|
185 | 190 |
(echo "/* -*- mode: C++; indent-tabs-mode: nil; -*- |
186 | 191 |
* |
187 | 192 |
* This file is a part of LEMON, a generic C++ optimization library. |
0 comments (0 inline)