diff options
author | Ralf Habacker <ralf.habacker@freenet.de> | 2019-01-24 08:56:19 +0100 |
---|---|---|
committer | Ralf Habacker <ralf.habacker@freenet.de> | 2019-01-24 09:07:45 +0100 |
commit | f4032b05ed9bd69c26e17a705b49af6da5e003e3 (patch) | |
tree | 8e974cdb25b29763a5a3d0e62dfff9ad1a7873fd /tools/cmake-format | |
parent | 904fa97a1b83217a57bf230f233ccd30d0e44f5b (diff) | |
download | dbus-f4032b05ed9bd69c26e17a705b49af6da5e003e3.tar.gz |
tools/cmake-format: Add option --check-indents to check indentations independently from other options
Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
Diffstat (limited to 'tools/cmake-format')
-rwxr-xr-x | tools/cmake-format | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/tools/cmake-format b/tools/cmake-format index 1e5f46fb..9ccf1653 100755 --- a/tools/cmake-format +++ b/tools/cmake-format @@ -22,6 +22,7 @@ if test -z "$1"; then echo " --keyword-spaces remove spaces between keyword and opening bracket" echo " --tabs replace tabs by 4 spaces" echo " --trailing-spaces remove trailing spaces" + echo " --check-indents check indents" exit 1 fi @@ -99,11 +100,27 @@ root=$(realpath $s/..) #echo $exp #echo $root -echo "locations with unusual indention level changes, please inspect" +if test "$1" = "--check-indents"; then + echo "locations with unusual indention level changes, please inspect" +fi + +# script for checking indents +awk='BEGIN { debug=0; indent=0 } +$0 ~ /^ {0}/ && $0 !~ /^$/{ indent=0; } +$0 ~ /^ {4}/ { indent=1; } +$0 ~ /^ {8}/ { indent=2; } +$0 ~ /^ {12}/ { indent=3; } +debug == 1 { print FILENAME "[" NR "]:" indent " " oldindent ": " $0; } +{ if (indent - oldindent > 1) print FILENAME ":" NR ":" $0; } +{ oldindent = indent;} +' + # apply to cmake related files for i in $(find $root -name 'CMakeLists.txt' -o -name '*.cmake' | grep -v README.cmake | grep -v config.h.cmake | grep -v bat.cmake | grep -v '/Find'); do # apply style - sed -i "$exp" $i - # show unusual indention changes - gawk 'BEGIN { indent=0 } $0 ~ /^ {0}/ && $0 !~ /^$/{ indent=0; } $0 ~ /^ {4}/ { indent=1; } $0 ~ /^ {8}/ { indent=2; } $0 ~ /^ {12}/ { indent=3; } { if (indent - oldindent > 1) print FILENAME ":" NR ":" $0; oldindent=indent;}' $i + if ! test "$1" = "--check-indents"; then + sed -i "$exp" $i + else + gawk "$awk" $i + fi done |