# This file is a part of LEMON, a generic C++ optimization library.
# Copyright (C) 2003-2009
# Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
# (Egervary Research Group on Combinatorial Optimization, EGRES).
# Permission to use, modify and distribute this software is granted
# provided that this copyright notice appears in all copies. For
# precise terms see the accompanying LICENSE file.
# This software is provided "AS IS" with no warranty of any kind,
# express or implied, and with no claim as to its suitability for any
if [ -n
"$(hg st $1)" ];
then
hg log -l 1 --template
='{date|isodate}\n' $1 |
cut -d
' ' -f 2 | grep -E
'(\.(cc|h|dox)$|Makefile\.am$)' |
while read file;
do echo $HGROOT/
$file;
done
function modified_files
() {
cut -d
' ' -f 2 | grep -E
'(\.(cc|h|dox)$|Makefile\.am$)' |
while read file;
do echo $HGROOT/
$file;
done
function changed_files
() {
hg status --rev
$HG_PARENT1:
$HG_NODE -a -m
hg status --rev
$HG_PARENT2:
$HG_NODE -a -m
} | cut -d
' ' -f 2 | grep -E
'(\.(cc|h|dox)$|Makefile\.am$)' |
while read file;
do echo $HGROOT/
$file;
done
function update_action
() {
if ! diff -q
$1 $2 >/dev/null
function update_warning
() {
echo Update
source files...
echo $CHANGED_FILES out of
$TOTAL_FILES files has been changed.
echo $WARNED_FILES out of
$TOTAL_FILES files triggered warnings.
function update_begin
() {
function check_action
() {
if echo $2 | grep -q -v -E
'Makefile\.am$'
elif [ "$3" == 'trailing spaces' ]
if ! diff -q
$1 $2 >/dev/null
diff
$1 $2 | grep
'^[0-9]' | sed
"s|^\(.*\)c.*$|$2:\1: check failed: $3|g" |
sed
"s/:\([0-9]*\),\([0-9]*\):\(.*\)$/:\1:\3 (until line \2)/g"
grep -n -E
"$PATTERN" $2 | sed
"s|^\([0-9]*\):.*$|$2:\1: check failed: $3|g"
function check_warning
() {
if [ "$2" == 'long lines' ]
grep -n -E
'.{81,}' $1 | sed
"s|^\([0-9]*\):.*$|$1:\1: warning: $2|g"
echo Check
source files...
echo $FAILED_FILES out of
$TOTAL_FILES files has been failed.
echo $WARNED_FILES out of
$TOTAL_FILES files triggered warnings.
if [ $WARNED_FILES -gt 0 -o
$FAILED_FILES -gt 0
]
if [ "$WARNING" == 'INTERACTIVE' ]
echo -n
"Are the files with errors/warnings acceptable? (yes/no) "
if [ "$answer" == 'yes' ]
elif [ "$answer" == 'no' ]
echo -n
"Are the files with errors/warnings acceptable? (yes/no) "
elif [ "$WARNING" == 'WERROR' ]
function header_check
() {
if echo $1 | grep -q -E
'Makefile\.am$'
(echo "/* -*- mode: C++; indent-tabs-mode: nil; -*-
* This file is a part of LEMON, a generic C++ optimization library.
* Copyright (C) 2003-"$(hg_year
$1)"
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
* (Egervary Research Group on Combinatorial Optimization, EGRES).
* Permission to use, modify and distribute this software is granted
* provided that this copyright notice appears in all copies. For
* precise terms see the accompanying LICENSE file.
* This software is provided \"AS IS\" with no warranty of any kind,
* express or implied, and with no claim as to its suitability for any
/\/\* / && pm==0 { pm=1;}
/[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;}
"$ACTION"_action
"$TMP_FILE" "$1" header
if echo $1 | grep -q -v -E
'Makefile\.am$'
OLD_PATTERN=$(echo -e
'\t')
NEW_PATTERN=$(echo -e
'\t')
cat
$1 | sed -e
"s/$OLD_PATTERN/$NEW_PATTERN/g" >
$TMP_FILE
"$ACTION"_action
"$TMP_FILE" "$1" 'tabs'
function spaces_check
() {
cat
$1 | sed -e
's/ \+$//g' >
$TMP_FILE
"$ACTION"_action
"$TMP_FILE" "$1" 'trailing spaces'
function long_lines_check
() {
if cat
$1 | grep -q -E
'.{81,}'
"$ACTION"_warning
$1 'long lines'
function process_file
() {
if [ "$ACTION" == 'update' ]
CHECKING="header tabs spaces long_lines"
if [ "$ACTION" == 'update' ]
if [ "$1" == '--help' ] || [ "$1" == '-h' ]
Check the files, but do not modify them.
If --dry-run is specified and the checker emits warnings,
then the user is asked if the warnings should be considered
Make all warnings into errors.
Check all source files in the repository.
Check only the modified (and new) source files. This option is
useful to check the modification before making a commit.
Check only the changed source files compared to the parent(s) of
the current hg node. This option is useful as hg hook script.
To automatically check all your changes before making a commit,
add the following section to the appropriate .hg/hgrc file.
pretxncommit.checksources = scripts/unify-sources.sh -c -n -i
The files to check/unify. If no file names are given, the modified
source files will be checked/unified (just like using the
elif [ "$1" == '--dry-run' ] || [ "$1" == '-n' ]
[ -n
"$ACTION" ] && echo "Conflicting action options" >&2
&& exit 1
elif [ "$1" == "--all" ] || [ "$1" == '-a' ]
[ -n
"$FILES" ] && echo "Conflicting target options" >&2
&& exit 1
elif [ "$1" == "--changed" ] || [ "$1" == '-c' ]
[ -n
"$FILES" ] && echo "Conflicting target options" >&2
&& exit 1
elif [ "$1" == "--modified" ] || [ "$1" == '-m' ]
[ -n
"$FILES" ] && echo "Conflicting target options" >&2
&& exit 1
elif [ "$1" == "--interactive" ] || [ "$1" == "-i" ]
[ -n
"$WARNING" ] && echo "Conflicting warning options" >&2
&& exit 1
elif [ "$1" == "--werror" ] || [ "$1" == "-w" ]
[ -n
"$WARNING" ] && echo "Conflicting warning options" >&2
&& exit 1
elif [ $(echo x
$1 | cut -c 2
) == '-' ]
echo "Invalid option $1" >&2
&& exit 1
[ -n
"$FILES" ] && echo "Invalid option $1" >&2
&& exit 1