#!/bin/sh # # lintDead -- identify "dead" code, un-called functions in a source tree. # Can produce false positives if the use is in another file. # Output is # "source/auth/auth.c", line 529: warning: name defined but never used: make_auth_context_fixed in auth.c(529) # ProgName=`basename $0` main() { if [ $# -lt 1 ]; then say "$ProgName error: you must supply a parameter" say "Usage: $0 parameter" exit 1 fi find $1 -type f -name '*\.c' -o -name '*\.h' -o -name '*.cpp' |\ egrep -v 'SCCS|RCS|\.svn' |\ xargs lint -s -XCC=yes -Nlevel=2 \ -erroff=%all,no%E_NAME_DEF_NOT_USED2,no%E_NAME_DEF_NOT_USED |\ postprocess } # # postprocess -- check with cscope, in the current directory # # 1 2 3 4 5 6 7 8 9 10 #"source/auth/auth.c", line 529: warning: name defined but never used: make_auth_context_fixed in auth.c(529) # postprocess() { while read one two three four five six seven eight nine ten rest; do x=`cscope -d -L -3 $ten` if [ "$x" = "" ]; then echo "$one $two $three $four $five $six $seven $eight $nine $ten $rest" fi done } say() { echo "$@" 1>&2 } main "$@"