Commit ece6b6feb4ea82d82985c4820f1e88724d1b1aa8
1 parent
554a870b
Add format-code script
Showing
1 changed file
with
35 additions
and
0 deletions
format-code
0 → 100755
| 1 | +#!/bin/sh | ||
| 2 | + | ||
| 3 | +# Formatting rules are in .clang-format. | ||
| 4 | + | ||
| 5 | +# To protect a block of code from automatic formatting, enclose in | ||
| 6 | +# comments such as | ||
| 7 | +# | ||
| 8 | +# // clang-format off | ||
| 9 | +# ... | ||
| 10 | +# // clang-format on | ||
| 11 | + | ||
| 12 | +# Sometimes, a comment of the form `// line-break` may appear in the | ||
| 13 | +# code to prevent clang-format from removing an intentional line | ||
| 14 | +# break. | ||
| 15 | + | ||
| 16 | +# For emacs users, the file `.dir-locals.el` configures cc-mode for an | ||
| 17 | +# indentation style that is close to but not exactly like what | ||
| 18 | +# clang-format produces. clang-format is authoritative. | ||
| 19 | + | ||
| 20 | +# Please see "Code Formatting" in the manual for additional notes. | ||
| 21 | + | ||
| 22 | +cd $(dirname $0) | ||
| 23 | +for i in $(find . -name 'build*' -prune -o '(' \ | ||
| 24 | + -name '*.hh' -o -name '*.h' -o -name '*.cc' -o -name '*.c' \ | ||
| 25 | + ')' -print); do | ||
| 26 | + if clang-format < $i >| $i.new; then | ||
| 27 | + if diff -q $i $i.new >/dev/null 2>/dev/null; then | ||
| 28 | + echo "okay: $i" | ||
| 29 | + rm $i.new | ||
| 30 | + else | ||
| 31 | + echo "updated: $i" | ||
| 32 | + mv $i.new $i | ||
| 33 | + fi | ||
| 34 | + fi | ||
| 35 | +done |