#!/bin/sh

# in-place "canonicalize-whitespace" conversion for files in $*:
#   * Convert tabs to spaces.
#   * Delete trailing whitespace.
# (on $*, in place, overwriting the old file)

scratchfilename=/tmp/canonicalize-whitespace-1.$$.tmp

echo '/in canonicalize-whitespace-1'
echo '/$*'=$*
echo '/$scratchfilename='$scratchfilename

for f in $*; do

 
  if egrep '(	|[	 ]+$)' $f >/dev/null
  then
    echo '/$f'=$f

    # We reuse the "expand" GNU utility to remove tabs, but if it turns out
    # not to be available everywhere (or someone has defined "expand" to 
    # mean something else on some other class of system!) we could probably
    # hand-code a replacement in a few lines.
    expand $f > $scratchfilename

    sed 's/[ 	]*$//' < $scratchfilename > $f
  fi

done

rm -f $scratchfilename
