diff options
author | EuAndreh <eu@euandre.org> | 2021-09-01 11:03:49 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2021-09-01 11:07:11 -0300 |
commit | 7eef4f04d9fd1fc8ecc38392ce1adb1c44899adc (patch) | |
tree | 7366fac128a49fb2b128090ca6b69f147ebfe583 /tests/c-lint.sh | |
parent | tests/lib.sh: Update (diff) | |
download | remembering-7eef4f04d9fd1fc8ecc38392ce1adb1c44899adc.tar.gz remembering-7eef4f04d9fd1fc8ecc38392ce1adb1c44899adc.tar.xz |
Refactor C files, split logerr and tests-lib
Diffstat (limited to '')
-rwxr-xr-x[-rw-r--r--] | tests/c-lint.sh | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/c-lint.sh b/tests/c-lint.sh index e69de29..0fa0b01 100644..100755 --- a/tests/c-lint.sh +++ b/tests/c-lint.sh @@ -0,0 +1,65 @@ +#!/bin/sh +set -eu + +awk ' +BEGIN { + ret = 0 + msg = "function not on the start of the line:" +} + +/^[a-zA-Z0-9_]+ .+\(/ { + if (ret == 0) { + print msg + } + printf "%s:%s:%s\n", FILENAME, FNR, $0 + ret = 1 +} + +END { + exit ret +} +' "$@" + + +awk ' +BEGIN { + ret = 0 + static = 1 + msg = "non-static function is not declared in a header:" +} + +/^[a-zA-Z0-9_]+\(.*$/ && static == 0 { + split($0, line, /\(/) + fn_name = line[1] + if (fn_name != "main") { + header = substr(FILENAME, 0, length(FILENAME) - 2) ".h" + if (system("grep -q ^\"" fn_name "\" \"" header "\"")) { + if (ret == 0) { + print msg + } + printf "%s:%s:%s\n", FILENAME, FNR, $0 + ret = 1 + } + } +} + +/^static / { + static = 1 +} + +!/^static / { + static = 0 +} + +END { + exit ret +} +' "$@" + + +RE='[a-z]+\(\) {' +if grep -Eq "$RE" "$@"; then + echo 'Functions with no argument without explicit "void" parameter:' >&2 + grep -En "$RE" "$@" + exit 1 +fi |