49 lines
741 B
Bash
Executable File
49 lines
741 B
Bash
Executable File
#!/bin/sh
|
|
|
|
_printhelp()
|
|
{
|
|
cat<<EOF
|
|
Usage: ${0##*/} FILES|FOLDERS
|
|
|
|
Prettify C source code using 'indent'.
|
|
|
|
Alternative to indent: astyle, uncrustify.
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
if [ $# -eq 0 ] || [ "$1" = "-h" ]; then
|
|
_printhelp
|
|
exit
|
|
fi
|
|
|
|
|
|
if ! command -v indent >/dev/null; then
|
|
echo "Please install 'indent'."
|
|
exit
|
|
fi
|
|
|
|
CMD="indent -i4 -ppi4 -bli0 -cli4 -nut"
|
|
_formatc_dir()
|
|
{
|
|
## Note that '+' does not work together with {} concatenation. Don't know
|
|
## why...
|
|
find "$1" -type f \
|
|
-name "*.[ch]" \
|
|
-print \
|
|
-exec $CMD {} \; \
|
|
-exec rm {}"~" \;
|
|
}
|
|
|
|
for i ; do
|
|
[ ! -e "$i" ] && continue
|
|
|
|
if [ -d "$i" ]; then
|
|
_formatc_dir "$i"
|
|
else
|
|
$CMD "$i"
|
|
rm -f "$i~"
|
|
fi
|
|
done
|