[alt.sources] check for name space pollution in include files gnu.gcc

rfg@ICS.UCI.EDU (12/29/89)

Archive-name: polluted/release
Original-posting-by: rfg@ICS.UCI.EDU
Original-subject: Is your system polluted?
Reposted-by: emv@math.lsa.umich.edu (Edward Vielmetti)

[This is an experimental alt.sources re-posting from the newsgroup(s)
gnu.gcc. Comments on this service to emv@math.lsa.umich.edu 
(Edward Vielmetti).]



As part of the work I'm doing on protoize/unprotoize, I decided that it would
be a good idea to be able to find out (for any given system) what the
names of all of the functions declared in system include files are.
I wrote the following script to do part of the job.

The results that I got from running this script on one system are very
saddening.  It appears that (for some systems at least) there is an awful
lot of pollution of various name spaces contained in the system include
files.  Specifically, there are lots of clashes of names where one name
is used for two (or more) different things in two (or more) different
include files.  This means that you may/will get errors if particular
pairs of include files are included into the same base file. :-(

For those of you who may want to know how polluted your own system's name
space is, I suggest that you try to run the following script and see what
happens.  I would be very interested to hear about results for various
systems.

All this script does is to make a big .c file that includes all of your
system's include files.  It then tries to compile the whole batch with gcc.
Now it seems that this ought to be an acceptable thing to do, but my
prediction is that (on most systems) many errors with arise during the
compilation.

Note that I have hacked out all of the filenames that I had to put into the
definition of the symbol DELETIONS in order to get the compile to complete
without error.  I did this to protect the guilty.

// rfg


#!/bin/sh

# Many include files require other include files to be included first
# The following is a list of such files.  This list may need to be
# tailored (i.e. added to, or reordered) for your particular system.
# There is generally no need to delete entries that don't apply to your
# particular system because if any one of the entries doesn't exist on
# your system, it will simply be ignored.

LEADERS="/usr/include/sys/types.h \
	/usr/include/rpc/types.h \
	/usr/include/rpc/auth.h \
	/usr/include/rpc/xdr.h \
	/usr/include/sys/socket.h \
	/usr/include/ufs/vnode.h \
	/usr/include/sys/ipc.h \
	/usr/include/rpc/clnt.h \
	/usr/include/rpcsvc/yp_prot.h \
	/usr/include/pwd.h \
	/usr/include/limits.h \
	/usr/include/utmp.h \
	/usr/include/stdio.h
	/usr/include/regexp.h"

# Note that for well behaved systems, it should be possible to include all of
# the include files which reside beneath /usr/include into one single file.

# If this is not true on your system, then that's definitely a problem.
# You should probably get either your sysadmin or your vendor to fix
# up your system include files.  Otherwise, you can include the names
# of offending files in the list of files *not* to be included here.

DELETIONS=""

# Some files may require odd things to be defined before they can be included.
# For example, regexp.h needs to have ERROR and INIT both defined to null
# string.

# If your include files need specific things defined, specify them here.

DEFINES="-DINIT= \
	-DERROR="


# Don't change anything below this line.
##############################################################################

LOCAL_INCLUDES=`find /usr/include -type f -name \*.h -print`

rm -f temp-include.c temp-include.s
rm -f leaders.h followers.h

echo '#include "leaders.h"' > temp-include.c
echo '#include "followers.h"' >> temp-include.c

# Find all the leader files that actually exist on this system, and write them
# (in the order given above) into the leaders.h file.

for leader_file in $LEADERS; do
	for include_file in $LOCAL_INCLUDES; do
		if [ "$include_file" = "$leader_file" ] ; then
			echo '#include "'$include_file'"' >> leaders.h
			break
		fi
	done
done

# Find all the non-leaders, and write them (in proper order) into the
# followers.h file.

for include_file in $LOCAL_INCLUDES; do
	IS_LEADER=0
	for leader_file in $LEADERS; do
		if [ "$include_file" = "$leader_file" ] ; then
			IS_LEADER=1
			break
		fi
	done
	if [ $IS_LEADER -eq 0 ] ; then
		echo '#include "'$include_file'"' >> followers.h
	fi
done

# kludge around problem files by not including them

for deletion in $DELETIONS; do
	fixed=`echo $deletion | sed 's%/%\\\\/%g'`
	echo /$fixed/d >> sed.script
done
sed -f sed.script followers.h > /tmp/followers.h
cp /tmp/followers.h followers.h
rm -f sed.script /tmp/followers.h

gcc $DEFINES -S temp-include.c
rm -f temp-include.c temp-include.s
rm -f leaders.h followers.h