File: format.sh

package info (click to toggle)
iqtree 2.0.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 14,620 kB
  • sloc: cpp: 142,571; ansic: 57,789; sh: 275; python: 242; makefile: 95
file content (38 lines) | stat: -rwxr-xr-x 1,146 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash

STYLE="{
	\"BasedOnStyle\": \"llvm\",
	\"IndentWidth\": 8,
	\"TabWidth\": 8,
	\"ContinuationIndentWidth\": 8,
	\"UseTab\": \"ForIndentation\",
	\"BreakBeforeBraces\": \"Attach\",
	\"AlwaysBreakTemplateDeclarations\": \"true\",
	\"ColumnLimit\": 100,
	\"PointerBindsToType\": \"true\",
	\"AccessModifierOffset\": -8,
	\"ConstructorInitializerIndentWidth\": 8,
}"

MODE=$1

function format_file() {
	if ! diff -u <(cat "$1") <(clang-format -style="$STYLE" $1) &> "/dev/null"; then
		if [ "$MODE" == "check" ]
		then
			exit 1
		fi
		echo formatting "$1"
		clang-format -style="$STYLE" -i "$1"
	fi
}

for FILE in $(find include -iname "*.[hc]pp"); do format_file "$FILE"; done
for FILE in $(find lib     -iname "*.[hc]pp"); do format_file "$FILE"; done
for FILE in $(find app     -iname "*.[hc]pp"); do format_file "$FILE"; done
for FILE in $(find tools   -iname "*.[hc]pp"); do format_file "$FILE"; done
for FILE in $(find test    -iname "*.[hc]pp"); do format_file "$FILE"; done
for FILE in $(find c_include -iname "*.[hc]"); do format_file "$FILE"; done
for FILE in $(find c_lib    -iname "*.[hc]pp"); do format_file "$FILE"; done