summaryrefslogtreecommitdiff
path: root/data/check-code-style
diff options
context:
space:
mode:
authorJan-Michael Brummer <jan.brummer@tabos.org>2023-05-02 10:53:36 +0200
committerGitHub <noreply@github.com>2023-05-02 10:53:36 +0200
commitd159c5f40ff7e82354e45116d9b66b1f596d9320 (patch)
tree34506d9ee6c699444a170c6bba8c925c45407d3e /data/check-code-style
parent8fec01ed4b95afc71bf7710bf5b736a5de03b343 (diff)
parent5272fb3d114f0d012871380bd429546c73f0226d (diff)
downloadlibproxy-git-d159c5f40ff7e82354e45116d9b66b1f596d9320.tar.gz
Merge pull request #201 from janbrummer/rewrite
Complete rewrite
Diffstat (limited to 'data/check-code-style')
-rwxr-xr-xdata/check-code-style60
1 files changed, 60 insertions, 0 deletions
diff --git a/data/check-code-style b/data/check-code-style
new file mode 100755
index 0000000..3b9ca19
--- /dev/null
+++ b/data/check-code-style
@@ -0,0 +1,60 @@
+#!/bin/bash
+
+SOURCE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
+
+UNCRUSTIFY=$(command -v uncrustify)
+if [ -z "$UNCRUSTIFY" ];
+then
+ echo "Uncrustify is not installed on your system."
+ exit 1
+fi
+
+LINEUP_PARAMETERS="$SOURCE_ROOT/data/lineup-parameters"
+if [ ! -x "$LINEUP_PARAMETERS" ];
+then
+ echo "lineup-parameters script is missing"
+ exit 1
+fi
+
+# create a filename to store our generated patch
+prefix="libproxy-ccs"
+suffix="$(date +%C%y-%m-%d_%Hh%Mm%Ss)"
+patch="/tmp/$prefix-$suffix.patch"
+
+# clean up old patches
+rm -f /tmp/$prefix*.patch
+
+pushd $SOURCE_ROOT
+for DIR in src
+do
+ # Aligning prototypes is not working yet, so avoid headers
+ for FILE in $(find "$DIR" -name "*.c" ! -path "*/contrib/*")
+ do
+ "$UNCRUSTIFY" -q -c "data/uncrustify.cfg" -f "$FILE" -o "$FILE.uncrustify"
+ "$LINEUP_PARAMETERS" "$FILE.uncrustify" > "$FILE.temp" && mv "$FILE.temp" "$FILE.uncrustify"
+ diff -urN "$FILE" "$FILE.uncrustify" | \
+ sed -e "1s|--- |--- a/|" -e "2s|+++ |+++ b/|" >> "$patch"
+ rm "$FILE.uncrustify"
+ done
+done
+popd
+
+if [ ! -s "$patch" ] ; then
+ printf "** Commit is valid. \\o/\n"
+ rm -f "$patch"
+ exit 0
+fi
+
+printf "** Commit does not comply to the correct style :(\n\n"
+
+if hash colordiff 2> /dev/null; then
+ colordiff < $patch
+else
+ cat "$patch"
+fi
+
+printf "\n"
+printf "You can apply these changed with: git apply $patch\n"
+printf "\n"
+
+exit 1