Changed code that used pts=0 in demux packets to indicate "not known".
[mplayer.git] / TOOLS / checktree.sh
blob106a0b987d3b7ef1c60148109e9e211c200c09ba
1 #!/bin/sh
3 # -----------------------------------------------------------------------------
5 # Check source-tree for anomalies
7 # (C)opyright 2005 by Ivo van Poorten
8 # Licensed under GNU General Public License version 2
10 # Thanks to Melchior Franz of the FlightGear project for the original idea
11 # of a source-tree checker and Torinthiel for the feedback along the way.
13 # $Id$
15 # -----------------------------------------------------------------------------
17 # Default settings
19 _spaces=yes
20 _extensions=yes
21 _crlf=yes
22 _trailws=no
23 _rcsid=no
24 _oll=no
25 _charset=no
26 _stupid=no
27 _showcont=no
29 _color=yes
30 _head=yes
31 _svn=yes
32 _files=
34 # -----------------------------------------------------------------------------
36 # Avoid locale problems
38 export LC_ALL=C
40 # -----------------------------------------------------------------------------
42 # Helper functions
44 enable_all_tests() {
45 _spaces=yes
46 _extensions=yes
47 _crlf=yes
48 _trailws=yes
49 _rcsid=yes
50 _oll=yes
51 _charset=yes
52 _stupid=yes
55 disable_all_tests() {
56 _spaces=no
57 _extensions=no
58 _crlf=no
59 _trailws=no
60 _rcsid=no
61 _oll=no
62 _charset=no
63 _stupid=no
66 printoption() {
67 echo " -(no)$1 $2 [default: $3]"
70 printhead() {
71 test "$_head" = "yes" && echo -e "$COLB$1$COLE"
74 all_filenames() {
75 test "$_files" != "" && echo "$_files" && return
77 if [ "$_svn" = "no" ]; then
78 find . -type f \
79 | grep -v "\.\#\|\~$\|\.depend\|\/\.svn\/\|config.mak\|^\./config\.h" \
80 | grep -v "^\./version\.h\|\.o$\|\.a$\|configure.log\|^\./help_mp.h"
81 else
82 list_svn .
86 list_svn() {
87 tmpfiles=`sed '/name/ba; /kind/ba; d; b;
88 :a; s/^ *....=\"\(.*\)\".*$/\1/;' $1/.svn/entries | \
89 sed '/$/N; s/\n/ /; / dir$/d; s/ file$//;'`
90 tmpdirs=`sed ' /name/ba; /kind/ba; d; b;
91 :a; s/^ *....=\"\(.*\)\".*$/\1/;' $1/.svn/entries | \
92 sed ' /$/N; s/\n/ /; / file$/d; /^ dir$/d; s/ dir$//;'`
94 for i in $tmpfiles; do
95 echo $1/$i
96 done
97 for j in $tmpdirs; do
98 list_svn $1/$j
99 done
102 # -----------------------------------------------------------------------------
104 # Parse command line
106 for i in "$@"; do
107 case "$i" in
108 -help)
109 echo -e "\n$0 [options] [files]\n"
110 echo -e "options:\n"
111 printoption "spaces " "test for spaces in filenames" "$_spaces"
112 printoption "extensions" "test for uppercase extensions" "$_extensions"
113 printoption "crlf " "test for MSDOS line endings" "$_crlf"
114 printoption "trailws " "test for trailing whitespace" "$_trailws"
115 printoption "rcsid " "test for missing RCS Id's" "$_rcsid"
116 printoption "oll " "test for overly long lines" "$_oll"
117 printoption "charset " "test for wrong charset" "$_charset"
118 printoption "stupid " "test for stupid code" "$_stupid"
119 echo
120 printoption "all " "enable all tests" "no"
121 echo
122 printoption "showcont " "show offending content of file(s)" \
123 "$_showcont"
124 echo
125 printoption "color " "colored output" "$_color"
126 printoption "head " "print heading for each test" "$_head"
127 printoption "svn " "use .svn/ to determine which files to " \
128 "check" "$_svn"
129 echo -e "\nIf no files are specified, the whole tree is traversed."
130 echo -e "If there are, -(no)svn has no effect.\n"
131 exit
133 -stupid)
134 _stupid=yes
136 -nostupid)
137 _stupid=no
139 -charset)
140 _charset=yes
142 -nocharset)
143 _charset=no
145 -oll)
146 _oll=yes
148 -nooll)
149 _oll=no
151 -svn)
152 _svn=yes
154 -nosvn)
155 _svn=no
157 -head)
158 _head=yes
160 -nohead)
161 _head=no
163 -color)
164 _color=yes
166 -nocolor)
167 _color=no
169 -spaces)
170 _spaces=yes
172 -nospaces)
173 _spaces=no
175 -extensions)
176 _extensions=yes
178 -noextensions)
179 _extensions=no
181 -crlf)
182 _crlf=yes
184 -nocrlf)
185 _crlf=no
187 -trailws)
188 _trailws=yes
190 -notrailws)
191 _trailws=no
193 -rcsid)
194 _rcsid=yes
196 -norcsid)
197 _rcsid=no
199 -all)
200 enable_all_tests
202 -noall)
203 disable_all_tests
205 -none)
206 disable_all_tests
208 -showcont)
209 _showcont=yes
211 -noshowcont)
212 _showcont=no
215 echo "unknown option: $i" >&2
216 exit 0
219 _files="$_files $i"
221 esac
222 done
224 # -----------------------------------------------------------------------------
226 # Set heading color
228 if [ "$_color" = "yes" ]; then
229 COLB="\e[36m"
230 COLE="\e[m"
231 else
232 COLB=""
233 COLE=""
236 # Generate filelist once so -svn isn't _that_ much slower than -nosvn anymore
238 filelist=`all_filenames`
240 if [ "$_showcont" = "yes" ]; then
241 _diffopts="-u"
242 _grepopts="-n -I"
243 else
244 _diffopts="-q"
245 _grepopts="-l -I"
248 # -----------------------------------------------------------------------------
250 # DO CHECKS
252 # -----------------------------------------------------------------------------
254 if [ "$_spaces" = "yes" ]; then
255 printhead "checking for spaces in filenames ..."
256 find . | grep " "
259 # -----------------------------------------------------------------------------
261 if [ "$_extensions" = "yes" ]; then
262 printhead "checking for uppercase extensions ..."
263 echo $filelist | grep "\.[[:upper:]]\+$" | grep -v "\.S$"
266 # -----------------------------------------------------------------------------
268 if [ "$_crlf" = "yes" ]; then
269 printhead "checking for MSDOS line endings ..."
270 CR=`echo " " | tr ' ' '\015'`
271 grep $_grepopts "$CR" $filelist
274 # -----------------------------------------------------------------------------
276 if [ "$_trailws" = "yes" ]; then
277 printhead "checking for trailing whitespace ..."
278 grep $_grepopts "[[:space:]]\+$" $filelist
281 # -----------------------------------------------------------------------------
283 if [ "$_rcsid" = "yes" ]; then
284 printhead "checking for missing RCS \$Id\$ or \$Revision\$ tags ..."
285 grep -L -I "\$\(Id\|Revision\)[[:print:]]\+\$" $filelist
288 # -----------------------------------------------------------------------------
290 if [ "$_oll" = "yes" ]; then
291 printhead "checking for overly long lines (over 79 characters) ..."
292 grep $_grepopts "^[[:print:]]\{80,\}$" $filelist
295 # -----------------------------------------------------------------------------
297 if [ "$_charset" = "yes" ]; then
298 printhead "checking bad charsets ..."
299 for I in $filelist ; do
300 case "$I" in
301 ./help/help_mp-*.h)
303 ./DOCS/*)
305 *.c|*.h)
306 iconv -c -f ascii -t ascii "$I" | diff $_diffopts "$I" -
308 esac
309 done
312 # -----------------------------------------------------------------------------
314 if [ "$_stupid" = "yes" ]; then
315 printhead "checking for stupid code ..."
317 # avoid false-positives in xpm files, docs, etc, only check .c and .h files
318 chfilelist=`echo $filelist | tr ' ' '\n' | grep "[\.][ch]$"`
320 for i in calloc malloc realloc memalign av_malloc av_mallocz faad_malloc \
321 lzo_malloc safe_malloc mpeg2_malloc _ogg_malloc; do
322 printhead "--> casting of void* $i()"
323 grep $_grepopts "([ ]*[a-zA-Z_]\+[ ]*\*.*)[ ]*$i" $chfilelist
324 done
326 for i in "" signed unsigned; do
327 printhead "--> usage of sizeof($i char)"
328 grep $_grepopts "sizeof[ ]*([ ]*$i[ ]*char[ ]*)" $chfilelist
329 done
331 for i in int8_t uint8_t; do
332 printhead "--> usage of sizeof($i)"
333 grep $_grepopts "sizeof[ ]*([ ]*$i[ ]*)" $chfilelist
334 done
336 printhead "--> usage of &&1"
337 grep $_grepopts "&&[ ]*1" $chfilelist
339 printhead "--> usage of ||0"
340 grep $_grepopts "||[ ]*0" $chfilelist
342 # added a-fA-F_ to eliminate some false positives
343 printhead "--> usage of *0"
344 grep $_grepopts "[a-zA-Z0-9)]\+[ ]*\*[ ]*0[^.0-9xa-fA-F_]" $chfilelist
346 printhead "--> usage of *1"
347 grep $_grepopts "[a-zA-Z0-9)]\+[ ]*\*[ ]*1[^.0-9ea-fA-F_]" $chfilelist
349 printhead "--> usage of +0"
350 grep $_grepopts "[a-zA-Z0-9)]\+[ ]*+[ ]*0[^.0-9xa-fA-F_]" $chfilelist
352 printhead "--> usage of -0"
353 grep $_grepopts "[a-zA-Z0-9)]\+[ ]*-[ ]*0[^.0-9xa-fA-F_]" $chfilelist
356 # -----------------------------------------------------------------------------