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
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 has been warned.
112 if [ $FAILED_FILES -gt 0 ]
115 elif [ $WARNED_FILES -gt 0 ]
117 if [ "$WARNING" == 'INTERACTIVE' ]
119 echo -n "Assume as normal behaviour? (yes/no) "
122 if [ "$answer" == 'yes' ]
125 elif [ "$answer" == 'no' ]
129 echo -n "Assume as normal behaviour? (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" 'trailing 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 given files, but do not modify them.
262 If --dry-run is specified and files are warned, then a message is
263 prompted whether the warnings should be turned to errors.
265 If --dry-run is specified, the warnings are turned to errors.
267 Check all source files in the repository.
269 Check only the modified source files. This option is proper to
270 use before a commit. E.g. all files which are modified or added
271 into the repository will be updated.
273 Check only the changed source files compared to the parent(s) of
274 the current hg node. This option is proper to use as hg hook
275 script. E.g. to check all your commited source files with this
276 script add the following section to the appropriate .hg/hgrc
280 pretxncommit.checksources = scripts/unify-sources.sh -c -n -i
283 Print this help message.
285 The files to check/unify. If no file names are given, the modified
286 source files will be checked/unified (just like using the
287 --modified|-m option).
290 elif [ "$1" == '--dry-run' ] || [ "$1" == '-n' ]
292 [ -n "$ACTION" ] && echo "Conflicting action options" >&2 && exit 1
294 elif [ "$1" == "--all" ] || [ "$1" == '-a' ]
296 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
298 elif [ "$1" == "--changed" ] || [ "$1" == '-c' ]
300 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
302 elif [ "$1" == "--modified" ] || [ "$1" == '-m' ]
304 [ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
306 elif [ "$1" == "--interactive" ] || [ "$1" == "-i" ]
308 [ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
309 WARNING='INTERACTIVE'
310 elif [ "$1" == "--werror" ] || [ "$1" == "-w" ]
312 [ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
314 elif [ $(echo x$1 | cut -c 2) == '-' ]
316 echo "Invalid option $1" >&2 && exit 1
318 [ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1