aboutsummaryrefslogtreecommitdiff
path: root/tests/c-lint.sh
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2021-08-19 16:13:24 -0300
committerEuAndreh <eu@euandre.org>2021-08-19 16:13:24 -0300
commitd851cc6cb1f738066f6597d28c470f354c549ad0 (patch)
tree054f01f4b75fa793d93afebcebccfd5231b4e55a /tests/c-lint.sh
parenttests/build-sample.sh: Add, to be included in the "check" target (diff)
downloadgistatic-d851cc6cb1f738066f6597d28c470f354c549ad0.tar.gz
gistatic-d851cc6cb1f738066f6597d28c470f354c549ad0.tar.xz
tests/c-lint.sh: Add more strict linting rules
Diffstat (limited to 'tests/c-lint.sh')
-rwxr-xr-xtests/c-lint.sh22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/c-lint.sh b/tests/c-lint.sh
new file mode 100755
index 0000000..7c5516d
--- /dev/null
+++ b/tests/c-lint.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+if [ -n "$(grep -En '[a-z]+\(\) {' "$@")" ]; then
+ echo 'Functions with no argument without explicit "void" parameter:' >&2
+ grep -En '[a-z]+\(\) {' "$@"
+ exit 1
+fi
+
+awk '
+/^[a-zA-Z0-9_]+.+{$/ && !/^static / {
+ match($0, /[a-zA-Z0-9_]+\(/)
+ fn_name = substr($0, RSTART, RLENGTH - 1)
+ if (fn_name != "main") {
+ header = substr(FILENAME, 0, length(FILENAME) - 1) "h"
+ if (system("grep -qF \"" fn_name "(\" " header)) {
+ print "non-static function is not declared in a header:"
+ printf "%s:%s:%s\n", FILENAME, FNR, $0
+ exit 1
+ }
+ }
+}
+' "$@"