scripts/unify-sources.sh
changeset 331 2f5c0c42a5cd
parent 325 0fbbb4bc42dd
parent 329 d900fd1e760f
child 341 f8832dc16d45
     1.1 --- a/scripts/unify-sources.sh	Mon Oct 20 20:03:14 2008 +0200
     1.2 +++ b/scripts/unify-sources.sh	Wed Oct 22 14:37:43 2008 +0100
     1.3 @@ -88,13 +88,24 @@
     1.4  function check_action() {
     1.5      if ! diff -q $1 $2 >/dev/null
     1.6      then
     1.7 -	echo -n " [$3 failed]"
     1.8 +	echo
     1.9 +	echo -n "      $3 failed at line(s): "
    1.10 +	echo -n $(diff $1 $2 | grep '^[0-9]' | sed "s/^\(.*\)c.*$/ \1/g" | 
    1.11 +	          sed "s/,/-/g" | paste -s -d',')
    1.12  	FAILED=YES
    1.13      fi
    1.14  }
    1.15  
    1.16  function check_warning() {
    1.17 -    echo -n " [$2 warning]"
    1.18 +    echo
    1.19 +    if [ "$2" == 'long lines' ]
    1.20 +    then
    1.21 +        echo -n "      $2 warning at line(s): "
    1.22 +        echo -n $(grep -n -E '.{81,}' $1 | sed "s/^\([0-9]*\)/ \1\t/g" | 
    1.23 +                  cut -f 1 | paste -s -d',')
    1.24 +    else
    1.25 +        echo -n "      $2 warning"
    1.26 +    fi
    1.27      WARNED=YES
    1.28  }
    1.29  
    1.30 @@ -212,7 +223,7 @@
    1.31      TMP_FILE=`mktemp`
    1.32      cat $1 | sed -e 's/ \+$//g' >$TMP_FILE
    1.33  
    1.34 -    "$ACTION"_action "$TMP_FILE" "$1" 'spaces'
    1.35 +    "$ACTION"_action "$TMP_FILE" "$1" 'trailing spaces'
    1.36  }
    1.37  
    1.38  function long_lines_check() {
    1.39 @@ -225,7 +236,7 @@
    1.40  # process the file
    1.41  
    1.42  function process_file() {
    1.43 -    echo -n "    $ACTION " $1...
    1.44 +    echo -n "    $ACTION $1..."
    1.45  
    1.46      CHECKING="header tabs spaces long_lines"
    1.47  
    1.48 @@ -265,7 +276,7 @@
    1.49    --werror|-w
    1.50       Make all warnings into errors.
    1.51    --all|-a
    1.52 -     All files in the repository will be checked.
    1.53 +     Check all source files in the repository.
    1.54    --modified|-m
    1.55       Check only the modified (and new) source files. This option is
    1.56       useful to check the modification before making a commit.
    1.57 @@ -281,36 +292,36 @@
    1.58    --help|-h
    1.59       Print this help message.
    1.60    files
    1.61 -     The files to check/unify. If no file names are given, the
    1.62 -     modified source will be checked/unified
    1.63 -
    1.64 +     The files to check/unify. If no file names are given, the modified
    1.65 +     source files will be checked/unified (just like using the
    1.66 +     --modified|-m option).
    1.67  "
    1.68          exit 0
    1.69      elif [ "$1" == '--dry-run' ] || [ "$1" == '-n' ]
    1.70      then
    1.71 -	[ -n "$ACTION" ] && echo "Invalid option $1" >&2 && exit 1
    1.72 +	[ -n "$ACTION" ] && echo "Conflicting action options" >&2 && exit 1
    1.73  	ACTION=check
    1.74      elif [ "$1" == "--all" ] || [ "$1" == '-a' ]
    1.75      then
    1.76 -	[ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1
    1.77 +	[ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
    1.78  	FILES=all_files
    1.79      elif [ "$1" == "--changed" ] || [ "$1" == '-c' ]
    1.80      then
    1.81 -	[ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1
    1.82 +	[ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
    1.83  	FILES=changed_files
    1.84      elif [ "$1" == "--modified" ] || [ "$1" == '-m' ]
    1.85      then
    1.86 -	[ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1
    1.87 +	[ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1
    1.88  	FILES=modified_files
    1.89      elif [ "$1" == "--interactive" ] || [ "$1" == "-i" ]
    1.90      then
    1.91 -	[ -n "$WARNING" ] && echo "Invalid option $1" >&2 && exit 1
    1.92 +	[ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
    1.93  	WARNING='INTERACTIVE'
    1.94      elif [ "$1" == "--werror" ] || [ "$1" == "-w" ]
    1.95      then
    1.96 -	[ -n "$WARNING" ] && echo "Invalid option $1" >&2 && exit 1
    1.97 +	[ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1
    1.98  	WARNING='WERROR'
    1.99 -    elif [ $(echo $1 | cut -c 1) == '-' ]
   1.100 +    elif [ $(echo x$1 | cut -c 2) == '-' ]
   1.101      then
   1.102  	echo "Invalid option $1" >&2 && exit 1
   1.103      else