summaryrefslogtreecommitdiffstats
path: root/tools/style.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/style.sh')
-rwxr-xr-xtools/style.sh43
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/style.sh b/tools/style.sh
new file mode 100755
index 0000000..08e40b1
--- /dev/null
+++ b/tools/style.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+# Read-only style check: no tabs, no trailing whitespace, nothing past 80
+# columns, and every .S file must declare a non-executable stack.
+
+set -eu
+
+here=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
+status=0
+
+for file in "$here"/src/*.S "$here"/src/*.inc "$here"/include/*.h \
+ "$here"/tests/*.c "$here"/examples/*.c; do
+ [ -e "$file" ] || continue
+ name=${file#"$here"/}
+ if grep -n ' ' "$file" >/dev/null 2>&1; then
+ echo "$name: contains a tab" >&2
+ grep -n ' ' "$file" | head -5 >&2
+ status=1
+ fi
+ if grep -n '[ ]$' "$file" >/dev/null 2>&1; then
+ echo "$name: trailing whitespace" >&2
+ grep -n '[ ]$' "$file" | head -5 >&2
+ status=1
+ fi
+ if awk 'length > 80 { print FILENAME ":" FNR ": line over 80 columns"; f=1 }
+ END { exit f ? 1 : 0 }' "$file" >&2; then
+ :
+ else
+ status=1
+ fi
+done
+
+for file in "$here"/src/*.S; do
+ name=${file#"$here"/}
+ if ! grep -q 'note.GNU-stack' "$file"; then
+ echo "$name: missing .note.GNU-stack" >&2
+ status=1
+ fi
+done
+
+if [ "$status" -eq 0 ]; then
+ echo "style: ok"
+fi
+exit "$status"