Uncrustify: Difference between revisions
Jump to navigation
Jump to search
Line 52: | Line 52: | ||
return 0; |
return 0; |
||
} |
} |
||
</source> |
|||
=== Bug - operator[] break method alignment=== |
|||
When <code>align_on_operator=true</code>, and <code>align_var_def_amp_style = 0</code>: |
|||
<source lang=c> |
|||
class Graph { |
|||
iterator end(); |
|||
Tree * GetSpanningTree(void); |
|||
Node & operator[] (int id); // Break alignment |
|||
size_t size(); |
|||
int Squeeze(); |
|||
}; |
|||
</source> |
</source> |
Revision as of 15:02, 4 September 2017
Uncrustify is highly configurable source beautifier.
Reference
Build
Since v0.63, build with cmake. Instructions are given in the README:
mkdir build
cd build
cmake ..
make # or cmake --build .
sudo make install # or sudo cmake --install
On Windows, install cmake, then it works the same:
md build
cd build
cmake ..
cmake --build . --config Release
You need a Windows compiler, like Visual Studio Express.
Tips
Canonical indent
The script below perform a canonical indentation as follows:
- Force #define on one line, and remove excess whitespace
- Force all code on one line, but
- Respect LF in block comments or before/after line comment
- Keep empty lines
- Indent
find . -name "*.[ch]" -type f -print0|xargs -0 sed -ri ':b s/\\$//;T;N;s/[ \t]*\n[ \t]*/ /;t b'
find . -name "*.[ch]" -type f -print0|xargs -0 sed -ri 's/^[ \t]*#define[ \t]+([a-zA-Z0-9_]+(\([^)]*\))?[ \t])[ \t]+/#define \1/'
find . -name "*.[ch]" -type f -print0|xargs -0 sed -ri ':b /\/\/|^[ \t]*$|#/b; N;/#|\n[ \t]*\/\/|\n$/b; /\/\*/{:c /\*\//b;N;b c}; s/[ \t]*\n[ \t]*/ /;b b'
# indent 5 times for stability
for i in $(seq 1 5); do indent include/* source/*; done
Troubleshoot
Bug - comment line not indented with tabs
int main(void)
{
// This line indented with space should be indented with tabs
helloWorld();
return 0;
}
Bug - operator[] break method alignment
When align_on_operator=true
, and align_var_def_amp_style = 0
:
class Graph {
iterator end();
Tree * GetSpanningTree(void);
Node & operator[] (int id); // Break alignment
size_t size();
int Squeeze();
};