#! /bin/sh

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


# set variables
LANG=C ; export LANG
LC_ALL=C ; export LC_ALL
PATH="$PATH:/usr/local/bin:.:.." ; export PATH
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib:.:..:../.." ; export LD_LIBRARY_PATH
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
