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
91 echo -n " [$3 failed]"
96 function check_warning() {
97 echo -n " [$2 warning]"
101 function check_init() {
102 echo Check source files...
108 function check_done() {
109 echo $FAILED_FILES out of $TOTAL_FILES files has been failed.
110 echo $WARNED_FILES out of $TOTAL_FILES files triggered warnings.
112 if [ $FAILED_FILES -gt 0 ]
115 elif [ $WARNED_FILES -gt 0 ]
117 if [ "$WARNING" == 'INTERACTIVE' ]
119 echo -n "Are the files with warnings acceptable? (yes/no) "
122 if [ "$answer" == 'yes' ]
125 elif [ "$answer" == 'no' ]
129 echo -n "Are the files with warnings acceptable? (yes/no) "
131 elif [ "$WARNING" == 'WERROR' ]
138 function check_begin() {
144 function check_end() {
145 if [ $FAILED == YES ]
149 if [ $WARNED == YES ]
159 function header_check() {
160 if echo $1 | grep -q -E 'Makefile\.am$'
167 (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*-
169 * This file is a part of LEMON, a generic C++ optimization library.
171 * Copyright (C) "$YEAR"
172 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
173 * (Egervary Research Group on Combinatorial Optimization, EGRES).
175 * Permission to use, modify and distribute this software is granted
176 * provided that this copyright notice appears in all copies. For
177 * precise terms see the accompanying LICENSE file.
179 * This software is provided \"AS IS\" with no warranty of any kind,
180 * express or implied, and with no claim as to its suitability for any
187 /\/\* / && pm==0 { pm=1;}
188 /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;}
189 /\*\// && pm==1 { pm=2;}
193 "$ACTION"_action "$TMP_FILE" "$1" header
196 function tabs_check() {
197 if echo $1 | grep -q -v -E 'Makefile\.am$'
199 OLD_PATTERN=$(echo -e '\t')
203 NEW_PATTERN=$(echo -e '\t')
206 cat $1 | sed -e "s/$OLD_PATTERN/$NEW_PATTERN/g" >$TMP_FILE
208 "$ACTION"_action "$TMP_FILE" "$1" 'tabs'
211 function spaces_check() {
213 cat $1 | sed -e 's/ \+$//g' >$TMP_FILE
215 "$ACTION"_action "$TMP_FILE" "$1" 'spaces'
218 function long_lines_check() {
219 if cat $1 | grep -q -E '.{81,}'
221 "$ACTION"_warning $1 'long lines'
227 function process_file() {
228 echo -n " $ACTION " $1...
230 CHECKING="header tabs spaces long_lines"
233 for check in $CHECKING
241 function process_all {
253 if [ "$1" == '--help' ] || [ "$1" == '-h' ]
260 Check the files, but do not modify them.
262 If --dry-run is specified and the checker emits warnings,
263 then the user is asked if the warnings should be considered
266 Make all warnings into errors.
268 All files in the repository will be checked.
270 Check only the modified (and new) source files. This option is
271 useful to check the modification before making a commit.
273 Check only the changed source files compared to the parent(s) of
274 the current hg node. This option is useful as hg hook script.
275 To automatically check all your changes before making a commit,
276 add the following section to the appropriate .hg/hgrc file.
279 pretxncommit.checksources = scripts/unify-sources.sh -c -n -i
282 Print this help message.
284 The files to check/unify. If no file names are given, the
285 modified source will be checked/unified
289 elif [ "$1" == '--dry-run' ] || [ "$1" == '-n' ]
291 [ -n "$ACTION" ] && echo "Invalid option $1" >&2 && exit 1
293 elif [ "$1" == "--all" ] || [ "$1" == '-a' ]
295 [ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1
297 elif [ "$1" == "--changed" ] || [ "$1" == '-c' ]
299 [ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1
301 elif [ "$1" == "--modified" ] || [ "$1" == '-m' ]
303 [ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1
305 elif [ "$1" == "--interactive" ] || [ "$1" == "-i" ]
307 [ -n "$WARNING" ] && echo "Invalid option $1" >&2 && exit 1
308 WARNING='INTERACTIVE'
309 elif [ "$1" == "--werror" ] || [ "$1" == "-w" ]
311 [ -n "$WARNING" ] && echo "Invalid option $1" >&2 && exit 1
313 elif [ $(echo $1 | cut -c 1) == '-' ]
315 echo "Invalid option $1" >&2 && exit 1
317 [ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1