forked from mavlink/mavlink
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat_xml.sh
executable file
·67 lines (59 loc) · 1.19 KB
/
format_xml.sh
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
#!/usr/bin/env bash
set -e
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# Initialize variables
mode="format"
xml_dir="message_definitions"
keep_old=0
while getopts "h?cd:o" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
c) mode="check"
;;
d) xml_dir=${OPTARG}
;;
o) keep_old=1
;;
esac
done
shift $(($OPTIND - 1))
xml_file="$1"
if [ "$xml_file" == "" ]
then
xml_files=$(find $xml_dir -name "*.xml")
else
xml_files="$xml_dir/$xml_file"
fi
echo "processing file(s):"
echo "$xml_files"
ret=0
for f in $xml_files
do
xmllint -format "${f}" > "${f}".new
case "$mode" in
format)
if ! cmp "${f}" "${f}".new >/dev/null 2>&1
then
echo "formatting $f"
if [ $keep_old -eq 1 ]
then
cp "${f}" "${f}".old
fi
cp "${f}".new "${f}"
fi
;;
check)
if ! cmp "${f}" "${f}".new >/dev/null 2>&1
then
echo "file $f needs formatting - run ./scripts/format_xml.sh $f"
ret=1
fi
;;
esac
rm "${f}".new
done
exit $ret