gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Merge
0 1 0
merge default
1 file changed with 7 insertions and 2 deletions:
↑ Collapse diff ↑
Ignore white space 192 line context
1 1
#!/bin/bash
2 2

	
3
YEAR=`date +2003-%Y`
3
YEAR=`date +%Y`
4 4
HGROOT=`hg root`
5 5

	
6
function hg_year() {
7
    if [ -n "$(hg st $1)" ]; then
8
        echo $YEAR
9
}
10

	
6 11
# file enumaration modes
7 12

	
8 13
function all_files() {
9 14
    hg status -a -m -c |
10 15
    cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' |
11 16
    while read file; do echo $HGROOT/$file; done
12 17
}
13 18

	
14 19
function modified_files() {
15 20
    hg status -a -m |
16 21
    cut -d ' ' -f 2 | grep -E  '(\.(cc|h|dox)$|Makefile\.am$)' |
17 22
    while read file; do echo $HGROOT/$file; done
18 23
}
19 24

	
20 25
function changed_files() {
21 26
    {
22 27
        if [ -n "$HG_PARENT1" ]
23 28
        then
24 29
            hg status --rev $HG_PARENT1:$HG_NODE -a -m
25 30
        fi
26 31
        if [ -n "$HG_PARENT2" ]
27 32
        then
28 33
            hg status --rev $HG_PARENT2:$HG_NODE -a -m
29 34
        fi
30 35
    } | cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' | 
31 36
    sort | uniq |
32 37
    while read file; do echo $HGROOT/$file; done
33 38
}
34 39

	
35 40
function given_files() {
36 41
    for file in $GIVEN_FILES
37 42
    do
38 43
	echo $file
39 44
    done
40 45
}
41 46

	
42 47
# actions
43 48

	
44 49
function update_action() {
45 50
    if ! diff -q $1 $2 >/dev/null
46 51
    then
47 52
	echo -n " [$3 updated]"
48 53
	rm $2
49 54
	mv $1 $2
50 55
	CHANGED=YES
51 56
    fi
52 57
}
53 58

	
54 59
function update_warning() {
55 60
    echo -n " [$2 warning]"
56 61
    WARNED=YES
57 62
}
58 63

	
59 64
function update_init() {
60 65
    echo Update source files...
61 66
    TOTAL_FILES=0
62 67
    CHANGED_FILES=0
63 68
    WARNED_FILES=0
64 69
}
65 70

	
66 71
function update_done() {
67 72
    echo $CHANGED_FILES out of $TOTAL_FILES files has been changed.
68 73
    echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings.
69 74
}
70 75

	
71 76
function update_begin() {
72 77
    ((TOTAL_FILES++))
73 78
    CHANGED=NO
74 79
    WARNED=NO
75 80
}
76 81

	
77 82
function update_end() {
78 83
    if [ $CHANGED == YES ]
79 84
    then
80 85
	((++CHANGED_FILES))
81 86
    fi
82 87
    if [ $WARNED == YES ]
83 88
    then
84 89
	((++WARNED_FILES))
85 90
    fi
86 91
}
87 92

	
88 93
function check_action() {
89 94
    if [ "$3" == 'tabs' ]
90 95
    then
91 96
        if echo $2 | grep -q -v -E 'Makefile\.am$'
92 97
        then
93 98
            PATTERN=$(echo -e '\t')
94 99
        else
95 100
            PATTERN='        '
96 101
        fi
97 102
    elif [ "$3" == 'trailing spaces' ]
98 103
    then
99 104
        PATTERN='\ +$'
100 105
    else
101 106
        PATTERN='*'
102 107
    fi
103 108

	
104 109
    if ! diff -q $1 $2 >/dev/null
105 110
    then
106 111
        if [ "$PATTERN" == '*' ]
107 112
        then
108 113
            diff $1 $2 | grep '^[0-9]' | sed "s|^\(.*\)c.*$|$2:\1: check failed: $3|g" |
109 114
              sed "s/:\([0-9]*\),\([0-9]*\):\(.*\)$/:\1:\3 (until line \2)/g"
110 115
        else
111 116
            grep -n -E "$PATTERN" $2 | sed "s|^\([0-9]*\):.*$|$2:\1: check failed: $3|g"
112 117
        fi
113 118
        FAILED=YES
114 119
    fi
115 120
}
116 121

	
117 122
function check_warning() {
118 123
    if [ "$2" == 'long lines' ]
119 124
    then
120 125
        grep -n -E '.{81,}' $1 | sed "s|^\([0-9]*\):.*$|$1:\1: warning: $2|g"
121 126
    else
122 127
        echo "$1: warning: $2"
123 128
    fi
124 129
    WARNED=YES
125 130
}
126 131

	
127 132
function check_init() {
128 133
    echo Check source files...
129 134
    FAILED_FILES=0
130 135
    WARNED_FILES=0
131 136
    TOTAL_FILES=0
132 137
}
133 138

	
134 139
function check_done() {
135 140
    echo $FAILED_FILES out of $TOTAL_FILES files has been failed.
136 141
    echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings.
137 142

	
138 143
    if [ $WARNED_FILES -gt 0 -o $FAILED_FILES -gt 0 ]
139 144
    then
140 145
	if [ "$WARNING" == 'INTERACTIVE' ]
141 146
	then
142 147
	    echo -n "Are the files with errors/warnings acceptable? (yes/no) "
143 148
	    while read answer
144 149
	    do
145 150
		if [ "$answer" == 'yes' ]
146 151
		then
147 152
		    return 0
148 153
		elif [ "$answer" == 'no' ]
149 154
		then
150 155
		    return 1
151 156
		fi
152 157
		echo -n "Are the files with errors/warnings acceptable? (yes/no) "
153 158
	    done
154 159
	elif [ "$WARNING" == 'WERROR' ]
155 160
	then
156 161
	    return 1
157 162
	fi
158 163
    fi
159 164
}
160 165

	
161 166
function check_begin() {
162 167
    ((TOTAL_FILES++))
163 168
    FAILED=NO
164 169
    WARNED=NO
165 170
}
166 171

	
167 172
function check_end() {
168 173
    if [ $FAILED == YES ]
169 174
    then
170 175
	((++FAILED_FILES))
171 176
    fi
172 177
    if [ $WARNED == YES ]
173 178
    then
174 179
	((++WARNED_FILES))
175 180
    fi
176 181
}
177 182

	
178 183

	
179 184

	
180 185
# checks
181 186

	
182 187
function header_check() {
183 188
    if echo $1 | grep -q -E 'Makefile\.am$'
184 189
    then
185 190
	return
186 191
    fi
187 192

	
188 193
    TMP_FILE=`mktemp`
189 194

	
190 195
    (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*-
191 196
 *
192 197
 * This file is a part of LEMON, a generic C++ optimization library.
193 198
 *
194
 * Copyright (C) "$YEAR"
199
 * Copyright (C) 2003-"$(hg_year $1)"
195 200
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
196 201
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
197 202
 *
198 203
 * Permission to use, modify and distribute this software is granted
199 204
 * provided that this copyright notice appears in all copies. For
200 205
 * precise terms see the accompanying LICENSE file.
201 206
 *
202 207
 * This software is provided \"AS IS\" with no warranty of any kind,
203 208
 * express or implied, and with no claim as to its suitability for any
204 209
 * purpose.
205 210
 *
206 211
 */
207 212
"
208 213
    awk 'BEGIN { pm=0; }
209 214
     pm==3 { print }
210 215
     /\/\* / && pm==0 { pm=1;}
211 216
     /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;}
212 217
     /\*\// && pm==1 { pm=2;}
213 218
    ' $1
214 219
    ) >$TMP_FILE
215 220

	
216 221
    "$ACTION"_action "$TMP_FILE" "$1" header
217 222
}
218 223

	
219 224
function tabs_check() {
220 225
    if echo $1 | grep -q -v -E 'Makefile\.am$'
221 226
    then
222 227
        OLD_PATTERN=$(echo -e '\t')
223 228
        NEW_PATTERN='        '
224 229
    else
225 230
        OLD_PATTERN='        '
226 231
        NEW_PATTERN=$(echo -e '\t')
227 232
    fi
228 233
    TMP_FILE=`mktemp`
229 234
    cat $1 | sed -e "s/$OLD_PATTERN/$NEW_PATTERN/g" >$TMP_FILE
230 235

	
231 236
    "$ACTION"_action "$TMP_FILE" "$1" 'tabs'
232 237
}
233 238

	
234 239
function spaces_check() {
235 240
    TMP_FILE=`mktemp`
236 241
    cat $1 | sed -e 's/ \+$//g' >$TMP_FILE
237 242

	
238 243
    "$ACTION"_action "$TMP_FILE" "$1" 'trailing spaces'
239 244
}
240 245

	
241 246
function long_lines_check() {
242 247
    if cat $1 | grep -q -E '.{81,}'
243 248
    then
244 249
	"$ACTION"_warning $1 'long lines'
245 250
    fi
246 251
}
247 252

	
248 253
# process the file
249 254

	
250 255
function process_file() {
251 256
    if [ "$ACTION" == 'update' ]
252 257
    then
253 258
        echo -n "    $ACTION $1..."
254 259
    else
255 260
        echo "	  $ACTION $1..."
256 261
    fi
257 262

	
258 263
    CHECKING="header tabs spaces long_lines"
259 264

	
260 265
    "$ACTION"_begin $1
261 266
    for check in $CHECKING
262 267
    do
263 268
	"$check"_check $1
264 269
    done
265 270
    "$ACTION"_end $1
266 271
    if [ "$ACTION" == 'update' ]
267 272
    then
268 273
        echo
269 274
    fi
270 275
}
271 276

	
272 277
function process_all {
273 278
    "$ACTION"_init
274 279
    while read file
275 280
    do
276 281
	process_file $file
277 282
    done < <($FILES)
278 283
    "$ACTION"_done
279 284
}
280 285

	
281 286
while [ $# -gt 0 ]
282 287
do
283 288
    
284 289
    if [ "$1" == '--help' ] || [ "$1" == '-h' ]
285 290
    then
286 291
	echo -n \
287 292
"Usage:
288 293
  $0 [OPTIONS] [files]
289 294
Options:
290 295
  --dry-run|-n
0 comments (0 inline)