]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
tools/cmake-format: Add option --check-indents to check indentations independently...
authorRalf Habacker <ralf.habacker@freenet.de>
Thu, 24 Jan 2019 07:56:19 +0000 (08:56 +0100)
committerRalf Habacker <ralf.habacker@freenet.de>
Thu, 24 Jan 2019 08:07:45 +0000 (09:07 +0100)
Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
tools/cmake-format

index 1e5f46fb0d4437cfef98b96abd5d44803183ed1e..9ccf1653b9b5c26a367d633f1b26df3a327e028b 100755 (executable)
@@ -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