diff options
author | Paul Moore <paul@paul-moore.com> | 2020-08-22 10:14:48 -0400 |
---|---|---|
committer | Paul Moore <paul@paul-moore.com> | 2020-09-02 10:39:47 -0400 |
commit | 00b858adc2866544d93af5d2d24086223e4363e8 (patch) | |
tree | aa508e01b3bf6f2830b78921dd29f39c5e9dea05 /tools | |
parent | f0686d9de911e7ffcdc7364566c1d146e44657c2 (diff) | |
download | libseccomp-00b858adc2866544d93af5d2d24086223e4363e8.tar.gz |
tools: integrate codespell into our syntax checker
Reviewed-by: Tom Hromatka <tom.hromatka@oracle.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/check-syntax | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/tools/check-syntax b/tools/check-syntax index 42790d3..a8df9f9 100755 --- a/tools/check-syntax +++ b/tools/check-syntax @@ -28,6 +28,8 @@ CHK_C_LIST="include/seccomp.h.in \ tools/*.c tools/*.h" CHK_C_EXCLUDE="src/syscalls.perf.c" +CHK_SPELL_EXCLUDE_WORDS="" + #### # functions @@ -60,13 +62,23 @@ EOF } # -# Generate a properly formatted C source/header file +# Spellcheck source code # -# Arguments: -# 1 Source file +function tool_spell_check() { + local tfile + + tfile=$(mktemp -t check-syntax-XXXXXX) + cat - > $tfile + codespell -q 16 -d -w -L "$CHK_SPELL_EXCLUDE_WORDS" $tfile + cat $tfile + rm -f $tfile +} + +# +# Generate a properly formatted C source/header file # function tool_c_style() { - astyle --options=none --lineend=linux --mode=c \ + cat - | astyle --options=none --lineend=linux --mode=c \ --style=linux \ --indent=force-tab=8 \ --indent-preprocessor \ @@ -77,7 +89,17 @@ function tool_c_style() { --align-pointer=name \ --align-reference=name \ --max-code-length=80 \ - --break-after-logical < "$1" + --break-after-logical +} + +# +# Generate a properly formatted and spellchecked C source/header file +# +# Arguments: +# 1 Source file +# +function tool_c_ideal() { + cat "$1" | tool_spell_check | tool_c_style } # @@ -89,7 +111,7 @@ function tool_c_style() { function tool_c_style_check() { [[ -z "$1" || ! -r "$1" ]] && return - tool_c_style "$1" | diff -pu --label="$1.orig" "$1" --label="$1" - + tool_c_ideal "$1" | diff -pu --label="$1.orig" "$1" --label="$1" - } # @@ -102,7 +124,7 @@ function tool_c_style_fix() { [[ -z "$1" || ! -r "$1" ]] && return tmp="$(mktemp --tmpdir=$(dirname "$1"))" - tool_c_style "$1" > "$tmp" + tool_c_ideal "$1" > "$tmp" mv "$tmp" "$1" } @@ -132,6 +154,7 @@ function fix_c() { # main verify_deps astyle +verify_deps codespell opt_fix=0 |