From e9f08f6a1591a2e35a17a430f5aa5cae7f62f816 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Tue, 3 Jun 2008 13:51:54 +0000 Subject: Add coding style checking tools 20080603135154-93b9a-b631438708091d087e3ba0eb58f04399819d1aba.gz --- tools/check-c-style.sh | 36 ++++++++++++++++++++++++++++++++++++ tools/check-coding-style.mk | 17 +++++++++++++++++ tools/check-misc.sh | 13 +++++++++++++ tools/check-whitespace.sh | 17 +++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 tools/check-c-style.sh create mode 100644 tools/check-coding-style.mk create mode 100644 tools/check-misc.sh create mode 100644 tools/check-whitespace.sh (limited to 'tools') diff --git a/tools/check-c-style.sh b/tools/check-c-style.sh new file mode 100644 index 00000000..357fdb36 --- /dev/null +++ b/tools/check-c-style.sh @@ -0,0 +1,36 @@ +#!/bin/sh +fail=0 + +( . "${tools_dir}"/check-misc.sh ) || fail=$? + +if grep -n '^ *GError *\*[[:alpha:]_][[:alnum:]_]* *;' "$@" +then + echo "^^^ The above files contain uninitialized GError*s - they should be" + echo " initialized to NULL" + fail=1 +fi + +# The first regex finds function calls like foo() (as opposed to foo ()). +# It attempts to ignore string constants (may cause false negatives). +# The second and third ignore block comments (gtkdoc uses foo() as markup). +# The fourth ignores cpp so you can +# #define foo(bar) (_real_foo (__FUNC__, bar)) (cpp insists on foo() style). +if grep -n '^[^"]*[[:lower:]](' "$@" \ + | grep -v '^[-[:alnum:]_./]*:[[:digit:]]*: *\*' \ + | grep -v '^[-[:alnum:]_./]*:[[:digit:]]*: */\*' \ + | grep -v '^[-[:alnum:]_./]*:[[:digit:]]*: *#' +then + echo "^^^ Our coding style is to use function calls like foo (), not foo()" + fail=1 +fi + +if test -n "$CHECK_FOR_LONG_LINES" +then + if egrep -n '.{80,}' "$@" + then + echo "^^^ The above files contain long lines" + fail=1 + fi +fi + +exit $fail diff --git a/tools/check-coding-style.mk b/tools/check-coding-style.mk new file mode 100644 index 00000000..3fc92fc8 --- /dev/null +++ b/tools/check-coding-style.mk @@ -0,0 +1,17 @@ +check-coding-style: + @fail=0; \ + if test -n "$(check_misc_sources)"; then \ + tools_dir=$(top_srcdir)/tools \ + sh $(top_srcdir)/tools/check-misc.sh \ + $(check_misc_sources) || fail=1; \ + fi; \ + if test -n "$(check_c_sources)"; then \ + tools_dir=$(top_srcdir)/tools \ + sh $(top_srcdir)/tools/check-c-style.sh \ + $(check_c_sources) || fail=1; \ + fi;\ + if test yes = "$(ENABLE_CODING_STYLE_CHECKS)"; then \ + exit "$$fail";\ + else \ + exit 0;\ + fi diff --git a/tools/check-misc.sh b/tools/check-misc.sh new file mode 100644 index 00000000..89e8e871 --- /dev/null +++ b/tools/check-misc.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +fail=0 + +( . "${tools_dir}"/check-whitespace.sh ) || fail=$? + +if egrep '(Free\s*Software\s*Foundation.*02139|02111-1307)' "$@" +then + echo "^^^ The above files contain the FSF's old address in GPL headers" + fail=1 +fi + +exit $fail diff --git a/tools/check-whitespace.sh b/tools/check-whitespace.sh new file mode 100644 index 00000000..53483312 --- /dev/null +++ b/tools/check-whitespace.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +fail=0 + +if grep -n ' $' "$@" +then + echo "^^^ The above files contain unwanted trailing spaces" + fail=1 +fi + +if grep -n ' ' "$@" +then + echo "^^^ The above files contain tabs" + fail=1 +fi + +exit $fail -- cgit v1.2.3