Revert "log-window: escape the body of the message"
[empathy-mirror.git] / tools / check-c-style.sh
blob55834207aa816768ef16de3325facf88f7c57b89
1 #!/bin/sh
2 fail=0
4 ( . "${tools_dir}"/check-misc.sh ) || fail=$?
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
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
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
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
40 if grep -n 'g_hash_table_destroy' "$@"; then
41 echo "^^^ Our coding style is to use g_hash_table_unref"
42 fail=1
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
51 done
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
62 exit $fail