papermario/format.sh

41 lines
936 B
Bash
Raw Normal View History

2020-12-12 09:55:21 +01:00
#!/usr/bin/env bash
2020-08-19 02:43:40 +02:00
2020-10-22 06:54:03 +02:00
COMPILER_OPTS="-std=gnu89 -Iinclude -Isrc -D_LANGUAGE_C -DSCRIPT(...)={}"
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=0 \
2020-08-18 00:07:13 +02:00
--style=attach \
--align-pointer=type --align-reference=name \
--indent-switches \
--pad-oper --pad-comma --pad-header --unpad-paren \
--attach-return-type \
2020-11-08 13:16:10 +01:00
--keep-one-line-blocks \
--keep-one-line-statements
2020-08-18 00:07:13 +02:00
# add newline at eof
find ${FILES} -exec sed -i -e '$a\' {} \;
# lint
2020-10-13 21:48:24 +02:00
C_FILES=$(echo "$FILES" | grep '\.c$')
if [[ ! -z $C_FILES ]]; then
clang-tidy -p . ${C_FILES} -- ${COMPILER_OPTS}
fi