2013-03-03 11:19:50 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-10-23 10:50:19 +02:00
|
|
|
_printhelp()
|
|
|
|
{
|
2013-03-06 22:37:14 +01:00
|
|
|
cat<<EOF
|
2013-10-23 10:50:19 +02:00
|
|
|
Usage: ${0##*/} FILES|FOLDERS
|
2013-03-06 22:37:14 +01:00
|
|
|
|
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
|
|
|
|
2013-03-06 22:37:14 +01:00
|
|
|
EOF
|
2013-10-23 10:50:19 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
|
|
|
|
_printhelp
|
|
|
|
exit
|
2013-03-06 22:37:14 +01:00
|
|
|
fi
|
|
|
|
|
2013-10-23 10:50:19 +02:00
|
|
|
|
2013-10-27 19:50:23 +01:00
|
|
|
if ! command -v indent >/dev/null; then
|
2013-06-25 22:56:10 +02:00
|
|
|
echo "Please install 'indent'."
|
|
|
|
exit
|
|
|
|
fi
|
2013-03-06 22:37:14 +01:00
|
|
|
|
2013-11-14 18:12:57 +01:00
|
|
|
CMD="indent -i4 -ppi4 -bli0 -cli4 -nut"
|
2013-03-03 11:19:50 +01:00
|
|
|
_formatc_dir()
|
|
|
|
{
|
2013-11-14 18:12:57 +01:00
|
|
|
## Note that '+' does not work together with {} concatenation. Don't know
|
|
|
|
## why...
|
2013-03-03 11:19:50 +01:00
|
|
|
find "$1" -type f \
|
|
|
|
-name "*.[ch]" \
|
|
|
|
-print \
|
2013-11-14 18:12:57 +01:00
|
|
|
-exec $CMD {} \; \
|
|
|
|
-exec rm {}"~" \;
|
2013-03-03 11:19:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for i ; do
|
2013-11-14 18:12:57 +01:00
|
|
|
[ ! -e "$i" ] && continue
|
2013-03-06 22:37:14 +01:00
|
|
|
|
2013-03-03 11:19:50 +01:00
|
|
|
if [ -d "$i" ]; then
|
|
|
|
_formatc_dir "$i"
|
|
|
|
else
|
2013-11-14 18:12:57 +01:00
|
|
|
$CMD "$i"
|
|
|
|
rm -f "$i~"
|
2013-03-03 11:19:50 +01:00
|
|
|
fi
|
|
|
|
done
|