123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #!/bin/bash
- folderArray=( "daemon" "cli" "gui" )
- # Variable that will hold the name of the clang-format command
- FMT=""
- # Some distros just call it clang-format. Others (e.g. Ubuntu) are insistent
- # that the version number be part of the command. We prefer clang-format if
- # that's present, otherwise we work backwards from highest version to lowest
- # version.
- for clangfmt in clang-format{,-{4,3}.{9,8,7,6,5,4,3,2,1,0}}; do
- if which "$clangfmt" &>/dev/null; then
- FMT="$clangfmt"
- break
- fi
- done
- # Check if we found a working clang-format
- if [ -z "$FMT" ]; then
- echo "failed to find clang-format"
- exit 1
- fi
- function format() {
- for f in $(find $@ -type d -path "$@/build" -prune -o -type f -name '*.h' -or -name '*.hpp' -or -name '*.c' -or -name '*.cpp'); do
- if [ ! -d "${f}" ]; then
- echo "format ${f}";
- ${FMT} -i ${f};
- fi
- done
- echo "~~~ $@ Done ~~~";
- }
- # Check all of the arguments first to make sure they're all directories
- for dir in ${folderArray[@]}; do
- if [ ! -d "${dir}" ]; then
- echo "${dir} is not a directory";
- else
- format ${dir};
- fi
- done
|