]> git.ipfire.org Git - thirdparty/pdns.git/blame - build-scripts/format-code
Merge pull request #8582 from omoerbeek/rec-reformat
[thirdparty/pdns.git] / build-scripts / format-code
CommitLineData
ba5ba96c
OM
1#!/bin/sh
2
3#
4# Reformat code, but do not touch if no changes.
ba5ba96c
OM
5#
6
4a4e056a 7if [ "$0" != "./build-scripts/format-code" -a "$0" != "build-scripts/format-code" ]; then
ba5ba96c
OM
8 echo "Please run me from the root checkout dir"
9 exit 1
10fi
11
4a4e056a
OM
12if [ $# = 0 ]; then
13 echo usage: $0 file...
14 echo
15 echo format C++ files, does not touch non-regular files
16 exit 0
17fi
ba5ba96c
OM
18if [ ! -e .clang-format ]; then
19 echo "No .clang-format file found in .";
20 exit 1
21fi
22
23for file in "${@}"; do
4a4e056a
OM
24 if [ -h "$file" -o ! -f "$file" ]; then
25 echo "$file: skipped, not a regular file or unreadable"
26 continue
27 fi
2a8fe6ca 28 tmp=$(mktemp "$file.XXXXXXXX")
4a4e056a
OM
29 if ! clang-format -style=file "$file" > "$tmp"; then
30 rm "$tmp"
ba5ba96c 31 else
4a4e056a
OM
32 if ! cmp -s "$file" "$tmp"; then
33 echo "$file: reformatted"
34 mv "$tmp" "$file"
ba5ba96c 35 else
4a4e056a
OM
36 echo "$file: already formatted to perfection"
37 rm "$tmp"
ba5ba96c
OM
38 fi
39 fi
40done
41