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.
15 # -----------------------------------------------------------------------------
34 # -----------------------------------------------------------------------------
36 # Avoid locale problems
40 # -----------------------------------------------------------------------------
67 echo " -(no)$1 $2 [default: $3]"
71 test "$_head" = "yes" && echo -e "$COLB$1$COLE"
75 test "$_files" != "" && echo "$_files" && return
77 if [ "$_svn" = "no" ]; then
79 |
grep -v "\.\#\|\~$\|\.depend\|\/\.svn\/\|config.mak\|^\./config\.h" \
80 |
grep -v "^\./version\.h\|\.o$\|\.a$\|configure.log\|^\./help_mp.h"
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
102 # -----------------------------------------------------------------------------
109 echo -e "\n$0 [options] [files]\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"
120 printoption
"all " "enable all tests" "no"
122 printoption
"showcont " "show offending content of file(s)" \
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 " \
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"
215 echo "unknown option: $i" >&2
224 # -----------------------------------------------------------------------------
228 if [ "$_color" = "yes" ]; then
236 # Generate filelist once so -svn isn't _that_ much slower than -nosvn anymore
238 filelist
=`all_filenames`
240 if [ "$_showcont" = "yes" ]; then
248 # -----------------------------------------------------------------------------
252 # -----------------------------------------------------------------------------
254 if [ "$_spaces" = "yes" ]; then
255 printhead
"checking for spaces in filenames ..."
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
306 iconv -c -f ascii
-t ascii
"$I" |
diff $_diffopts "$I" -
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
326 for i
in "" signed unsigned
; do
327 printhead
"--> usage of sizeof($i char)"
328 grep $_grepopts "sizeof[ ]*([ ]*$i[ ]*char[ ]*)" $chfilelist
331 for i
in int8_t uint8_t
; do
332 printhead
"--> usage of sizeof($i)"
333 grep $_grepopts "sizeof[ ]*([ ]*$i[ ]*)" $chfilelist
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 # -----------------------------------------------------------------------------