1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
#!/bin/sh
#
# Copyright (C) 2014 Masatake YAMATO
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
CTAGS=./ctags
line()
{
local i
for i in $(seq 72); do
echo -n -e -
done
echo
}
header()
{
echo
echo "$1"
line
}
check_include_general_h_first()
{
local f
local l
local i=0
header "Check whether general.h is included first: $1"
for f in $(find $1 -name '*.c'); do
if grep -a -q -e '^#[[:space:]]*include' $f; then
l=$()
if ! ( grep -a -e '^#[[:space:]]*include' $f | head -1 | grep -q "general.h" ); then
i=$(expr $i + 1)
echo "$f: general.h should be included FIRST" 2>&1
fi
fi
done
return $i
}
check_name_cpp_macro()
{
local dir=$1
local r=0
local n
header "Check whether '_' is not used as ctags own macro name"
for f in $(find $dir -name '*.[ch]'); do
if ${CTAGS} --language-force=C -x --_xformat='%F:%N' --kinds-C=d -o - $f | grep -q '.*:_.*H'; then
for n in $(${CTAGS} --language-force=C -x --_xformat='%N' --kinds-C=d -o - $f | grep '^_.*H'); do
echo "#" $n
echo sed -i \""s|$n|CTAGS_$(echo $dir | tr a-z A-Z)_${n#_}|g\"" $f
done
r=1
fi
done
return $r
}
check_vStringCatS_usage()
{
local i=0
header "Check wrong vStringCatS usage(use vStringPut instead): $1"
for f in $(find $1 -name '*.c'); do
if grep -H -a -e 'vStringCatS[[:space:]]*(.*,[[:space:]]*"."[[:space:]]*)' $f; then
i=$(expr $i + 1)
elif grep -H -a -e 'vStringCatS[[:space:]]*(.*,[[:space:]]*"\\."[[:space:]]*)' $f; then
i=$(expr $i + 1)
fi
done
return $i
}
main()
{
local i=0
if ! [ -d ./main ]; then
echo "cannot find ./main"
return 2
fi
if ! [ -d ./parsers ]; then
echo "cannot find ./parsers"
return 2
fi
if ! check_include_general_h_first main; then
i=$(expr $i + 1)
fi
if ! check_include_general_h_first parsers; then
i=$(expr $i + 1)
fi
if ! check_name_cpp_macro main; then
i=$(expr $i + 1)
fi
if ! check_name_cpp_macro parsers; then
i=$(expr $i + 1)
fi
if ! check_vStringCatS_usage main; then
i=$(expr $i + 1)
fi
if ! check_vStringCatS_usage parsers; then
i=$(expr $i + 1)
fi
return 0
}
main "$@"
exit $?
|