ambevar-dotfiles/.scripts/prettyc

52 lines
801 B
Plaintext
Raw Normal View History

#!/bin/sh
2013-10-23 10:50:19 +02:00
_printhelp()
{
cat<<EOF
2013-10-23 10:50:19 +02:00
Usage: ${0##*/} FILES|FOLDERS
2013-06-25 22:56:10 +02:00
Format C source code using 'indent'.
Alternative to indent: astyle, uncrustify.
EOF
2013-10-23 10:50:19 +02:00
}
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
_printhelp
exit
fi
2013-10-23 10:50:19 +02:00
if ! command -v indent >/dev/null; then
2013-06-25 22:56:10 +02:00
echo "Please install 'indent'."
exit
fi
_formatc_dir()
{
find "$1" -type f \
-name "*.[ch]" \
-print \
-exec indent -i4 -ppi4 -bli0 -cli4 -nut {} \;
## Remove backup files.
find "$1" -type f \( \
-name "*.[ch]~" -o \
-name "*.[ch]~[0-9]*~" \) \
-delete
}
for i ; do
if [ ! -e "$i" ]; then
continue
fi
if [ -d "$i" ]; then
_formatc_dir "$i"
else
indent -i4 -ppi4 -bli0 -cli4 -nut "$i"
rm -f "$i~" "$i~[0-9]*~"
fi
done