#!/bin/bash
#
# Expand tabs in all well-known file types
# + Strip trailing whitespace

TYPES="ac c clang-format cmake cxx dox fl gitattributes gitignore h H html man md mm rc txt xml yml"

function fail() {
  echo
  echo "*** $@ FAILED ***"
  echo
}

for ext in $TYPES; do
  echo
  echo "=================================================="
  echo "***                    $ext"
  echo "=================================================="
  echo

  for f in `git ls-files \
      | egrep -v '^jpeg|^png|^zlib|^nano|stb_truetype.h' \
      | grep "\\.${ext}\$"`;
  do

    : echo $f
    echo -n "."

    expand $f > $f.tmp && mv $f.tmp $f || fail expand $f
    sed -i -e's/[[:space:]]*$//' $f || fail sed $f

  done
done

echo ""
