ambevar-dotfiles/.scripts/prettyc

49 lines
741 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-11-14 18:12:57 +01:00
Prettify C source code using 'indent'.
2013-06-25 22:56:10 +02:00
Alternative to indent: astyle, uncrustify.
2013-11-14 18:12:57 +01:00
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
2013-11-14 18:12:57 +01:00
CMD="indent -i4 -ppi4 -bli0 -cli4 -nut"
_formatc_dir()
{
2013-11-14 18:12:57 +01:00
## Note that '+' does not work together with {} concatenation. Don't know
## why...
find "$1" -type f \
-name "*.[ch]" \
-print \
2013-11-14 18:12:57 +01:00
-exec $CMD {} \; \
-exec rm {}"~" \;
}
for i ; do
2013-11-14 18:12:57 +01:00
[ ! -e "$i" ] && continue
if [ -d "$i" ]; then
_formatc_dir "$i"
else
2013-11-14 18:12:57 +01:00
$CMD "$i"
rm -f "$i~"
fi
done