From edb62c8475a47cb83ea8ee628f8280050f092e05 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 4 Dec 2007 10:25:17 +0000 Subject: darcs mv check-* tools/ ; adjust src/Makefile.am, tests/Makefile.am, tools/Makefile.am, Makefile.am accordingly 20071204102517-53eee-9ffd2adb59a5b4018c97c2ba8d85c6bd93812f97.gz --- tools/Makefile.am | 3 +++ tools/check-c-style.sh | 36 ++++++++++++++++++++++++++++++++++++ tools/check-coding-style.mk | 15 +++++++++++++++ tools/check-whitespace.sh | 17 +++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 tools/check-c-style.sh create mode 100644 tools/check-coding-style.mk create mode 100644 tools/check-whitespace.sh (limited to 'tools') diff --git a/tools/Makefile.am b/tools/Makefile.am index c27fe04a5..6be0b72c4 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,6 +1,9 @@ EXTRA_DIST = \ c-constants-generator.xsl \ c-interfaces-generator.xsl \ + check-coding-style.mk \ + check-c-style.sh \ + check-whitespace.sh \ doc-generator.xsl \ genginterface.py \ ls-interfaces.xsl \ diff --git a/tools/check-c-style.sh b/tools/check-c-style.sh new file mode 100644 index 000000000..793d34b82 --- /dev/null +++ b/tools/check-c-style.sh @@ -0,0 +1,36 @@ +#!/bin/sh +fail=0 + +/bin/sh "${top_srcdir}"/check-whitespace.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 000000000..b69c63839 --- /dev/null +++ b/tools/check-coding-style.mk @@ -0,0 +1,15 @@ +check-local:: + @fail=0; \ + if test -n "$(check_misc_sources)"; then \ + top_srcdir=$(top_srcdir) sh $(top_srcdir)/check-whitespace.sh \ + $(check_misc_sources) || fail=1; \ + fi; \ + if test -n "$(check_c_sources)"; then \ + top_srcdir=$(top_srcdir) sh $(top_srcdir)/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-whitespace.sh b/tools/check-whitespace.sh new file mode 100644 index 000000000..534833126 --- /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