6 # file enumaration modes
10 cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' |
11 while read file; do echo $HGROOT/$file; done
14 function modified_files() {
16 cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' |
17 while read file; do echo $HGROOT/$file; done
20 function changed_files() {
22 if [ -n "$HG_PARENT1" ]
24 hg status --rev $HG_PARENT1:$HG_NODE -a -m
26 if [ -n "$HG_PARENT2" ]
28 hg status --rev $HG_PARENT2:$HG_NODE -a -m
30 } | cut -d ' ' -f 2 | grep -E '(\.(cc|h|dox)$|Makefile\.am$)' |
32 while read file; do echo $HGROOT/$file; done
35 function given_files() {
36 for file in $GIVEN_FILES
44 function update_action() {
45 if ! diff -q $1 $2 >/dev/null
47 echo -n " [$3 updated]"
54 function update_warning() {
55 echo -n " [$2 warning]"
59 function update_init() {
60 echo Update source files...
66 function update_done() {
67 echo $CHANGED_FILES out of $TOTAL_FILES files has been changed.
68 echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings.
71 function update_begin() {
77 function update_end() {
78 if [ $CHANGED == YES ]
88 function check_action() {
91 if echo $2 | grep -q -v -E 'Makefile\.am$'
93 PATTERN=$(echo -e '\t')
97 elif [ "$3" == 'trailing spaces' ]
104 if ! diff -q $1 $2 >/dev/null
106 if [ "$PATTERN" == '*' ]
108 diff $1 $2 | grep '^[0-9]' | sed "s|^\(.*\)c.*$|$2:\1: check failed: $3|g" |
109 sed "s/:\([0-9]*\),\([0-9]*\):\(.*\)$/:\1:\3 (until line \2)/g"
111 grep -n -E "$PATTERN" $2 | sed "s|^\([0-9]*\):.*$|$2:\1: check failed: $3|g"
117 function check_warning() {
118 if [ "$2" == 'long lines' ]
120 grep -n -E '.{81,}' $1 | sed "s|^\([0-9]*\):.*$|$1:\1: warning: $2|g"
122 echo "$1: warning: $2"
127 function check_init() {
128 echo Check source files...
134 function check_done() {
135 echo $FAILED_FILES out of $TOTAL_FILES files has been failed.
136 echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings.
138 if [ $WARNED_FILES -gt 0 -o $FAILED_FILES -gt 0 ]
140 if [ "$WARNING" == 'INTERACTIVE' ]
142 echo -n "Are the files with errors/warnings acceptable? (yes/no) "
145 if [ "$answer" == 'yes' ]
148 elif [ "$answer" == 'no' ]
152 echo -n "Are the files with errors/warnings acceptable? (yes/no) "
154 elif [ "$WARNING" == 'WERROR' ]
161 function check_begin() {
167 function check_end() {
168 if [ $FAILED == YES ]
172 if [ $WARNED == YES ]
182 function header_check() {
183 if echo $1 | grep -q -E 'Makefile\.am$'
190 (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*-
192 * This file is a part of LEMON, a generic C++ optimization library.
194 * Copyright (C) "$YEAR"
195 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
196 * (Egervary Research Group on Combinatorial Optimization, EGRES).
198 * Permission to use, modify and distribute this software is granted
199 * provided that this copyright notice appears in all copies. For
200 * precise terms see the accompanying LICENSE file.
202 * This software is provided \"AS IS\" with no warranty of any kind,
203 * express or implied, and with no claim as to its suitability for any
210 /\/\* / && pm==0 { pm=1;}
211 /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;}
212 /\*\// && pm==1 { pm=2;}
216 "$ACTION"_action "$TMP_FILE" "$1" header
219 function tabs_check() {
220 if echo $1 | grep -q -v -E 'Makefile\.am$'
222 OLD_PATTERN=$(echo -e '\t')
226 NEW_PATTERN=$(echo -e '\t')
229 cat $1 | sed -e "s/$OLD_PATTERN/$NEW_PATTERN/g" >$TMP_FILE
231 "$ACTION"_action "$TMP_FILE" "$1" 'tabs'
234 function spaces_check() {
236 cat $1 | sed -e 's/ \+$//g' >$TMP_FILE
238 "$ACTION"_action "$TMP_FILE" "$1" 'trailing spaces'
241 function long_lines_check() {
242 if cat $1 | grep -q -E '.{81,}'
244 "$ACTION"_warning $1 'long lines'
250 function process_file() {
251 if [ "$ACTION" == 'update' ]
253 echo -n " $ACTION $1..."
255 echo " $ACTION $1..."
258 CHECKING="header tabs spaces long_lines"
261 for check in $CHECKING
266 if [ "$ACTION" == 'update' ]
272 function process_all {
284 if [ "$1" == '--help' ] || [ "$1" == '-h' ]
291 Check the files, but do not modify them.
293 If --dry-run is specified and the checker emits warnings,
294 then the user is asked if the warnings should be considered
297 Make all warnings into errors.
299 Check all source files in the repository.
301 Check only the modified (and new) source files. This option is
302 useful to check the modification before making a commit.
304 Check only the changed source files compared to the parent(s) of
305 the current hg node. This option is useful as hg hook script.
306 To automatically check all your changes before making a commit,
307 add the following section to the appropriate .hg/hgrc file.
310 pretxncommit.checksources = scripts/unify-sources.sh -c -n -i
313 Print this help message.
315 The files to check/unify. If no file names are given, the modified
316 source files will be checked/unified (just like using the
317 --modified|-m option).
320 elif [ "$1" == '--dry-run' ] || [ "$1" == '-n' ]
322 [ -n "$ACTION" ] && echo "Conflicting action options" >&2 && exit 1
324 elif [ "$1" == "--all" ] || [ "$1" == '-a' ]
326 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
328 elif [ "$1" == "--changed" ] || [ "$1" == '-c' ]
330 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
332 elif [ "$1" == "--modified" ] || [ "$1" == '-m' ]
334 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
336 elif [ "$1" == "--interactive" ] || [ "$1" == "-i" ]
338 [ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
339 WARNING='INTERACTIVE'
340 elif [ "$1" == "--werror" ] || [ "$1" == "-w" ]
342 [ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
344 elif [ $(echo x$1 | cut -c 2) == '-' ]
346 echo "Invalid option $1" >&2 && exit 1
348 [ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1