#!/bin/sh
# rename is provided to easily update code using sed-command files

USAGE='rename sed-command-file file1 file2...
    apply all sed-command-file to the files file1 file2
'

if test "$1" = '-?'; then echo "$USAGE";exit 1;fi
commands=$1
shift

for i in $*
do if test -f $i
   then echo -n "$i: "
	echo -n "."
	sed -f $commands $i > /tmp/rename.sed.$$;
	if test ! -s /tmp/rename.sed.$$; then rm /tmp/rename.sed.$$; exit 1;fi
	if cmp /tmp/rename.sed.$$ $i >/dev/null; then echo 
	else cp $i $i.BAK; cp /tmp/rename.sed.$$ $i; echo " modified."
	fi
   fi
done

rm -f /tmp/rename.sed.$$ /tmp/rename.sed.$$.org
