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