format.uncrustify 717 Bytes
Newer Older
Matthew Woehlke's avatar
Matthew Woehlke committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#!/bin/sh
# This formatter uses the `uncrustify` tool to perform formatting of files
# written in C, C++, and other C-like languages (CUDA, GLSL, etc.).
#
# It uses the `uncrustify` executable in `$PATH` and checks for the existence
# of the `.uncrustify.cfg` file as its configuration.

set -e

readonly path="$1"
shift

if ! [ -f "$path" ]; then
    echo >&2 'error: could not find file to format: '"$path"
    exit 4
fi

if ! type "uncrustify" > /dev/null; then
    echo >&2 'error: could not find the `uncrustify` binary'
    exit 3
fi

if ! [ -f ".uncrustify.cfg" ]; then
    echo >&2 'error: the `.uncrustify.cfg` file is missing'
    exit 2
fi

exec uncrustify -c .uncrustify.cfg --replace --no-backup "$path"