#!/bin/sh
# $Id: indent-perl,v 1.3 2014/03/30 19:44:15 tom Exp $
# vi:ts=4 sw=4
doit=yes
show=no
temp=`mktemp`
trap "rm -f $temp" 0 1 2 5 15

usage() {
	cat <<EOF
usage: $0 [options] [html-files]

options:
  -n   no-op
  -v   verbose, showing diff
EOF
	exit 1
}

set -- `getopt 'nv' $*`
if test $? != 0 || test $# = 1
then
	usage
fi

for name in $*
do
	case $name in
	-n)
		doit=no
		;;
	-v)
		show=yes
		;;
	--)
		;;
	*)
		case `file $name` in
		*perl*|*Perl*)
			;;
		*)
			echo "...skipping $name (not a perl script)"
			continue
			;;
		esac
		perltidy $name 2>/dev/null -o $temp
		if cmp -s $name $temp
		then
			test $show = yes && echo "... unchanged $name"
		else
			test $show = yes && diff -u $name $temp
			test $doit = yes && copy -v $temp $name
		fi
		rm -f $temp
		;;
	esac
done
