Use help:empathy to open the help
[empathy-mirror.git] / tools / check-c-style.sh
blob4330b1479f6154ef4752787ea86e7f3a5129f16f
1 #!/bin/sh
2 fail=0
4 ( . "${tools_dir}"/check-misc.sh ) || fail=$?
6 if grep -n '^ *GError *\*[[:alpha:]_][[:alnum:]_]* *;' "$@"
7 then
8 echo "^^^ The above files contain uninitialized GError*s - they should be"
9 echo " initialized to NULL"
10 fail=1
13 # The first regex finds function calls like foo() (as opposed to foo ()).
14 # It attempts to ignore string constants (may cause false negatives).
15 # The second and third ignore block comments (gtkdoc uses foo() as markup).
16 # The fourth ignores cpp so you can
17 # #define foo(bar) (_real_foo (__FUNC__, bar)) (cpp insists on foo() style).
18 if grep -n '^[^"]*[[:lower:]](' "$@" \
19 | grep -v '^[-[:alnum:]_./]*:[[:digit:]]*: *\*' \
20 | grep -v '^[-[:alnum:]_./]*:[[:digit:]]*: */\*' \
21 | grep -v '^[-[:alnum:]_./]*:[[:digit:]]*: *#'
22 then
23 echo "^^^ Our coding style is to use function calls like foo (), not foo()"
24 fail=1
27 if grep -En '[(][[:alnum:]_]+ ?\*[)][(]?[[:alpha:]_]' "$@"; then
28 echo "^^^ Our coding style is to have a space between a cast and the "
29 echo " thing being cast"
30 fail=1
33 # this only spots casts
34 if grep -En '[(][[:alnum:]_]+\*+[)]' "$@"; then
35 echo "^^^ Our coding style is to have a space before the * of pointer types"
36 echo " (regex 1)"
37 fail=1
39 # ... and this only spots variable declarations and function return types
40 if grep -En '^ *(static |const |)* *[[:alnum:]_]+\*+([[:alnum:]_]|;|$)' \
41 "$@"; then
42 echo "^^^ Our coding style is to have a space before the * of pointer types"
43 echo " (regex 2)"
44 fail=1
47 if grep -n 'g_hash_table_destroy' "$@"; then
48 echo "^^^ Our coding style is to use g_hash_table_unref"
49 fail=1
52 for p in "" "ptr_" "byte_"; do
53 if grep -En "g_${p}array_free \(([^ ,]+), TRUE\)" "$@"; then
54 echo "^^^ Our coding style is to use g_${p}array_unref in the case "
55 echo " the underlying C array is not used"
56 fail=1
58 done
60 if test -n "$CHECK_FOR_LONG_LINES"
61 then
62 if egrep -n '.{80,}' "$@"
63 then
64 echo "^^^ The above files contain long lines"
65 fail=1
69 exit $fail