summaryrefslogtreecommitdiffstats
path: root/bin/tidy-bowl
blob: bda37da2fda5a6166cfd04b3f1af42237d7f23ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
########################################################################
#
# This script is invoked by "commitinfo" just after the incoming file has 
# been uploaded to the server.  It gets passed these arguments:
#
#	tidy-bowl file ...
#
# If we approve of the commit for EVERY file in the list, then we return 
# a zero (0).  Any non-zero return aborts the commit, so we must be very
# careful here.
#
# AFAIK, the $PWD is the temporary file where the incoming "file" is located,
# but that needs to be verified.
#
# For every "file" that ends with ".xml", we will attempt to normalize the
# formatting by using tidy(1) to prettyprint it.  We must overwrite "file" so
# that the rest of CVS knows where to find the file.
#
# There doesn't seem to be any way to return error messages, so we'll just bang
# them out to "/var/log/messages".
#
########################################################################
# exit 0		# Early exit while frobbing around
########################################################################
# All ancillary files should be in the same directory as this script
ME=`/bin/basename $0`
PREFIX=`/usr/bin/dirname $0`
########################################################################
USAGE="Usage: ${ME} [-T tool] [-n] [-t tool-args] file..."
NORMTOOL=${PREFIX}/xmlformat
NORMARGS="-v -f ${PREFIX}/xmlformat-fdp.conf"
INPLACE='-i'
while getopts T:nt: c
do
	case "${c}" in
	T)	NORMTOOL="${OPTARG}";;
	n)	INPLACE="";;
	t)	NORMARGS="${OPTARG}";;
	*)	/bin/echo "${USAGE}" >&2; exit 1;;
	esac
done
shift `/usr/bin/expr "${OPTIND}" - 1`
########################################################################
for fn in $@
do
	case "${fn}" in
	*.xml )
		# Make sure we can find the input file
		# /bin/echo "$0: XML file ${fn} prettyprinted."
		if [ ! -f "${fn}" ]; then
			# A non-readable file may be removed. Ever
			# think of that?
			# /bin/echo $0 "Cannot find '${fn}'"
			exit 0
		fi
		# Try to clean it up
		${NORMTOOL} ${NORMARGS} ${INPLACE} "${fn}"
		if [ $? -ne 0 ]; then
			/bin/echo $0 "File '${fn}' unclean."
			exit 1
		fi
		;;
	* )
		# Some other kind of file.  DO NOTHING!!!
		# /bin/echo "$0: file ${fn} left unchanged."
		;;
	esac
done
exit 0