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 [ $FAILED_FILES -gt 0 ]
 
   136     elif [ $WARNED_FILES -gt 0 ]
 
   138 	if [ "$WARNING" == 'INTERACTIVE' ]
 
   140 	    echo -n "Are the files with warnings acceptable? (yes/no) "
 
   143 		if [ "$answer" == 'yes' ]
 
   146 		elif [ "$answer" == 'no' ]
 
   150 		echo -n "Are the files with warnings acceptable? (yes/no) "
 
   152 	elif [ "$WARNING" == 'WERROR' ]
 
   159 function check_begin() {
 
   165 function check_end() {
 
   166     if [ $FAILED == YES ]
 
   170     if [ $WARNED == YES ]
 
   180 function header_check() {
 
   181     if echo $1 | grep -q -E 'Makefile\.am$'
 
   188     (echo "/* -*- mode: C++; indent-tabs-mode: nil; -*-
 
   190  * This file is a part of LEMON, a generic C++ optimization library.
 
   192  * Copyright (C) "$YEAR"
 
   193  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
 
   194  * (Egervary Research Group on Combinatorial Optimization, EGRES).
 
   196  * Permission to use, modify and distribute this software is granted
 
   197  * provided that this copyright notice appears in all copies. For
 
   198  * precise terms see the accompanying LICENSE file.
 
   200  * This software is provided \"AS IS\" with no warranty of any kind,
 
   201  * express or implied, and with no claim as to its suitability for any
 
   208      /\/\* / && pm==0 { pm=1;}
 
   209      /[^:blank:]/ && (pm==0 || pm==2) { pm=3; print;}
 
   210      /\*\// && pm==1 { pm=2;}
 
   214     "$ACTION"_action "$TMP_FILE" "$1" header
 
   217 function tabs_check() {
 
   218     if echo $1 | grep -q -v -E 'Makefile\.am$'
 
   220         OLD_PATTERN=$(echo -e '\t')
 
   224         NEW_PATTERN=$(echo -e '\t')
 
   227     cat $1 | sed -e "s/$OLD_PATTERN/$NEW_PATTERN/g" >$TMP_FILE
 
   229     "$ACTION"_action "$TMP_FILE" "$1" 'tabs'
 
   232 function spaces_check() {
 
   234     cat $1 | sed -e 's/ \+$//g' >$TMP_FILE
 
   236     "$ACTION"_action "$TMP_FILE" "$1" 'trailing spaces'
 
   239 function long_lines_check() {
 
   240     if cat $1 | grep -q -E '.{81,}'
 
   242 	"$ACTION"_warning $1 'long lines'
 
   248 function process_file() {
 
   249     if [ "$ACTION" == 'update' ]
 
   251         echo -n "    $ACTION $1..."
 
   253         echo "	  $ACTION $1..."
 
   256     CHECKING="header tabs spaces long_lines"
 
   259     for check in $CHECKING
 
   264     if [ "$ACTION" == 'update' ]
 
   270 function process_all {
 
   282     if [ "$1" == '--help' ] || [ "$1" == '-h' ]
 
   289      Check the files, but do not modify them.
 
   291      If --dry-run is specified and the checker emits warnings,
 
   292      then the user is asked if the warnings should be considered
 
   295      Make all warnings into errors.
 
   297      Check all source files in the repository.
 
   299      Check only the modified (and new) source files. This option is
 
   300      useful to check the modification before making a commit.
 
   302      Check only the changed source files compared to the parent(s) of
 
   303      the current hg node.  This option is useful as hg hook script.
 
   304      To automatically check all your changes before making a commit,
 
   305      add the following section to the appropriate .hg/hgrc file.
 
   308        pretxncommit.checksources = scripts/unify-sources.sh -c -n -i
 
   311      Print this help message.
 
   313      The files to check/unify. If no file names are given, the modified
 
   314      source files will be checked/unified (just like using the
 
   315      --modified|-m option).
 
   318     elif [ "$1" == '--dry-run' ] || [ "$1" == '-n' ]
 
   320 	[ -n "$ACTION" ] && echo "Conflicting action options" >&2 && exit 1
 
   322     elif [ "$1" == "--all" ] || [ "$1" == '-a' ]
 
   324 	[ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
 
   326     elif [ "$1" == "--changed" ] || [ "$1" == '-c' ]
 
   328 	[ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
 
   330     elif [ "$1" == "--modified" ] || [ "$1" == '-m' ]
 
   332 	[ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
 
   334     elif [ "$1" == "--interactive" ] || [ "$1" == "-i" ]
 
   336 	[ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
 
   337 	WARNING='INTERACTIVE'
 
   338     elif [ "$1" == "--werror" ] || [ "$1" == "-w" ]
 
   340 	[ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
 
   342     elif [ $(echo x$1 | cut -c 2) == '-' ]
 
   344 	echo "Invalid option $1" >&2 && exit 1
 
   346 	[ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1