Blame telepathy-account-widgets/tools/check-c-style.sh

Packit 79f644
#!/bin/sh
Packit 79f644
fail=0
Packit 79f644
Packit 79f644
( . "${tools_dir}"/check-misc.sh ) || fail=$?
Packit 79f644
Packit 79f644
# The first regex finds function calls like foo() (as opposed to foo ()).
Packit 79f644
#   It attempts to ignore string constants (may cause false negatives).
Packit 79f644
# The second and third ignore block comments (gtkdoc uses foo() as markup).
Packit 79f644
# The fourth ignores cpp so you can
Packit 79f644
#   #define foo(bar) (_real_foo (__FUNC__, bar)) (cpp insists on foo() style).
Packit 79f644
if grep -n '^[^"]*[[:lower:]](' "$@" \
Packit 79f644
  | grep -v '^[-[:alnum:]_./]*:[[:digit:]]*: *\*' \
Packit 79f644
  | grep -v '^[-[:alnum:]_./]*:[[:digit:]]*: */\*' \
Packit 79f644
  | grep -v '^[-[:alnum:]_./]*:[[:digit:]]*: *#'
Packit 79f644
then
Packit 79f644
  echo "^^^ Our coding style is to use function calls like foo (), not foo()"
Packit 79f644
  fail=1
Packit 79f644
fi
Packit 79f644
Packit 79f644
if grep -En '[(][[:alnum:]_]+ ?\*[)][(]?[[:alpha:]_]' "$@"; then
Packit 79f644
  echo "^^^ Our coding style is to have a space between a cast and the "
Packit 79f644
  echo "    thing being cast"
Packit 79f644
  fail=1
Packit 79f644
fi
Packit 79f644
Packit 79f644
# this only spots casts
Packit 79f644
if grep -En '[(][[:alnum:]_]+\*+[)]' "$@"; then
Packit 79f644
  echo "^^^ Our coding style is to have a space before the * of pointer types"
Packit 79f644
  echo "    (regex 1)"
Packit 79f644
  fail=1
Packit 79f644
fi
Packit 79f644
# ... and this only spots variable declarations and function return types
Packit 79f644
if grep -En '^ *(static |const |)* *[[:alnum:]_]+\*+([[:alnum:]_]|;|$)' \
Packit 79f644
    "$@"; then
Packit 79f644
  echo "^^^ Our coding style is to have a space before the * of pointer types"
Packit 79f644
  echo "    (regex 2)"
Packit 79f644
  fail=1
Packit 79f644
fi
Packit 79f644
Packit 79f644
if grep -n 'g_hash_table_destroy' "$@"; then
Packit 79f644
  echo "^^^ Our coding style is to use g_hash_table_unref"
Packit 79f644
  fail=1
Packit 79f644
fi
Packit 79f644
Packit 79f644
for p in "" "ptr_" "byte_"; do
Packit 79f644
  if grep -En "g_${p}array_free \(([^ ,]+), TRUE\)" "$@"; then
Packit 79f644
    echo "^^^ Our coding style is to use g_${p}array_unref in the case "
Packit 79f644
    echo "    the underlying C array is not used"
Packit 79f644
    fail=1
Packit 79f644
  fi
Packit 79f644
done
Packit 79f644
Packit 79f644
if test -n "$CHECK_FOR_LONG_LINES"
Packit 79f644
then
Packit 79f644
  if egrep -n '.{80,}' "$@"
Packit 79f644
  then
Packit 79f644
    echo "^^^ The above files contain long lines"
Packit 79f644
    fail=1
Packit 79f644
  fi
Packit 79f644
fi
Packit 79f644
Packit 79f644
exit $fail