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 PATTERN=$(echo -e '\t')
92 elif [ "$3" == 'trailing spaces' ]
99 if ! diff -q $1 $2 >/dev/null
101 if [ "$PATTERN" == '*' ]
103 diff $1 $2 | grep '^[0-9]' | sed "s|^\(.*\)c.*$|$2:\1: check failed: $3|g" |
104 sed "s/:\([0-9]*\),\([0-9]*\):\(.*\)$/:\1:\3 (until line \2)/g"
106 grep -n -E "$PATTERN" $2 | sed "s|^\([0-9]*\):.*$|$2:\1: check failed: $3|g"
112 function check_warning() {
113 if [ "$2" == 'long lines' ]
115 grep -n -E '.{81,}' $1 | sed "s|^\([0-9]*\):.*$|$1:\1: warning: $2|g"
117 echo "$1: warning: $2"
122 function check_init() {
123 echo Check source files...
129 function check_done() {
130 echo $FAILED_FILES out of $TOTAL_FILES files has been failed.
131 echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings.
133 if [ $WARNED_FILES -gt 0 -o $FAILED_FILES -gt 0 ]
135 if [ "$WARNING" == 'INTERACTIVE' ]
137 echo -n "Are the files with errors/warnings acceptable? (yes/no) "
140 if [ "$answer" == 'yes' ]
143 elif [ "$answer" == 'no' ]
147 echo -n "Are the files with errors/warnings acceptable? (yes/no) "
149 elif [ "$WARNING" == 'WERROR' ]
156 function check_begin() {
162 function check_end() {
163 if [ $FAILED == YES ]
167 if [ $WARNED == YES ]
177 function header_check() {
178 if echo $1 | grep -q -E 'Makefile\.am$'
185 (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*-
187 * This file is a part of LEMON, a generic C++ optimization library.
189 * Copyright (C) "$YEAR"
190 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
191 * (Egervary Research Group on Combinatorial Optimization, EGRES).
193 * Permission to use, modify and distribute this software is granted
194 * provided that this copyright notice appears in all copies. For
195 * precise terms see the accompanying LICENSE file.
197 * This software is provided \"AS IS\" with no warranty of any kind,
198 * express or implied, and with no claim as to its suitability for any
205 /\/\* / && pm==0 { pm=1;}
206 /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;}
207 /\*\// && pm==1 { pm=2;}
211 "$ACTION"_action "$TMP_FILE" "$1" header
214 function tabs_check() {
215 if echo $1 | grep -q -v -E 'Makefile\.am$'
217 OLD_PATTERN=$(echo -e '\t')
221 NEW_PATTERN=$(echo -e '\t')
224 cat $1 | sed -e "s/$OLD_PATTERN/$NEW_PATTERN/g" >$TMP_FILE
226 "$ACTION"_action "$TMP_FILE" "$1" 'tabs'
229 function spaces_check() {
231 cat $1 | sed -e 's/ \+$//g' >$TMP_FILE
233 "$ACTION"_action "$TMP_FILE" "$1" 'trailing spaces'
236 function long_lines_check() {
237 if cat $1 | grep -q -E '.{81,}'
239 "$ACTION"_warning $1 'long lines'
245 function process_file() {
246 if [ "$ACTION" == 'update' ]
248 echo -n " $ACTION $1..."
250 echo " $ACTION $1..."
253 CHECKING="header tabs spaces long_lines"
256 for check in $CHECKING
261 if [ "$ACTION" == 'update' ]
267 function process_all {
279 if [ "$1" == '--help' ] || [ "$1" == '-h' ]
286 Check the files, but do not modify them.
288 If --dry-run is specified and the checker emits warnings,
289 then the user is asked if the warnings should be considered
292 Make all warnings into errors.
294 Check all source files in the repository.
296 Check only the modified (and new) source files. This option is
297 useful to check the modification before making a commit.
299 Check only the changed source files compared to the parent(s) of
300 the current hg node. This option is useful as hg hook script.
301 To automatically check all your changes before making a commit,
302 add the following section to the appropriate .hg/hgrc file.
305 pretxncommit.checksources = scripts/unify-sources.sh -c -n -i
308 Print this help message.
310 The files to check/unify. If no file names are given, the modified
311 source files will be checked/unified (just like using the
312 --modified|-m option).
315 elif [ "$1" == '--dry-run' ] || [ "$1" == '-n' ]
317 [ -n "$ACTION" ] && echo "Conflicting action options" >&2 && exit 1
319 elif [ "$1" == "--all" ] || [ "$1" == '-a' ]
321 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
323 elif [ "$1" == "--changed" ] || [ "$1" == '-c' ]
325 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
327 elif [ "$1" == "--modified" ] || [ "$1" == '-m' ]
329 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
331 elif [ "$1" == "--interactive" ] || [ "$1" == "-i" ]
333 [ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
334 WARNING='INTERACTIVE'
335 elif [ "$1" == "--werror" ] || [ "$1" == "-w" ]
337 [ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
339 elif [ $(echo x$1 | cut -c 2) == '-' ]
341 echo "Invalid option $1" >&2 && exit 1
343 [ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1