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