Skip to content

Instantly share code, notes, and snippets.

@dan82840
Created February 14, 2017 01:15
Show Gist options
  • Save dan82840/8a1badcd5b8cb747a02dfe24d9168635 to your computer and use it in GitHub Desktop.
Save dan82840/8a1badcd5b8cb747a02dfe24d9168635 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# ./coding-style.sh [File or Directory]
#
options="--style=kr
--mode=c
--indent=tab=4
--brackets=linux
--indent-labels
--indent-switches
--indent-col1-comments
--pad-oper
--pad-header
--unpad-paren
--add-brackets
--keep-one-line-statements
--convert-tabs
--indent-preprocessor
--suffix=none"
usage() {
echo "Usage: coding-style.sh [File or Directory]"
}
chk_args() {
if [ -z $2 ]; then
usage
exit 1
fi
}
chk_astyle() {
which astyle >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Need to install astyle !!!"
exit 1
fi
}
main() {
local d=$1
if [ -d $d ]; then
find $d -regex ".*\.\(c\|cc\|h\|cpp\)" -exec astyle $options "{}" \;
else
astyle $options $d
fi
}
chk_args $# $1
chk_astyle
main $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment