Donovan said:
Detecting dead headers is an extremely tiresome and lengthy process. Is
there an automated utility available which might do this for me? That is,
some utility that will check my .cpp and .h files and determine which
headers that are referenced are unnecessary?
I wrote a shell script several years ago to do that. It's far from perfect,
but it's a start (and free). It searches for the name of the included file
in the file doing the including. If the nameis found more than once I
assume the include needs to be there.
#!/bin/tcsh
set tmpfil=un.inc.$$
foreach f ( $* )
# See what file f "includes" (ignore <includes> - those are usually
# system things).
grep '^#include' $f | cut -f2 -d'"' | grep -v include | cut -f1 -d. >
$tmpfil
set firstPass=0
#
# For each file thus included...
#
foreach i (`cat $tmpfil`)
# If the name included appears more than once in the file
# being checked...
expr `grep $i $f | wc -l` \> 1 > /dev/null
if ( $status == "1" ) then
# Print the filename the 1st time we find a possibly useless include.
if ( `expr $firstPass == 0` ) then
set firstPass=1
echo $f
endif
# Print the name of the included file.
echo "\t" $i
endif
end
end
rm $tmpfil