forked from pmret/papermario
-
Notifications
You must be signed in to change notification settings - Fork 0
/
format.sh
executable file
·40 lines (33 loc) · 919 Bytes
/
format.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
COMPILER_OPTS="-std=gnu89 -Iinclude -Isrc -D_LANGUAGE_C"
shopt -s globstar
FILES="src/**/*.c include/*.h"
if (( $# > 0 )); then
# only process .c and .h files
FILES=$(echo "$@" | sed 's/ /\n/g' | grep '\.[ch]$')
fi
if [[ -z $FILES ]]; then
echo "no .c or .h files specified"
exit
fi
# format
astyle ${FILES} \
--formatted --suffix=none \
--lineend=linux \
--convert-tabs \
--max-code-length=120 \
--min-conditional-indent=0 \
--style=attach \
--align-pointer=type --align-reference=name \
--indent-switches \
--pad-oper --pad-comma --pad-header --unpad-paren \
--attach-return-type \
--keep-one-line-blocks \
--keep-one-line-statements
# add newline at eof
find ${FILES} -exec sed -i -e '$a\' {} \;
# lint
C_FILES=$(echo "$FILES" | grep '\.c$')
if [[ ! -z $C_FILES ]]; then
clang-tidy -p . ${C_FILES} -- ${COMPILER_OPTS}
fi