make style: take care of EOF LF

This commit is contained in:
Philippe Teuwen 2019-03-12 00:11:27 +01:00
parent 346af6e3d1
commit f205f9db87
2 changed files with 10 additions and 6 deletions

View file

@ -258,9 +258,7 @@ you shouldn't use it (same for _FOOBAR_H).
=== WHITESPACE === === WHITESPACE ===
Avoid trailing whitespace (no line should end in tab or space). People forget Avoid trailing whitespace (no line should end in tab or space).
this all the time if their editor doesn't handle it, but don't be surprised if
you see someone fixing it from time to time.
"make style" will take care of that.
Keep a newline (blank line) at the end of each file. Keep a newline (blank line) at the end of each file.
"make style" will take care of both.

View file

@ -106,8 +106,14 @@ endif
print-%: ; @echo $* = $($*) print-%: ; @echo $* = $($*)
style: style:
# Make sure astyle is installed
@which astyle >/dev/null || ( echo "Please install 'astyle' package first" ; exit 1 ) @which astyle >/dev/null || ( echo "Please install 'astyle' package first" ; exit 1 )
find . \( -name "*.[ch]" -or -name "*.cpp" -or -name "*.lua" -or -name "Makefile" \) -exec perl -pi -e 's/[ \t\r]+$$//' {} \; # Remove spaces & tabs at EOL, add LF at EOF if needed on *.c, *.h, *.cpp. *.lua, *.py, *.pl, Makefile
find . \( -name "*.[ch]" -or -name "*.cpp" -or -name "*.lua" -or -name "*.py" -or -name "*.pl" -or -name "Makefile" \) \
-exec perl -pi -e 's/[ \t\r]+$$//' {} \; \
-exec sh -c "tail -c1 {} | xxd -p | tail -1 | grep -q -v 0a$$" \; \
-exec sh -c "echo >> {}" \;
# Apply astyle on *.c, *.h, *.cpp
find . \( -name "*.[ch]" -or -name "*.cpp" \) -exec astyle --formatted --mode=c --suffix=none \ find . \( -name "*.[ch]" -or -name "*.cpp" \) -exec astyle --formatted --mode=c --suffix=none \
--indent=spaces=4 --indent-switches --indent-preprocessor \ --indent=spaces=4 --indent-switches --indent-preprocessor \
--keep-one-line-blocks --max-instatement-indent=60 \ --keep-one-line-blocks --max-instatement-indent=60 \