Skip to content

Commit

Permalink
improve format_xml.sh script, tab to spaces (mavlink#1555)
Browse files Browse the repository at this point in the history
  • Loading branch information
olliw42 authored Feb 4, 2021
1 parent 0851afe commit 9afc65d
Showing 1 changed file with 42 additions and 21 deletions.
63 changes: 42 additions & 21 deletions scripts/format_xml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,61 @@ OPTIND=1 # Reset in case getopts has been used previously in the shell.

# Initialize variables
mode="format"
xml_dir="."
keep_old=0

while getopts "h?c" opt; do
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

xml_files=$(find . -name "*.xml")
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) $xml_files"

ret=0
for f in $xml_files
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"
cp "${f}".new "${f}"
fi
;;
check)
if ! cmp "${f}" "${f}".new >/dev/null 2>&1
then
echo "$f needs formatting - run ./scripts/format_xml.sh $f"
ret=1
fi
;;
esac
rm "${f}".new
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

0 comments on commit 9afc65d

Please sign in to comment.