summaryrefslogtreecommitdiff
path: root/build-aux/lint-h
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-01-27 23:07:51 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-01-27 23:07:51 -0700
commit1e2b67047da4ad0f567ef5956f813b2d33b3cfa6 (patch)
tree5f186c02fd3649894f2a5c28c2db6efa3abf9df6 /build-aux/lint-h
parentf7b7c04e2ebb24ccae89b77ce76f0b405eb213d1 (diff)
parent3199e6a45fd5e8bd9ec44616d5dcfb856ba6a888 (diff)
Merge branch 'lukeshu/lint'
Diffstat (limited to 'build-aux/lint-h')
-rwxr-xr-xbuild-aux/lint-h27
1 files changed, 27 insertions, 0 deletions
diff --git a/build-aux/lint-h b/build-aux/lint-h
new file mode 100755
index 0000000..26ac13d
--- /dev/null
+++ b/build-aux/lint-h
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+# build-aux/lint-h - Lint checks for C header files
+#
+# Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+RED=$(tput setaf 1)
+RESET=$(tput sgr0)
+
+err() {
+ printf "${RED}%s${RESET}: %s\n" "$1" "$2" >&2
+ r=1
+}
+
+r=0
+for filename in "$@"; do
+ dscname=$(./build-aux/get-dscname "$filename")
+ guard=${dscname//'/'/'_'}
+ guard=${guard//'.'/'_'}
+ guard="_${guard^^}_"
+ if ! { grep -Fxq "#ifndef ${guard}" "$filename" &&
+ grep -Fxq "#define ${guard}" "$filename" &&
+ grep -Fxq "#endif /* ${guard} */" "$filename"; }; then
+ err "$filename" "does not have ${guard} guard"
+ fi
+done
+exit $r