Add indent.sh helper script
This commit is contained in:
parent
aac116bc8f
commit
cffee8748f
1 changed files with 52 additions and 5 deletions
|
|
@ -1,6 +1,53 @@
|
|||
#!/bin/sh
|
||||
D="$(dirname "$PWD/$0")"
|
||||
#shellcheck disable=SC2048
|
||||
#shellcheck disable=SC2086
|
||||
uncrustify -c ${D}/uncrustify.cfg $*
|
||||
diff -ru "$1" "$1.uncrustify"
|
||||
|
||||
IFILE="$1"
|
||||
|
||||
if [ -z "${IFILE}" ]; then
|
||||
echo "Usage: indent.sh [-i|-u] [file]"
|
||||
echo " -i - indent in place (modify file"
|
||||
echo " -u - indent in place (modify file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CWD="$PWD"
|
||||
INPLACE=0
|
||||
UNIFIED=0
|
||||
|
||||
if [ "${IFILE}" = "-i" ]; then
|
||||
shift
|
||||
INPLACE=1
|
||||
IFILE="$1"
|
||||
fi
|
||||
|
||||
if [ "${IFILE}" = "-u" ]; then
|
||||
shift
|
||||
UNIFIED=1
|
||||
IFILE="$1"
|
||||
fi
|
||||
|
||||
while : ; do
|
||||
[ "$PWD" = / ] && break
|
||||
if [ -f doc/clang-format ]; then
|
||||
cp -f doc/clang-format ${CWD}/.clang-format
|
||||
(
|
||||
cd "$CWD"
|
||||
clang-format "${IFILE}" > .tmp-format
|
||||
# fix ternary conditional indent
|
||||
cat .tmp-format | sed -e 's, \? ,? ,g' > .tmp-format2
|
||||
# do not space before parenthesis on function signatures
|
||||
awk '{if (/^static/ || /^R_API/) { gsub(/ \(/,"("); }; print;}' \
|
||||
< .tmp-format2 > .tmp-format
|
||||
if [ "$UNIFIED" = 1 ]; then
|
||||
diff -ru "${IFILE}" .tmp-format
|
||||
rm .tmp-format
|
||||
elif [ "$INPLACE" = 1 ]; then
|
||||
mv .tmp-format $a
|
||||
else
|
||||
cat .tmp-format
|
||||
rm .tmp-format
|
||||
fi
|
||||
)
|
||||
rm -f ${CWD}/.clang-format
|
||||
fi
|
||||
cd ..
|
||||
done
|
||||
|
|
|
|||
Loading…
Reference in a new issue