scripts/unify-sources.sh
changeset 416 76287c8caa26
parent 331 2f5c0c42a5cd
child 396 c5f010a5647a
equal deleted inserted replaced
5:32ecc0715318 6:6ae052554994
    84 	((++WARNED_FILES))
    84 	((++WARNED_FILES))
    85     fi
    85     fi
    86 }
    86 }
    87 
    87 
    88 function check_action() {
    88 function check_action() {
       
    89     if [ "$3" == 'tabs' ]
       
    90     then
       
    91         PATTERN=$(echo -e '\t')
       
    92     elif [ "$3" == 'trailing spaces' ]
       
    93     then
       
    94         PATTERN='\ +$'
       
    95     else
       
    96         PATTERN='*'
       
    97     fi
       
    98 
    89     if ! diff -q $1 $2 >/dev/null
    99     if ! diff -q $1 $2 >/dev/null
    90     then
   100     then
    91 	echo
   101         if [ "$PATTERN" == '*' ]
    92 	echo -n "      $3 failed at line(s): "
   102         then
    93 	echo -n $(diff $1 $2 | grep '^[0-9]' | sed "s/^\(.*\)c.*$/ \1/g" | 
   103             diff $1 $2 | grep '^[0-9]' | sed "s|^\(.*\)c.*$|$2:\1: check failed: $3|g" |
    94 	          sed "s/,/-/g" | paste -s -d',')
   104               sed "s/:\([0-9]*\),\([0-9]*\):\(.*\)$/:\1:\3 (until line \2)/g"
    95 	FAILED=YES
   105         else
       
   106             grep -n -E "$PATTERN" $2 | sed "s|^\([0-9]*\):.*$|$2:\1: check failed: $3|g"
       
   107         fi
       
   108         FAILED=YES
    96     fi
   109     fi
    97 }
   110 }
    98 
   111 
    99 function check_warning() {
   112 function check_warning() {
   100     echo
       
   101     if [ "$2" == 'long lines' ]
   113     if [ "$2" == 'long lines' ]
   102     then
   114     then
   103         echo -n "      $2 warning at line(s): "
   115         grep -n -E '.{81,}' $1 | sed "s|^\([0-9]*\):.*$|$1:\1: warning: $2|g"
   104         echo -n $(grep -n -E '.{81,}' $1 | sed "s/^\([0-9]*\)/ \1\t/g" | 
   116     else
   105                   cut -f 1 | paste -s -d',')
   117         echo "$1: warning: $2"
   106     else
       
   107         echo -n "      $2 warning"
       
   108     fi
   118     fi
   109     WARNED=YES
   119     WARNED=YES
   110 }
   120 }
   111 
   121 
   112 function check_init() {
   122 function check_init() {
   234 }
   244 }
   235 
   245 
   236 # process the file
   246 # process the file
   237 
   247 
   238 function process_file() {
   248 function process_file() {
   239     echo -n "    $ACTION $1..."
   249     if [ "$ACTION" == 'update' ]
       
   250     then
       
   251         echo -n "    $ACTION $1..."
       
   252     else
       
   253         echo "	  $ACTION $1..."
       
   254     fi
   240 
   255 
   241     CHECKING="header tabs spaces long_lines"
   256     CHECKING="header tabs spaces long_lines"
   242 
   257 
   243     "$ACTION"_begin $1
   258     "$ACTION"_begin $1
   244     for check in $CHECKING
   259     for check in $CHECKING
   245     do
   260     do
   246 	"$check"_check $1
   261 	"$check"_check $1
   247     done
   262     done
   248     "$ACTION"_end $1
   263     "$ACTION"_end $1
   249     echo
   264     if [ "$ACTION" == 'update' ]
       
   265     then
       
   266         echo
       
   267     fi
   250 }
   268 }
   251 
   269 
   252 function process_all {
   270 function process_all {
   253     "$ACTION"_init
   271     "$ACTION"_init
   254     while read file
   272     while read file