Add missing new file
[xapian.git] / xapian-maintainer-tools / run-clang-format
blobbb3a17a1f6d0357cf64ed493e55d919fe9e2093b
1 #!/bin/sh
2 set -e
4 # Experimental.
6 # This script attempts to reformat to match Xapian coding conventions
7 # but it's currently a work-in-progress.
9 # The results should be manually checked before committing.
11 files=`git ls-files '*.cc' '*.h'|grep -v 'tests/\(harness/\|apitest\)'`
12 ${CLANG_FORMAT:-clang-format-5.0} -i $files
13 # Fix-up LOGCALL uses to be on a single line regardless of length.
14 perl -pi -e 'if (/^\s+LOGCALL/) { while (!/;$/) { chomp; print; $_ = <>; s/^\s*/ / }}' $files
15 # Fix-up "try" wrapped around a whole function.
16 # Fix-up goto labels.
17 # Fix-up for with empty first statement.
18 perl -pi -e 's/^(\s*)(.*\)) (try \{)/$1$2\n$1$3/;s/^[ \t]+((?!default|p(?:rivate|rotected|ublic))[A-Za-z]\w*:)(?!:)/$1/;s/(^[ \t]+for \();/$1 ;/' $files
19 # Add back newline before end of namespace block.
20 perl -pi -e '$e = /^\}/; if ($l && $e) { print "\n"; $l=0 } else { $l=$e }' $files
21 perl -pi -e '$e = /^\}/; if ($l && $e) { print "\n"; $l=0 } else { $l=$e }' $files