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() {
89 if ! diff -q $1 $2 >/dev/null
92 echo -n " $3 failed at line(s): "
93 echo -n $(diff $1 $2 | grep '^[0-9]' | sed "s/^\(.*\)c.*$/ \1/g" |
94 sed "s/,/-/g" | paste -s -d',')
99 function check_warning() {
101 if [ "$2" == 'long lines' ]
103 echo -n " $2 warning at line(s): "
104 echo -n $(grep -n -E '.{81,}' $1 | sed "s/^\([0-9]*\)/ \1\t/g" |
105 cut -f 1 | paste -s -d',')
107 echo -n " $2 warning"
112 function check_init() {
113 echo Check source files...
119 function check_done() {
120 echo $FAILED_FILES out of $TOTAL_FILES files has been failed.
121 echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings.
123 if [ $FAILED_FILES -gt 0 ]
126 elif [ $WARNED_FILES -gt 0 ]
128 if [ "$WARNING" == 'INTERACTIVE' ]
130 echo -n "Are the files with warnings acceptable? (yes/no) "
133 if [ "$answer" == 'yes' ]
136 elif [ "$answer" == 'no' ]
140 echo -n "Are the files with warnings acceptable? (yes/no) "
142 elif [ "$WARNING" == 'WERROR' ]
149 function check_begin() {
155 function check_end() {
156 if [ $FAILED == YES ]
160 if [ $WARNED == YES ]
170 function header_check() {
171 if echo $1 | grep -q -E 'Makefile\.am$'
178 (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*-
180 * This file is a part of LEMON, a generic C++ optimization library.
182 * Copyright (C) "$YEAR"
183 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
184 * (Egervary Research Group on Combinatorial Optimization, EGRES).
186 * Permission to use, modify and distribute this software is granted
187 * provided that this copyright notice appears in all copies. For
188 * precise terms see the accompanying LICENSE file.
190 * This software is provided \"AS IS\" with no warranty of any kind,
191 * express or implied, and with no claim as to its suitability for any
198 /\/\* / && pm==0 { pm=1;}
199 /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;}
200 /\*\// && pm==1 { pm=2;}
204 "$ACTION"_action "$TMP_FILE" "$1" header
207 function tabs_check() {
208 if echo $1 | grep -q -v -E 'Makefile\.am$'
210 OLD_PATTERN=$(echo -e '\t')
214 NEW_PATTERN=$(echo -e '\t')
217 cat $1 | sed -e "s/$OLD_PATTERN/$NEW_PATTERN/g" >$TMP_FILE
219 "$ACTION"_action "$TMP_FILE" "$1" 'tabs'
222 function spaces_check() {
224 cat $1 | sed -e 's/ \+$//g' >$TMP_FILE
226 "$ACTION"_action "$TMP_FILE" "$1" 'trailing spaces'
229 function long_lines_check() {
230 if cat $1 | grep -q -E '.{81,}'
232 "$ACTION"_warning $1 'long lines'
238 function process_file() {
239 echo -n " $ACTION $1..."
241 CHECKING="header tabs spaces long_lines"
244 for check in $CHECKING
252 function process_all {
264 if [ "$1" == '--help' ] || [ "$1" == '-h' ]
271 Check the files, but do not modify them.
273 If --dry-run is specified and the checker emits warnings,
274 then the user is asked if the warnings should be considered
277 Make all warnings into errors.
279 Check all source files in the repository.
281 Check only the modified (and new) source files. This option is
282 useful to check the modification before making a commit.
284 Check only the changed source files compared to the parent(s) of
285 the current hg node. This option is useful as hg hook script.
286 To automatically check all your changes before making a commit,
287 add the following section to the appropriate .hg/hgrc file.
290 pretxncommit.checksources = scripts/unify-sources.sh -c -n -i
293 Print this help message.
295 The files to check/unify. If no file names are given, the modified
296 source files will be checked/unified (just like using the
297 --modified|-m option).
300 elif [ "$1" == '--dry-run' ] || [ "$1" == '-n' ]
302 [ -n "$ACTION" ] && echo "Conflicting action options" >&2 && exit 1
304 elif [ "$1" == "--all" ] || [ "$1" == '-a' ]
306 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
308 elif [ "$1" == "--changed" ] || [ "$1" == '-c' ]
310 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
312 elif [ "$1" == "--modified" ] || [ "$1" == '-m' ]
314 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
316 elif [ "$1" == "--interactive" ] || [ "$1" == "-i" ]
318 [ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
319 WARNING='INTERACTIVE'
320 elif [ "$1" == "--werror" ] || [ "$1" == "-w" ]
322 [ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
324 elif [ $(echo x$1 | cut -c 2) == '-' ]
326 echo "Invalid option $1" >&2 && exit 1
328 [ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1