#!/bin/sh
#
# @author Markus Raab <elektra@markus-raab.org>
# @brief Reformats the whole source code
# @date 18.02.2016
# @tags reformat

SCRIPTS_DIR=$(dirname "$0")
. "${SCRIPTS_DIR}/include-common"

CLANG_FORMAT=$(which clang-format-5.0 2> /dev/null)

if [ -z "${CLANG_FORMAT}" ]; then
	CLANG_FORMAT=$(which clang-format)
fi

if [ -z "${CLANG_FORMAT}" ]; then
	echo "Please install clang-format 5, 6, or 7"
	exit 0
fi

cd "$SOURCE"

$($CLANG_FORMAT -style=file -i `find . -name '*.[ch]' -or -name '*.[ch]pp' -or -name '*.[ch].in' | egrep -v "^./src/tools/gen"`)
