3 # -----------------------------------------------------------------------------
5 # Check source-tree for anomalies
7 # Copyright (C) 2005-2007 by Ivo van Poorten
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 # Thanks to Melchior Franz of the FlightGear project for the original idea
24 # of a source-tree checker and Torinthiel for the feedback along the way.
28 # -----------------------------------------------------------------------------
30 # All yes/no flags. Spaces around flagnames are important!
32 testflags
=" spaces extensions crlf tabs trailws rcsid oll charset stupid gnu \
34 allflags
="$testflags showcont color head svn "
36 # -----------------------------------------------------------------------------
38 # Avoid locale problems
42 # -----------------------------------------------------------------------------
47 for i
in $testflags ; do
53 test -n "$3" && def
=$3 ||
eval def
=\
$_$1
54 echo " -(no)$1 $2 [default: $def]"
58 test "$_head" = "yes" && echo -e "$COLB$1$COLE"
62 test "$_files" != "" && echo "$_files" && return
64 if [ "$_svn" = "no" ]; then
66 |
grep -v "\.\#\|\~$\|\.depend\|\/\.svn\/\|config.mak\|^\./config\.h" \
67 |
grep -v "^\./version\.h\|\.o$\|\.a$\|config.log\|^\./help_mp.h"
69 for p
in . libavcodec libavutil libavformat libpostproc
; do
70 svn info
-R $p 2>/dev
/null |
sed -n \
71 '/Path:/bb; :a; d; b; :b; s/Path: /.\//; h; :c; n;
72 /Node Kind:/bd; bc; :d; /directory/ba; g; p;'
77 # -----------------------------------------------------------------------------
97 echo -e "\n$0 [options] [files]\n"
99 printoption
"spaces " "test for spaces in filenames"
100 printoption
"extensions" "test for uppercase extensions"
101 printoption
"crlf " "test for MSDOS line endings"
102 printoption
"tabs " "test for tab characters"
103 printoption
"trailws " "test for trailing whitespace"
104 printoption
"rcsid " "test for missing RCS Id's"
105 printoption
"oll " "test for overly long lines"
106 printoption
"charset " "test for wrong charset"
107 printoption
"stupid " "test for stupid code"
108 printoption
"gnu " "test for GNUisms"
109 printoption
"res " "test for reserved identifiers"
110 printoption
"depr " "test for deprecated function calls"
112 printoption
"all " "enable all tests" "no"
113 echo " (-noall can be specified as -none)"
115 printoption
"showcont " "show offending content of file(s)"
117 printoption
"color " "colored output"
118 printoption
"head " "print heading for each test"
120 "use svn info to determine which files to check"
121 echo -e "\nIf no files are specified, the whole tree is traversed."
122 echo -e "If there are, -(no)svn has no effect.\n"
135 var
=`echo X$i | sed 's/^X-//'`
139 var
=`echo "$var" | cut -c 3-`
148 echo "unknown option: $i" >&2
159 # -----------------------------------------------------------------------------
163 if [ "$_color" = "yes" ]; then
171 # Test presence of svn info
173 if [ "$_svn" = "yes" -a ! -d .svn
] ; then
174 echo "No svn info available. Please use -nosvn." >&2
178 # Generate filelist once so -svn isn't _that_ much slower than -nosvn anymore
180 filelist
=`all_filenames`
182 case "$_stupid$_res$_depr$_gnu" in
184 # generate 'shortlist' to avoid false positives in xpm files, docs, etc,
185 # when one only needs to check .c and .h files
186 chfilelist
=`echo $filelist | tr ' ' '\n' | grep "[\.][ch]$"`
190 if [ "$_showcont" = "yes" ]; then
198 TAB
=`echo " " | tr ' ' '\011'`
200 # -----------------------------------------------------------------------------
204 # -----------------------------------------------------------------------------
206 if [ "$_spaces" = "yes" ]; then
207 printhead
"checking for spaces in filenames ..."
211 # -----------------------------------------------------------------------------
213 if [ "$_extensions" = "yes" ]; then
214 printhead
"checking for uppercase extensions ..."
215 echo $filelist |
grep "\.[[:upper:]]\+$" |
grep -v "\.S$"
218 # -----------------------------------------------------------------------------
220 if [ "$_crlf" = "yes" ]; then
221 printhead
"checking for MSDOS line endings ..."
222 CR
=`echo " " | tr ' ' '\015'`
223 grep $_grepopts "$CR" $filelist
226 # -----------------------------------------------------------------------------
228 if [ "$_tabs" = "yes" ]; then
229 printhead
"checking for TAB characters ..."
230 grep $_grepopts "$TAB" $filelist
233 # -----------------------------------------------------------------------------
235 if [ "$_trailws" = "yes" ]; then
236 printhead
"checking for trailing whitespace ..."
237 grep $_grepopts "[[:space:]]\+$" $filelist
240 # -----------------------------------------------------------------------------
242 if [ "$_rcsid" = "yes" ]; then
243 printhead
"checking for missing RCS \$Id\$ or \$Revision\$ tags ..."
244 grep -L -I "\$\(Id\|Revision\)[[:print:]]\+\$" $filelist
247 # -----------------------------------------------------------------------------
249 if [ "$_oll" = "yes" ]; then
250 printhead
"checking for overly long lines (over 79 characters) ..."
251 grep $_grepopts "^[[:print:]]\{80,\}$" $filelist
254 # -----------------------------------------------------------------------------
256 if [ "$_gnu" = "yes" -a -n "$chfilelist" ]; then
257 printhead
"checking for GNUisms ..."
258 grep $_grepopts "case.*\.\.\..*:" $chfilelist
261 # -----------------------------------------------------------------------------
263 if [ "$_res" = "yes" -a -n "$chfilelist" ]; then
264 printhead
"checking for reserved identifiers ..."
265 grep $_grepopts "#[ $TAB]*define[ $TAB]\+_[[:upper:]].*" $chfilelist
266 grep $_grepopts "#[ $TAB]*define[ $TAB]\+__.*" $chfilelist
269 # -----------------------------------------------------------------------------
271 if [ "$_charset" = "yes" ]; then
272 printhead
"checking bad charsets ..."
273 for I
in $filelist ; do
280 iconv -c -f ascii
-t ascii
"$I" |
diff $_diffopts "$I" -
286 # -----------------------------------------------------------------------------
288 if [ "$_stupid" = "yes" -a -n "$chfilelist" ]; then
289 printhead
"checking for stupid code ..."
291 for i
in calloc malloc realloc memalign av_malloc av_mallocz faad_malloc \
292 lzo_malloc safe_malloc mpeg2_malloc _ogg_malloc
; do
293 printhead
"--> casting of void* $i()"
294 grep $_grepopts "([ $TAB]*[a-zA-Z_]\+[ $TAB]*\*.*)[ $TAB]*$i" \
298 for i
in "" signed unsigned
; do
299 printhead
"--> usage of sizeof($i char)"
300 grep $_grepopts "sizeof[ $TAB]*([ $TAB]*$i[ $TAB]*char[ $TAB]*)" \
304 for i
in int8_t uint8_t
; do
305 printhead
"--> usage of sizeof($i)"
306 grep $_grepopts "sizeof[ $TAB]*([ $TAB]*$i[ $TAB]*)" $chfilelist
309 printhead
"--> usage of &&1"
310 grep $_grepopts "&&[ $TAB]*1" $chfilelist
312 printhead
"--> usage of ||0"
313 grep $_grepopts "||[ $TAB]*0" $chfilelist
315 # added a-fA-F_ to eliminate some false positives
316 printhead
"--> usage of *0"
317 grep $_grepopts "[a-zA-Z0-9)]\+[ $TAB]*\*[ $TAB]*0[^.0-9xa-fA-F_]" \
320 printhead
"--> usage of *1"
321 grep $_grepopts "[a-zA-Z0-9)]\+[ $TAB]*\*[ $TAB]*1[^.0-9ea-fA-F_]" \
324 printhead
"--> usage of +0"
325 grep $_grepopts "[a-zA-Z0-9)]\+[ $TAB]*+[ $TAB]*0[^.0-9xa-fA-F_]" \
328 printhead
"--> usage of -0"
329 grep $_grepopts "[a-zA-Z0-9)]\+[ $TAB]*-[ $TAB]*0[^.0-9xa-fA-F_]" \
333 # -----------------------------------------------------------------------------
335 if [ "$_depr" = "yes" -a -n "$chfilelist" ]; then
336 printhead
"checking for deprecated and obsolete function calls ..."
338 for i
in bcmp bcopy bzero getcwd getipnodebyname inet_ntoa inet_addr \
339 atoq ecvt fcvt ecvt_r fcvt_r qecvt_r qfcvt_r finite ftime gcvt herror \
340 hstrerror getpass getpw getutent getutid getutline pututline setutent \
341 endutent utmpname gsignal ssignal gsignal_r ssignal_r infnan memalign \
342 valloc re_comp re_exec drem dremf dreml rexec svc_getreq sigset \
343 sighold sigrelse sigignore sigvec sigmask sigblock sigsetmask \
344 siggetmask ualarm
ulimit usleep statfs fstatfs ustat get_kernel_syms \
345 query_module sbrk tempnam tmpnam mktemp mkstemp
348 grep $_grepopts "[^a-zA-Z0-9]$i[ $TAB]*(" $chfilelist