papermario/format.sh

37 lines
796 B
Bash
Raw Normal View History

2020-08-19 02:43:40 +02:00
#!/bin/bash
COMPILER_OPTS="-std=gnu89 -Iinclude -Isrc -D_LANGUAGE_C"
2020-08-12 04:08:48 +02:00
shopt -s globstar
2020-08-18 00:07:13 +02:00
FILES="src/**/*.c include/*.h"
2020-08-12 04:08:48 +02:00
if (( $# > 0 )); then
2020-08-18 00:07:13 +02:00
# only process .c and .h files
FILES=$(echo "$@" | sed 's/ /\n/g' | grep '\.[ch]$')
2020-08-18 00:07:13 +02:00
fi
if [[ -z $FILES ]]; then
echo "no .c or .h files specified"
2020-08-12 04:08:48 +02:00
exit
fi
2020-08-18 00:07:13 +02:00
# format
astyle ${FILES} \
--formatted --suffix=none \
--lineend=linux \
--convert-tabs \
--max-code-length=120 \
--min-conditional-indent=1 \
--style=attach \
--align-pointer=type --align-reference=name \
--indent-switches \
--indent-labels \
--pad-oper --pad-comma --pad-header --unpad-paren \
--attach-return-type \
# add newline at eof
find ${FILES} -exec sed -i -e '$a\' {} \;
# lint
clang-tidy -p . ${FILES} -- ${COMPILER_OPTS}