util/codestyle.sh: Allow using the directive "codestyle:disable" in source files that shouldn't be automatically formatted

This commit is contained in:
Perttu Ahola 2014-10-09 15:20:07 +03:00
parent c3905412e7
commit 579d103467
3 changed files with 32 additions and 0 deletions

View File

@ -634,3 +634,5 @@ void Noise::transformNoiseMap() {
} }
} // namespace interface } // namespace interface
// codestyle:disable
// vim: set noet ts=4 sw=4:

View File

@ -178,3 +178,5 @@ namespace interface
(float)z / np->spread.Z, s + np->seed, np->octaves, np->persist)); (float)z / np->spread.Z, s + np->seed, np->octaves, np->persist));
} }
} }
// codestyle:disable
// vim: set noet ts=4 sw=4:

View File

@ -2,6 +2,19 @@
set -euv set -euv
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
error() {
local parent_lineno="$1"
local message="$2"
local code="${3:-1}"
if [[ -n "$message" ]] ; then
echo "Error on or near line ${parent_lineno}: ${message}; exiting with status ${code}"
else
echo "Error on or near line ${parent_lineno}; exiting with status ${code}"
fi
exit "${code}"
}
trap 'error ${LINENO} "" ""' ERR
header_files="$script_dir"/../src/*/*.h header_files="$script_dir"/../src/*/*.h
cpp_files="$script_dir"/../src/*/*.cpp cpp_files="$script_dir"/../src/*/*.cpp
@ -20,6 +33,21 @@ lua_files+=" "$(find "$script_dir"/../games -name '*.lua')
cmake_files="$script_dir"/../CMakeLists.txt cmake_files="$script_dir"/../CMakeLists.txt
# Allow files to disable this script by the special directive
# 'codestyle:disable'
function filter_files() {
local files=$@
for f in $files; do
if ! grep -lq 'codestyle:disable' "$f"; then
echo "$f"
fi
done
}
header_files=$(filter_files $header_files)
cpp_files=$(filter_files $cpp_files)
lua_files=$(filter_files $lua_files)
cmake_files=$(filter_files $cmake_files)
echo "header_files: $header_files" echo "header_files: $header_files"
echo "cpp_files: $cpp_files" echo "cpp_files: $cpp_files"
echo "lua_files: $lua_files" echo "lua_files: $lua_files"