libav: switch from CODEC_ID to AV_CODEC_ID
[mplayer.git] / TOOLS / checktree.sh
blob4af9ad103efbe8e2595da93c54cca97090a39dfd
1 #!/bin/bash
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.
26 # $Id$
28 # -----------------------------------------------------------------------------
30 # All yes/no flags. Spaces around flagnames are important!
32 testflags=" spaces extensions crlf tabs trailws rcsid oll charset stupid gnu \
33 res depr "
34 allflags="$testflags showcont color head svn "
36 # -----------------------------------------------------------------------------
38 # Avoid locale problems
40 export LC_ALL=C
42 # -----------------------------------------------------------------------------
44 # Helper functions
46 set_all_tests() {
47 for i in $testflags ; do
48 eval _$i=$1
49 done
52 printoption() {
53 test -n "$3" && def=$3 || eval def=\$_$1
54 echo " -(no)$1 $2 [default: $def]"
57 printhead() {
58 test "$_head" = "yes" && echo -e "$COLB$1$COLE"
61 all_filenames() {
62 test "$_files" != "" && echo "$_files" && return
64 if [ "$_svn" = "no" ]; then
65 find . -type f \
66 | grep -v "\.\#\|\~$\|\.depend\|\/\.svn\/\|config.mak\|^\./config\.h" \
67 | grep -v "^\./version\.h\|\.o$\|\.a$\|config.log\|^\./help_mp.h"
68 else
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;'
73 done
77 # -----------------------------------------------------------------------------
79 # Default settings
81 set_all_tests no
82 _spaces=yes
83 _extensions=yes
84 _crlf=yes
86 _showcont=no
87 _color=yes
88 _head=yes
89 _svn=yes
90 _files=
92 # Parse command line
94 for i in "$@"; do
95 case "$i" in
96 -help|--help|-h|-\?)
97 echo -e "\n$0 [options] [files]\n"
98 echo -e "options:\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"
111 echo
112 printoption "all " "enable all tests" "no"
113 echo " (-noall can be specified as -none)"
114 echo
115 printoption "showcont " "show offending content of file(s)"
116 echo
117 printoption "color " "colored output"
118 printoption "head " "print heading for each test"
119 printoption "svn " \
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"
123 exit
125 -all)
126 set_all_tests yes
128 -noall)
129 set_all_tests no
131 -none)
132 set_all_tests no
135 var=`echo X$i | sed 's/^X-//'`
136 val=yes
137 case "$var" in
138 no*)
139 var=`echo "$var" | cut -c 3-`
140 val=no
142 esac
143 case "$allflags" in
144 *\ $var\ *)
145 eval _$var=$val
148 echo "unknown option: $i" >&2
149 exit 0
151 esac
154 _files="$_files $i"
156 esac
157 done
159 # -----------------------------------------------------------------------------
161 # Set heading color
163 if [ "$_color" = "yes" ]; then
164 COLB="\e[36m"
165 COLE="\e[m"
166 else
167 COLB=""
168 COLE=""
171 # Test presence of svn info
173 if [ "$_svn" = "yes" -a ! -d .svn ] ; then
174 echo "No svn info available. Please use -nosvn." >&2
175 exit 1
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
183 *yes*)
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]$"`
188 esac
190 if [ "$_showcont" = "yes" ]; then
191 _diffopts="-u"
192 _grepopts="-n -I"
193 else
194 _diffopts="-q"
195 _grepopts="-l -I"
198 TAB=`echo " " | tr ' ' '\011'`
200 # -----------------------------------------------------------------------------
202 # DO CHECKS
204 # -----------------------------------------------------------------------------
206 if [ "$_spaces" = "yes" ]; then
207 printhead "checking for spaces in filenames ..."
208 find . | grep " "
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
274 case "$I" in
275 ./help/help_mp-*.h)
277 ./DOCS/*)
279 *.c|*.h)
280 iconv -c -f ascii -t ascii "$I" | diff $_diffopts "$I" -
282 esac
283 done
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" \
295 $chfilelist
296 done
298 for i in "" signed unsigned; do
299 printhead "--> usage of sizeof($i char)"
300 grep $_grepopts "sizeof[ $TAB]*([ $TAB]*$i[ $TAB]*char[ $TAB]*)" \
301 $chfilelist
302 done
304 for i in int8_t uint8_t; do
305 printhead "--> usage of sizeof($i)"
306 grep $_grepopts "sizeof[ $TAB]*([ $TAB]*$i[ $TAB]*)" $chfilelist
307 done
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_]" \
318 $chfilelist
320 printhead "--> usage of *1"
321 grep $_grepopts "[a-zA-Z0-9)]\+[ $TAB]*\*[ $TAB]*1[^.0-9ea-fA-F_]" \
322 $chfilelist
324 printhead "--> usage of +0"
325 grep $_grepopts "[a-zA-Z0-9)]\+[ $TAB]*+[ $TAB]*0[^.0-9xa-fA-F_]" \
326 $chfilelist
328 printhead "--> usage of -0"
329 grep $_grepopts "[a-zA-Z0-9)]\+[ $TAB]*-[ $TAB]*0[^.0-9xa-fA-F_]" \
330 $chfilelist
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
347 printhead "--> $i()"
348 grep $_grepopts "[^a-zA-Z0-9]$i[ $TAB]*(" $chfilelist
349 done