2005-08-17 01:50:05 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Check source-tree for anomalies
|
|
|
|
#
|
2007-07-31 08:17:35 +00:00
|
|
|
# Copyright (C) 2005-2007 by Ivo van Poorten
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-08-17 01:50:05 +00:00
|
|
|
#
|
|
|
|
# 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$
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2007-07-31 14:48:13 +00:00
|
|
|
# All yes/no flags. Spaces around flagnames are important!
|
|
|
|
|
|
|
|
testflags=" spaces extensions crlf tabs trailws rcsid oll charset stupid gnu \
|
2007-11-30 23:02:32 +00:00
|
|
|
res depr "
|
2007-07-31 14:48:13 +00:00
|
|
|
allflags="$testflags showcont color head svn "
|
|
|
|
|
2005-08-17 01:50:05 +00:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Avoid locale problems
|
|
|
|
|
|
|
|
export LC_ALL=C
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Helper functions
|
|
|
|
|
2007-07-31 14:50:44 +00:00
|
|
|
set_all_tests() {
|
|
|
|
for i in $testflags ; do
|
|
|
|
eval _$i=$1
|
|
|
|
done
|
2005-08-17 01:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printoption() {
|
2007-07-31 15:10:10 +00:00
|
|
|
test -n "$3" && def=$3 || eval def=\$_$1
|
|
|
|
echo " -(no)$1 $2 [default: $def]"
|
2005-08-17 01:50:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2007-12-05 17:42:56 +00:00
|
|
|
for p in . libavcodec libavutil libavformat libpostproc ; do
|
2007-12-05 23:44:31 +00:00
|
|
|
svn info -R $p 2>/dev/null | sed -n \
|
2007-12-03 21:45:43 +00:00
|
|
|
'/Path:/bb; :a; d; b; :b; s/Path: /.\//; h; :c; n;
|
|
|
|
/Node Kind:/bd; bc; :d; /directory/ba; g; p;'
|
2007-12-03 21:43:48 +00:00
|
|
|
done
|
2005-08-17 01:50:05 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2007-11-30 23:01:30 +00:00
|
|
|
# Default settings
|
|
|
|
|
|
|
|
set_all_tests no
|
|
|
|
_spaces=yes
|
|
|
|
_extensions=yes
|
|
|
|
_crlf=yes
|
|
|
|
|
|
|
|
_showcont=no
|
|
|
|
_color=yes
|
|
|
|
_head=yes
|
|
|
|
_svn=yes
|
|
|
|
_files=
|
|
|
|
|
2005-08-17 01:50:05 +00:00
|
|
|
# Parse command line
|
|
|
|
|
|
|
|
for i in "$@"; do
|
|
|
|
case "$i" in
|
2007-02-28 11:50:23 +00:00
|
|
|
-help|--help|-h|-\?)
|
2005-08-17 01:50:05 +00:00
|
|
|
echo -e "\n$0 [options] [files]\n"
|
|
|
|
echo -e "options:\n"
|
2007-07-31 15:10:10 +00:00
|
|
|
printoption "spaces " "test for spaces in filenames"
|
|
|
|
printoption "extensions" "test for uppercase extensions"
|
|
|
|
printoption "crlf " "test for MSDOS line endings"
|
|
|
|
printoption "tabs " "test for tab characters"
|
|
|
|
printoption "trailws " "test for trailing whitespace"
|
|
|
|
printoption "rcsid " "test for missing RCS Id's"
|
|
|
|
printoption "oll " "test for overly long lines"
|
|
|
|
printoption "charset " "test for wrong charset"
|
|
|
|
printoption "stupid " "test for stupid code"
|
|
|
|
printoption "gnu " "test for GNUisms"
|
|
|
|
printoption "res " "test for reserved identifiers"
|
2007-11-30 22:52:56 +00:00
|
|
|
printoption "depr " "test for deprecated function calls"
|
2005-08-17 01:50:05 +00:00
|
|
|
echo
|
|
|
|
printoption "all " "enable all tests" "no"
|
2007-02-28 11:46:53 +00:00
|
|
|
echo " (-noall can be specified as -none)"
|
2005-08-17 01:50:05 +00:00
|
|
|
echo
|
2007-07-31 15:10:10 +00:00
|
|
|
printoption "showcont " "show offending content of file(s)"
|
2005-12-07 18:11:58 +00:00
|
|
|
echo
|
2007-07-31 15:10:10 +00:00
|
|
|
printoption "color " "colored output"
|
|
|
|
printoption "head " "print heading for each test"
|
2007-03-12 17:16:45 +00:00
|
|
|
printoption "svn " \
|
2007-07-31 15:10:10 +00:00
|
|
|
"use svn info to determine which files to check"
|
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
|
|
|
|
;;
|
|
|
|
-all)
|
2007-07-31 14:50:44 +00:00
|
|
|
set_all_tests yes
|
2005-08-17 01:50:05 +00:00
|
|
|
;;
|
|
|
|
-noall)
|
2007-07-31 14:50:44 +00:00
|
|
|
set_all_tests no
|
2005-08-17 01:50:05 +00:00
|
|
|
;;
|
|
|
|
-none)
|
2007-07-31 14:50:44 +00:00
|
|
|
set_all_tests no
|
2005-08-17 01:50:05 +00:00
|
|
|
;;
|
|
|
|
-*)
|
2007-07-31 14:48:13 +00:00
|
|
|
var=`echo X$i | sed 's/^X-//'`
|
|
|
|
val=yes
|
|
|
|
case "$var" in
|
|
|
|
no*)
|
|
|
|
var=`echo "$var" | cut -c 3-`
|
|
|
|
val=no
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
case "$allflags" in
|
|
|
|
*\ $var\ *)
|
|
|
|
eval _$var=$val
|
|
|
|
;;
|
|
|
|
*)
|
2007-07-31 14:51:56 +00:00
|
|
|
echo "unknown option: $i" >&2
|
|
|
|
exit 0
|
|
|
|
;;
|
2007-07-31 14:48:13 +00:00
|
|
|
esac
|
|
|
|
;;
|
2005-08-17 01:50:05 +00:00
|
|
|
*)
|
|
|
|
_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
|
|
|
|
|
2007-12-05 23:36:03 +00:00
|
|
|
# Test presence of svn info
|
|
|
|
|
|
|
|
if [ "$_svn" = "yes" -a ! -d .svn ] ; then
|
|
|
|
echo "No svn info available. Please use -nosvn." >&2
|
|
|
|
exit 1
|
|
|
|
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`
|
|
|
|
|
2007-12-05 23:41:59 +00:00
|
|
|
case "$_stupid$_res$_depr$_gnu" in
|
2007-12-05 23:39:01 +00:00
|
|
|
*yes*)
|
2007-07-31 07:45:06 +00:00
|
|
|
# generate 'shortlist' to avoid false positives in xpm files, docs, etc,
|
|
|
|
# when one only needs to check .c and .h files
|
|
|
|
chfilelist=`echo $filelist | tr ' ' '\n' | grep "[\.][ch]$"`
|
2007-12-05 23:39:01 +00:00
|
|
|
;;
|
|
|
|
esac
|
2007-07-31 07:45:06 +00:00
|
|
|
|
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
|
|
|
|
|
2007-07-31 07:49:24 +00:00
|
|
|
TAB=`echo " " | tr ' ' '\011'`
|
|
|
|
|
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
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
2007-05-07 17:34:31 +00:00
|
|
|
if [ "$_tabs" = "yes" ]; then
|
|
|
|
printhead "checking for TAB characters ..."
|
|
|
|
grep $_grepopts "$TAB" $filelist
|
|
|
|
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
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
2007-07-30 18:08:26 +00:00
|
|
|
|
2007-12-05 23:41:59 +00:00
|
|
|
if [ "$_gnu" = "yes" -a -n "$chfilelist" ]; then
|
2007-07-30 18:08:26 +00:00
|
|
|
printhead "checking for GNUisms ..."
|
2007-12-05 23:41:59 +00:00
|
|
|
grep $_grepopts "case.*\.\.\..*:" $chfilelist
|
2007-07-30 18:08:26 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
2006-04-14 10:47:40 +00:00
|
|
|
|
2007-07-31 07:55:22 +00:00
|
|
|
if [ "$_res" = "yes" -a -n "$chfilelist" ]; then
|
2007-07-31 07:45:06 +00:00
|
|
|
printhead "checking for reserved identifiers ..."
|
|
|
|
grep $_grepopts "#[ $TAB]*define[ $TAB]\+_[[:upper:]].*" $chfilelist
|
|
|
|
grep $_grepopts "#[ $TAB]*define[ $TAB]\+__.*" $chfilelist
|
|
|
|
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
|
|
|
|
2007-07-31 07:55:22 +00:00
|
|
|
if [ "$_stupid" = "yes" -a -n "$chfilelist" ]; then
|
2006-07-14 22:05:49 +00:00
|
|
|
printhead "checking for stupid code ..."
|
|
|
|
|
|
|
|
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()"
|
2007-07-31 08:11:18 +00:00
|
|
|
grep $_grepopts "([ $TAB]*[a-zA-Z_]\+[ $TAB]*\*.*)[ $TAB]*$i" \
|
|
|
|
$chfilelist
|
2006-07-14 22:05:49 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
for i in "" signed unsigned; do
|
|
|
|
printhead "--> usage of sizeof($i char)"
|
2007-07-31 08:11:18 +00:00
|
|
|
grep $_grepopts "sizeof[ $TAB]*([ $TAB]*$i[ $TAB]*char[ $TAB]*)" \
|
|
|
|
$chfilelist
|
2006-07-14 22:05:49 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
for i in int8_t uint8_t; do
|
|
|
|
printhead "--> usage of sizeof($i)"
|
2007-07-31 08:06:37 +00:00
|
|
|
grep $_grepopts "sizeof[ $TAB]*([ $TAB]*$i[ $TAB]*)" $chfilelist
|
2006-07-14 22:05:49 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
printhead "--> usage of &&1"
|
2007-07-31 08:06:37 +00:00
|
|
|
grep $_grepopts "&&[ $TAB]*1" $chfilelist
|
2006-07-14 22:05:49 +00:00
|
|
|
|
|
|
|
printhead "--> usage of ||0"
|
2007-07-31 08:06:37 +00:00
|
|
|
grep $_grepopts "||[ $TAB]*0" $chfilelist
|
2006-07-14 22:05:49 +00:00
|
|
|
|
|
|
|
# added a-fA-F_ to eliminate some false positives
|
|
|
|
printhead "--> usage of *0"
|
2007-07-31 08:11:18 +00:00
|
|
|
grep $_grepopts "[a-zA-Z0-9)]\+[ $TAB]*\*[ $TAB]*0[^.0-9xa-fA-F_]" \
|
|
|
|
$chfilelist
|
2006-07-14 22:05:49 +00:00
|
|
|
|
|
|
|
printhead "--> usage of *1"
|
2007-07-31 08:11:18 +00:00
|
|
|
grep $_grepopts "[a-zA-Z0-9)]\+[ $TAB]*\*[ $TAB]*1[^.0-9ea-fA-F_]" \
|
|
|
|
$chfilelist
|
2006-07-14 22:05:49 +00:00
|
|
|
|
|
|
|
printhead "--> usage of +0"
|
2007-07-31 08:11:18 +00:00
|
|
|
grep $_grepopts "[a-zA-Z0-9)]\+[ $TAB]*+[ $TAB]*0[^.0-9xa-fA-F_]" \
|
|
|
|
$chfilelist
|
2006-07-14 22:05:49 +00:00
|
|
|
|
|
|
|
printhead "--> usage of -0"
|
2007-07-31 08:11:18 +00:00
|
|
|
grep $_grepopts "[a-zA-Z0-9)]\+[ $TAB]*-[ $TAB]*0[^.0-9xa-fA-F_]" \
|
|
|
|
$chfilelist
|
2006-07-14 22:05:49 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------
|
2007-11-30 22:52:56 +00:00
|
|
|
|
|
|
|
if [ "$_depr" = "yes" -a -n "$chfilelist" ]; then
|
|
|
|
printhead "checking for deprecated and obsolete function calls ..."
|
|
|
|
|
|
|
|
for i in bcmp bcopy bzero getcwd getipnodebyname inet_ntoa inet_addr \
|
|
|
|
atoq ecvt fcvt ecvt_r fcvt_r qecvt_r qfcvt_r finite ftime gcvt herror \
|
|
|
|
hstrerror getpass getpw getutent getutid getutline pututline setutent \
|
|
|
|
endutent utmpname gsignal ssignal gsignal_r ssignal_r infnan memalign \
|
|
|
|
valloc re_comp re_exec drem dremf dreml rexec svc_getreq sigset \
|
|
|
|
sighold sigrelse sigignore sigvec sigmask sigblock sigsetmask \
|
|
|
|
siggetmask ualarm ulimit usleep statfs fstatfs ustat get_kernel_syms \
|
2007-12-03 21:40:54 +00:00
|
|
|
query_module sbrk tempnam tmpnam mktemp mkstemp
|
2007-11-30 22:52:56 +00:00
|
|
|
do
|
|
|
|
printhead "--> $i()"
|
|
|
|
grep $_grepopts "[^a-zA-Z0-9]$i[ $TAB]*(" $chfilelist
|
|
|
|
done
|
|
|
|
fi
|