#! /bin/sh

#================================================================
# tabcheck
# Find files including dispensable tab and space characters
#================================================================


# set variables
regex='(\.h|\.c|\.cc|\.cpp|\.cxx|\.java|\.pl|\.pm|\.pod|\.rb|\.rd)$'
tabcode=`printf '\t'`


# find tab
find . -type f | egrep $regex |
while read file
do
  printf 'Checking %s ... ' $file
  err=0
  if grep "$tabcode" $file > /dev/null
  then
    printf '### !!! TAB FOUND !!! ###'
    err=1
  fi
  if grep ' $' $file > /dev/null
  then
    printf '### !!! TAILING SPACE FOUND !!! ###'
    err=1
  fi
  [ "$err" = 0 ] && printf 'ok'
  printf '\n'
done


# exit normally
exit 0



# END OF FILE
