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 has been warned.
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 has been warned.
123 if [ $FAILED_FILES -gt 0 ]
126 elif [ $WARNED_FILES -gt 0 ]
128 if [ "$WARNING" == 'INTERACTIVE' ]
130 echo -n "Assume as normal behaviour? (yes/no) "
133 if [ "$answer" == 'yes' ]
136 elif [ "$answer" == 'no' ]
140 echo -n "Assume as normal behaviour? (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 given files, but do not modify them.
273 If --dry-run is specified and files are warned, then a message is
274 prompted whether the warnings should be turned to errors.
276 If --dry-run is specified, the warnings are turned to errors.
278 Check all source files in the repository.
280 Check only the modified source files. This option is proper to
281 use before a commit. E.g. all files which are modified or added
282 into the repository will be updated.
284 Check only the changed source files compared to the parent(s) of
285 the current hg node. This option is proper to use as hg hook
286 script. E.g. to check all your commited source files with this
287 script add the following section to the appropriate .hg/hgrc
291 pretxncommit.checksources = scripts/unify-sources.sh -c -n -i
294 Print this help message.
296 The files to check/unify. If no file names are given, the modified
297 source files will be checked/unified (just like using the
298 --modified|-m option).
301 elif [ "$1" == '--dry-run' ] || [ "$1" == '-n' ]
303 [ -n "$ACTION" ] && echo "Conflicting action options" >&2 && exit 1
305 elif [ "$1" == "--all" ] || [ "$1" == '-a' ]
307 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
309 elif [ "$1" == "--changed" ] || [ "$1" == '-c' ]
311 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
313 elif [ "$1" == "--modified" ] || [ "$1" == '-m' ]
315 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
317 elif [ "$1" == "--interactive" ] || [ "$1" == "-i" ]
319 [ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
320 WARNING='INTERACTIVE'
321 elif [ "$1" == "--werror" ] || [ "$1" == "-w" ]
323 [ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
325 elif [ $(echo x$1 | cut -c 2) == '-' ]
327 echo "Invalid option $1" >&2 && exit 1
329 [ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1