2005-08-17 01:50:05 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Check source-tree for anomalies
|
|
|
|
#
|
|
|
|
# (C)opyright 2005 by Ivo van Poorten
|
|
|
|
# Licensed under GNU General Public License version 2
|
|
|
|
#
|
|
|
|
# Thanks to Melchior Franz of the FlightGear project for the original idea
|
|
|
|
# of a source-tree checker and Torinthiel for the feedback along the way.
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Default settings
|
|
|
|
|
|
|
|
_spaces=yes
|
|
|
|
_extensions=yes
|
|
|
|
_crlf=yes
|
|
|
|
_trailws=no
|
|
|
|
_rcsid=no
|
|
|
|
_oll=no
|
2006-04-14 10:47:40 +00:00
|
|
|
_charset=no
|
2006-07-14 22:05:49 +00:00
|
|
|
_stupid=no
|
2005-12-07 18:11:58 +00:00
|
|
|
_showcont=no
|
2005-08-17 01:50:05 +00:00
|
|
|
|
|
|
|
_color=yes
|
|
|
|
_head=yes
|
2006-07-14 12:57:37 +00:00
|
|
|
_svn=yes
|
2005-08-17 01:50:05 +00:00
|
|
|
_files=
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Avoid locale problems
|
|
|
|
|
|
|
|
export LC_ALL=C
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Helper functions
|
|
|
|
|
|
|
|
enable_all_tests() {
|
|
|
|
_spaces=yes
|
|
|
|
_extensions=yes
|
|
|
|
_crlf=yes
|
|
|
|
_trailws=yes
|
|
|
|
_rcsid=yes
|
|
|
|
_oll=yes
|
2006-04-14 10:47:40 +00:00
|
|
|
_charset=yes
|
2006-07-14 22:05:49 +00:00
|
|
|
_stupid=yes
|
2005-08-17 01:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
disable_all_tests() {
|
|
|
|
_spaces=no
|
|
|
|
_extensions=no
|
|
|
|
_crlf=no
|
|
|
|
_trailws=no
|
|
|
|
_rcsid=no
|
|
|
|
_oll=no
|
2006-04-14 10:47:40 +00:00
|
|
|
_charset=no
|
2006-07-14 22:05:49 +00:00
|
|
|
_stupid=no
|
2005-08-17 01:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printoption() {
|
|
|
|
echo " -(no)$1 $2 [default: $3]"
|
|
|
|
}
|
|
|
|
|
|
|
|
printhead() {
|
|
|
|
test "$_head" = "yes" && echo -e "$COLB$1$COLE"
|
|
|
|
}
|
|
|
|
|
|
|
|
all_filenames() {
|
|
|
|
test "$_files" != "" && echo "$_files" && return
|
|
|
|
|
2006-10-14 15:28:33 +00:00
|
|
|
if [ "$_svn" = "no" ]; then
|
2005-08-17 01:50:05 +00:00
|
|
|
find . -type f \
|
2006-07-14 12:57:37 +00:00
|
|
|
| grep -v "\.\#\|\~$\|\.depend\|\/\.svn\/\|config.mak\|^\./config\.h" \
|
2006-07-14 13:34:44 +00:00
|
|
|
| grep -v "^\./version\.h\|\.o$\|\.a$\|configure.log\|^\./help_mp.h"
|
2005-08-17 01:50:05 +00:00
|
|
|
else
|
2006-07-14 12:57:37 +00:00
|
|
|
list_svn .
|
2005-08-17 01:50:05 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2006-07-14 12:57:37 +00:00
|
|
|
list_svn() {
|
|
|
|
tmpfiles=`sed '/name/ba; /kind/ba; d; b;
|
|
|
|
:a; s/^ *....=\"\(.*\)\".*$/\1/;' $1/.svn/entries | \
|
|
|
|
sed '/$/N; s/\n/ /; / dir$/d; s/ file$//;'`
|
|
|
|
tmpdirs=`sed ' /name/ba; /kind/ba; d; b;
|
|
|
|
:a; s/^ *....=\"\(.*\)\".*$/\1/;' $1/.svn/entries | \
|
|
|
|
sed ' /$/N; s/\n/ /; / file$/d; /^ dir$/d; s/ dir$//;'`
|
|
|
|
|
|
|
|
for i in $tmpfiles; do
|
2005-08-17 01:50:05 +00:00
|
|
|
echo $1/$i
|
|
|
|
done
|
2006-07-14 12:57:37 +00:00
|
|
|
for j in $tmpdirs; do
|
|
|
|
list_svn $1/$j
|
2005-08-17 01:50:05 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Parse command line
|
|
|
|
|
|
|
|
for i in "$@"; do
|
|
|
|
case "$i" in
|
|
|
|
-help)
|
|
|
|
echo -e "\n$0 [options] [files]\n"
|
|
|
|
echo -e "options:\n"
|
|
|
|
printoption "spaces " "test for spaces in filenames" "$_spaces"
|
|
|
|
printoption "extensions" "test for uppercase extensions" "$_extensions"
|
|
|
|
printoption "crlf " "test for MSDOS line endings" "$_crlf"
|
|
|
|
printoption "trailws " "test for trailing whitespace" "$_trailws"
|
|
|
|
printoption "rcsid " "test for missing RCS Id's" "$_rcsid"
|
|
|
|
printoption "oll " "test for overly long lines" "$_oll"
|
2006-04-14 10:47:40 +00:00
|
|
|
printoption "charset " "test for wrong charset" "$_charset"
|
2006-07-14 22:05:49 +00:00
|
|
|
printoption "stupid " "test for stupid code" "$_stupid"
|
2005-08-17 01:50:05 +00:00
|
|
|
echo
|
|
|
|
printoption "all " "enable all tests" "no"
|
|
|
|
echo
|
2005-12-07 18:11:58 +00:00
|
|
|
printoption "showcont " "show offending content of file(s)" \
|
2006-07-14 15:12:05 +00:00
|
|
|
"$_showcont"
|
2005-12-07 18:11:58 +00:00
|
|
|
echo
|
2005-08-17 01:50:05 +00:00
|
|
|
printoption "color " "colored output" "$_color"
|
|
|
|
printoption "head " "print heading for each test" "$_head"
|
2006-07-14 12:57:37 +00:00
|
|
|
printoption "svn " "use .svn/ to determine which files to " \
|
|
|
|
"check" "$_svn"
|
2005-08-17 01:50:05 +00:00
|
|
|
echo -e "\nIf no files are specified, the whole tree is traversed."
|
2006-07-14 12:57:37 +00:00
|
|
|
echo -e "If there are, -(no)svn has no effect.\n"
|
2005-08-17 01:50:05 +00:00
|
|
|
exit
|
|
|
|
;;
|
2006-07-14 22:05:49 +00:00
|
|
|
-stupid)
|
|
|
|
_stupid=yes
|
|
|
|
;;
|
|
|
|
-nostupid)
|
|
|
|
_stupid=no
|
|
|
|
;;
|
2006-04-14 10:47:40 +00:00
|
|
|
-charset)
|
|
|
|
_charset=yes
|
|
|
|
;;
|
|
|
|
-nocharset)
|
|
|
|
_charset=no
|
|
|
|
;;
|
2005-08-17 01:50:05 +00:00
|
|
|
-oll)
|
|
|
|
_oll=yes
|
|
|
|
;;
|
|
|
|
-nooll)
|
|
|
|
_oll=no
|
|
|
|
;;
|
2006-07-14 12:57:37 +00:00
|
|
|
-svn)
|
|
|
|
_svn=yes
|
2005-08-17 01:50:05 +00:00
|
|
|
;;
|
2006-07-14 12:57:37 +00:00
|
|
|
-nosvn)
|
|
|
|
_svn=no
|
2005-08-17 01:50:05 +00:00
|
|
|
;;
|
|
|
|
-head)
|
|
|
|
_head=yes
|
|
|
|
;;
|
|
|
|
-nohead)
|
|
|
|
_head=no
|
|
|
|
;;
|
|
|
|
-color)
|
|
|
|
_color=yes
|
|
|
|
;;
|
|
|
|
-nocolor)
|
|
|
|
_color=no
|
|
|
|
;;
|
|
|
|
-spaces)
|
|
|
|
_spaces=yes
|
|
|
|
;;
|
|
|
|
-nospaces)
|
|
|
|
_spaces=no
|
|
|
|
;;
|
|
|
|
-extensions)
|
|
|
|
_extensions=yes
|
|
|
|
;;
|
|
|
|
-noextensions)
|
|
|
|
_extensions=no
|
|
|
|
;;
|
|
|
|
-crlf)
|
|
|
|
_crlf=yes
|
|
|
|
;;
|
|
|
|
-nocrlf)
|
|
|
|
_crlf=no
|
|
|
|
;;
|
|
|
|
-trailws)
|
|
|
|
_trailws=yes
|
|
|
|
;;
|
|
|
|
-notrailws)
|
|
|
|
_trailws=no
|
|
|
|
;;
|
|
|
|
-rcsid)
|
|
|
|
_rcsid=yes
|
|
|
|
;;
|
|
|
|
-norcsid)
|
|
|
|
_rcsid=no
|
|
|
|
;;
|
|
|
|
-all)
|
|
|
|
enable_all_tests
|
|
|
|
;;
|
|
|
|
-noall)
|
|
|
|
disable_all_tests
|
|
|
|
;;
|
|
|
|
-none)
|
2005-09-06 15:30:12 +00:00
|
|
|
disable_all_tests
|
2005-08-17 01:50:05 +00:00
|
|
|
;;
|
2005-12-07 18:11:58 +00:00
|
|
|
-showcont)
|
|
|
|
_showcont=yes
|
|
|
|
;;
|
|
|
|
-noshowcont)
|
|
|
|
_showcont=no
|
|
|
|
;;
|
2005-08-17 01:50:05 +00:00
|
|
|
-*)
|
|
|
|
echo "unknown option: $i" >&2
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
_files="$_files $i"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Set heading color
|
|
|
|
|
2006-10-14 15:28:33 +00:00
|
|
|
if [ "$_color" = "yes" ]; then
|
2005-08-17 01:50:05 +00:00
|
|
|
COLB="\e[36m"
|
|
|
|
COLE="\e[m"
|
|
|
|
else
|
|
|
|
COLB=""
|
|
|
|
COLE=""
|
|
|
|
fi
|
|
|
|
|
2006-07-14 12:57:37 +00:00
|
|
|
# Generate filelist once so -svn isn't _that_ much slower than -nosvn anymore
|
2005-08-17 01:50:05 +00:00
|
|
|
|
|
|
|
filelist=`all_filenames`
|
|
|
|
|
2006-10-14 15:28:33 +00:00
|
|
|
if [ "$_showcont" = "yes" ]; then
|
2006-04-14 10:47:40 +00:00
|
|
|
_diffopts="-u"
|
|
|
|
_grepopts="-n -I"
|
|
|
|
else
|
|
|
|
_diffopts="-q"
|
|
|
|
_grepopts="-l -I"
|
|
|
|
fi
|
|
|
|
|
2005-08-17 01:50:05 +00:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# DO CHECKS
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2006-10-14 15:28:33 +00:00
|
|
|
if [ "$_spaces" = "yes" ]; then
|
2005-08-17 01:50:05 +00:00
|
|
|
printhead "checking for spaces in filenames ..."
|
|
|
|
find . | grep " "
|
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2006-10-14 15:28:33 +00:00
|
|
|
if [ "$_extensions" = "yes" ]; then
|
2005-08-17 01:50:05 +00:00
|
|
|
printhead "checking for uppercase extensions ..."
|
|
|
|
echo $filelist | grep "\.[[:upper:]]\+$" | grep -v "\.S$"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2006-10-14 15:28:33 +00:00
|
|
|
if [ "$_crlf" = "yes" ]; then
|
2005-08-17 01:50:05 +00:00
|
|
|
printhead "checking for MSDOS line endings ..."
|
2006-07-14 15:08:31 +00:00
|
|
|
CR=`echo " " | tr ' ' '\015'`
|
|
|
|
grep $_grepopts "$CR" $filelist
|
2005-08-17 01:50:05 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2006-10-14 15:28:33 +00:00
|
|
|
if [ "$_trailws" = "yes" ]; then
|
2005-08-17 01:50:05 +00:00
|
|
|
printhead "checking for trailing whitespace ..."
|
2006-04-14 10:47:40 +00:00
|
|
|
grep $_grepopts "[[:space:]]\+$" $filelist
|
2005-08-17 01:50:05 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2006-10-14 15:28:33 +00:00
|
|
|
if [ "$_rcsid" = "yes" ]; then
|
2005-08-17 01:50:05 +00:00
|
|
|
printhead "checking for missing RCS \$Id\$ or \$Revision\$ tags ..."
|
|
|
|
grep -L -I "\$\(Id\|Revision\)[[:print:]]\+\$" $filelist
|
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2006-10-14 15:28:33 +00:00
|
|
|
if [ "$_oll" = "yes" ]; then
|
2005-08-17 01:50:05 +00:00
|
|
|
printhead "checking for overly long lines (over 79 characters) ..."
|
2006-04-14 10:47:40 +00:00
|
|
|
grep $_grepopts "^[[:print:]]\{80,\}$" $filelist
|
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2006-10-14 15:28:33 +00:00
|
|
|
if [ "$_charset" = "yes" ]; then
|
2006-04-14 10:47:40 +00:00
|
|
|
printhead "checking bad charsets ..."
|
|
|
|
for I in $filelist ; do
|
|
|
|
case "$I" in
|
|
|
|
./help/help_mp-*.h)
|
|
|
|
;;
|
|
|
|
./DOCS/*)
|
|
|
|
;;
|
|
|
|
*.c|*.h)
|
|
|
|
iconv -c -f ascii -t ascii "$I" | diff $_diffopts "$I" -
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2005-08-17 01:50:05 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
2006-07-14 22:05:49 +00:00
|
|
|
|
2006-10-14 15:28:33 +00:00
|
|
|
if [ "$_stupid" = "yes" ]; then
|
2006-07-14 22:05:49 +00:00
|
|
|
printhead "checking for stupid code ..."
|
|
|
|
|
|
|
|
# avoid false-positives in xpm files, docs, etc, only check .c and .h files
|
|
|
|
chfilelist=`echo $filelist | tr ' ' '\n' | grep "[\.][ch]$"`
|
|
|
|
|
|
|
|
for i in calloc malloc realloc memalign av_malloc av_mallocz faad_malloc \
|
|
|
|
lzo_malloc safe_malloc mpeg2_malloc _ogg_malloc; do
|
|
|
|
printhead "--> casting of void* $i()"
|
|
|
|
grep $_grepopts "([ ]*[a-zA-Z_]\+[ ]*\*.*)[ ]*$i" $chfilelist
|
|
|
|
done
|
|
|
|
|
|
|
|
for i in "" signed unsigned; do
|
|
|
|
printhead "--> usage of sizeof($i char)"
|
|
|
|
grep $_grepopts "sizeof[ ]*([ ]*$i[ ]*char[ ]*)" $chfilelist
|
|
|
|
done
|
|
|
|
|
|
|
|
for i in int8_t uint8_t; do
|
|
|
|
printhead "--> usage of sizeof($i)"
|
|
|
|
grep $_grepopts "sizeof[ ]*([ ]*$i[ ]*)" $chfilelist
|
|
|
|
done
|
|
|
|
|
|
|
|
printhead "--> usage of &&1"
|
|
|
|
grep $_grepopts "&&[ ]*1" $chfilelist
|
|
|
|
|
|
|
|
printhead "--> usage of ||0"
|
|
|
|
grep $_grepopts "||[ ]*0" $chfilelist
|
|
|
|
|
|
|
|
# added a-fA-F_ to eliminate some false positives
|
|
|
|
printhead "--> usage of *0"
|
|
|
|
grep $_grepopts "[a-zA-Z0-9)]\+[ ]*\*[ ]*0[^.0-9xa-fA-F_]" $chfilelist
|
|
|
|
|
|
|
|
printhead "--> usage of *1"
|
|
|
|
grep $_grepopts "[a-zA-Z0-9)]\+[ ]*\*[ ]*1[^.0-9ea-fA-F_]" $chfilelist
|
|
|
|
|
|
|
|
printhead "--> usage of +0"
|
|
|
|
grep $_grepopts "[a-zA-Z0-9)]\+[ ]*+[ ]*0[^.0-9xa-fA-F_]" $chfilelist
|
|
|
|
|
|
|
|
printhead "--> usage of -0"
|
|
|
|
grep $_grepopts "[a-zA-Z0-9)]\+[ ]*-[ ]*0[^.0-9xa-fA-F_]" $chfilelist
|
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|