File: format.sh

package info (click to toggle)
zmap 4.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,628 kB
  • sloc: ansic: 15,033; python: 1,085; yacc: 125; sh: 120; lex: 28; makefile: 4
file content (24 lines) | stat: -rwxr-xr-x 661 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash
set -e
set -o pipefail

MAJOR_REV=$((clang-format --version | awk '{print $3}' | cut -d '.' -f 1) || echo 0)
if [ $MAJOR_REV -lt 5 ]; then
	echo "error: need at least clang-format version 5.x"
	exit 1
fi

FORMAT_CMD="clang-format -i -style=file"

# No files passed, format everything
if [ $# -eq 0 ]; then
	echo "formatting all C code in src/ and lib/"
	find ./src -type f -name '*.c' -exec $FORMAT_CMD {} \;
	find ./src -type f -name '*.h' -exec $FORMAT_CMD {} \;
	find ./lib -type f -name '*.c' -exec $FORMAT_CMD {} \;
	find ./lib -type f -name '*.h' -exec $FORMAT_CMD {} \;
	exit 0
fi

# File names passed, format only those files
$FORMAT_CMD $@