contrib/format.sh: Add script for formatting files using a remote clang-format.
[collectd.git] / contrib / format.sh
1 #!/bin/sh
2
3 # This script sends files to a web service using POST requests and reads back
4 # the correctly formatted source files. This allows to apply clang-format
5 # without having to install the tool locally.
6
7 if test $# -lt 1; then
8   echo "Usage $0 <file> [<file> ...]"
9   exit 1
10 fi
11
12 for i in "$@"; do
13   d="$(dirname "${i}")"
14   o="$(tempfile -d "${d}" -m 0644)"
15
16   curl --silent --data-binary "@-" https://clang-format.appspot.com/ <"${i}" >"${o}"
17   if test $? -eq 0; then
18     cat "${o}" >"${i}"
19   fi
20   rm -f "${o}"
21 done