From ad5ce96253b3fa6209de84a6d4072b3f471a188c Mon Sep 17 00:00:00 2001 From: Alex Shepherd Date: Sun, 9 May 2021 16:51:08 +1200 Subject: [PATCH] after making a mess of a PR from davidzuhn and not having the git skills to fix it, I've resorted to simply copying the desired files from his PR. I've excluded his reformatted NmraDcc.h NmraDcc.cpp because there were too many merge conflicts now, so I'll reapply his formatting rules in another commit --- .astylerc | 55 ++++++++++++++++++++++++++++++++++++++++++++++ .gitignore | 2 ++ README.md | 11 ++++++++++ support/pre-commit | 20 +++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 .astylerc create mode 100755 support/pre-commit diff --git a/.astylerc b/.astylerc new file mode 100644 index 0000000..468ecf6 --- /dev/null +++ b/.astylerc @@ -0,0 +1,55 @@ +# http://astyle.sourceforge.net/astyle.html#_style=allman +# use the allman style for braces +--style=allman + +# http://astyle.sourceforge.net/astyle.html#_lineend +# newlines for all line endings +--lineend=linux + +# http://astyle.sourceforge.net/astyle.html#_indent=spaces +# 4 space indents +--indent=spaces=4 + +# http://astyle.sourceforge.net/astyle.html#_add-braces +# don't leave any unbraced one-line blocks by changing: +# if (thing) +# statement; +# +# to +# if (thing) +# { +# statement; +# } +# +# --add-braces + +# http://astyle.sourceforge.net/astyle.html#_indent-preproc-cond +# line up #if/#endif with the code +# +# statement; +# #if SOMETHING +# statement; +# #endif +# +--indent-preproc-cond + +# http://astyle.sourceforge.net/astyle.html#_indent-preproc-block +# indent top level preprocessor block contents +# +# #ifdef __ARDUINO__ +# #include "Arduino.h" +# #endif +# +--indent-preproc-block + +# normalize spacing around parenthese +# http://astyle.sourceforge.net/astyle.html#_unpad-paren +# first, remove all whitespace on either side of a paren +--unpad-paren +# http://astyle.sourceforge.net/astyle.html#_pad-paren-out +# then add a space on the "outer" side of a paren +--pad-paren-out + +# http://astyle.sourceforge.net/astyle.html#_max-code-length +# we've got big monitors these days.... +--max-code-length=180 diff --git a/.gitignore b/.gitignore index 3160275..0a7a756 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .development *.zip +*.orig +*~ diff --git a/README.md b/README.md index d111399..4b1f793 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,14 @@ The library currently supports the AVR ATTiny84/85 & ATMega88/168/328/32u4 and T extern void notifyDccAccState( uint16_t Addr, uint16_t BoardAddr, uint8_t OutputAddr, uint8_t State ) extern void notifyDccSigState( uint16_t Addr, uint8_t OutputIndex, uint8_t State) + + +Developers: + Use of the supplied git pre-commit hook is encouraged. This will require installation of the 'astyle' package for formatting source file. + See http://astyle.sourceforge.net for details on this package. + + On Linux or Mac development machines, run the following command after you clone the repository: + + ln -s support/pre-commit .git/hooks/pre-commit + + Reformatting the source code to the preferred style is easy using astyle. Just run 'astyle --options=.astylerc NmraDcc.h NmraDcc.cpp' diff --git a/support/pre-commit b/support/pre-commit new file mode 100755 index 0000000..19f401d --- /dev/null +++ b/support/pre-commit @@ -0,0 +1,20 @@ +#!/bin/sh + +FORMAT_SOURCES="NmraDcc.h NmraDcc.cpp" + +error=0 + +for file in ${FORMAT_SOURCES} +do + output=$(mktemp -t stylecheckXXXXXXX) + astyle --options=.astylerc < $file > $output + if ! cmp -s $file $output + then + echo "Formatting on $file doesn't match expectations" + diff -u $file $output + error=1 + fi + [ -f $output ] && rm $output +done + +exit $error