|
|
|
|
— |
automated_code_tidying [2017/12/06 11:18] (current) |
| | ====== Automated Code Tidying ====== |
| | ===== tidy-source.sh ===== |
| | This simple script searches a directory for source files, and performs the following actions: |
| | * Replaces tabs with spaces |
| | * Ensures the file ends with a newline |
| | * Replaces CRLF with LF |
| | * Removes any trailing whitespace on each line of code |
| | <code>#!/bin/bash |
| |
| | DIR=$1 |
| | TABWIDTH=4 |
| | |
| | ( cd $DIR; for i in $( find -regex ".*\.\(c\|cpp\|cxx\|cc\|h\|\hpp\)" | sort ); do echo $i; expand -t$TABWIDTH $i | sed '${/^$/!s/$/\ |
| | /;}' | sed 's/\x0D$//' | sed 's/ *$//' > x; mv x $i; done ) |
| | |
| | git commit -am"Tidied $DIR. Replaced tabs with spaces, ensured each source file ends with a newline, replaced CRLF with LF, and removed trailing whitespace"</code> |
| | ===== Other Tools ===== |
| | * [[http://clang.llvm.org/extra/clang-tidy.html|clang-tidy]] - Code formatting built around the clang C++ language front end. |
| | * [[http://astyle.sourceforge.net/|astyle]] - A Free, Fast and Small Automatic Formatter for C, C++, C++/CLI, C#, and Java Source Code |