[net.sources] Check C identifiers for uniqueness

steven@boring.UUCP (06/20/85)

If a C program is to be portable, its external identifiers must all differ
in the first 7 characters, and its non-externals in the first 8. Many
compilers have a larger limit than this and, curse them, no switch to
enforce the smaller limit.

The following shell scripts check that the identifiers in a C program
conform to the limits: the script 7limit takes an unstripped binary, and
checks all externals; the script 8limit takes a list of object files, and
checks the non-externals. The scripts work by processing the output of the
nm(1) command, which is why the binary must be unstripped.

Steven Pemberton, CWI, Amsterdam; steven@mcvax.

--------CUT HERE--------
: This is a shar archive. Extract with sh, not csh.
: The rest of this file will extract:
: 7limit 8limit
echo x - 7limit
sed -e 's/^X//' <<'Bye-Bye' >7limit
X: Check externals differ over first 7 chars
Xcase $# in
X1) ;;
X*) echo Usage: $0 executable-file ; exit 1;;
Xesac
X
Xtrap 'rm -f /tmp/lim1.$$ /tmp/lim2.$$; exit 1' 1 2 15
Xnm -g $1 | sed "s/^............//" >/tmp/lim1.$$
Xsed "s/^\(.......\).*/\1/" </tmp/lim1.$$ | uniq -d | sed "s/.*/grep \"^&\" \/tmp\/lim1.$$/" > /tmp/lim2.$$
Xif test -s /tmp/lim2.$$
Xthen
X	echo The following externals don\'t differ in the first 7 characters:
X	sh /tmp/lim2.$$
Xelse
X	echo All externals differ in the first 7 characters
Xfi
Xrm -f /tmp/lim1.$$ /tmp/lim2.$$
Bye-Bye
echo x - 8limit
sed -e 's/^X//' <<'Bye-Bye' >8limit
X: Check names differ over first 8 chars
Xcase $# in
X0) echo Usage: $0 object-files ... ; exit 1;;
X*) ;;
Xesac
X
Xtrap 'rm -f /tmp/lim1.$$ /tmp/lim2.$$; exit 1' 1 2 15
Xfor f
Xdo
X   echo $f:
X   nm $f | sed "s/^...........//" | grep "^_" | sed "s/^_//" >/tmp/lim1.$$
X   sed "s/^\(........\).*/\1/" </tmp/lim1.$$ | uniq -d | sed "s/.*/grep \"^&\" \/tmp\/lim1.$$/" >/tmp/lim2.$$
X   if test -s /tmp/lim2.$$
X   then
X	echo In $f the following don\'t differ in the first 8 characters:
X	sh /tmp/lim2.$$
X   fi
Xdone
Xrm -f /tmp/lim1.$$ /tmp/lim2.$$
Bye-Bye
chmod 755 7limit 8limit

steven@boring.UUCP (07/01/85)

Someone complained that the two scripts that I submitted checked for the 7
limit for externals, and the 8 limit for internals, but not for the 6
character case-independent limit for externals.
Here is a script to check that. Beware that it uses 'grep -i' to grep case
independently, but on some systems a different flag is used. Change this if
necessary.

Steven Pemberton, CWI, Amsterdam; steven@mcvax.

------------------ CUT HERE -----------------------
: This is a shar archive. Extract with sh, not csh.
: The rest of this file will extract:
: 6limit
echo x - 6limit
sed -e 's/^X//' <<'Bye-Bye' >6limit
X: Check externals differ over first 7 chars
Xcase $# in
X1) ;;
X*) echo Usage: $0 executable-file ; exit 1;;
Xesac
X
Xtrap 'rm -f /tmp/lim1.$$ /tmp/lim2.$$; exit 1' 1 2 15
Xnm -g $1 | sed "s/^............//" >/tmp/lim1.$$
Xsed "s/^\(......\).*/\1/" </tmp/lim1.$$ | tr A-Z a-z | sort | uniq -d | sed "s/.*/grep -i \"^&\" \/tmp\/lim1.$$/" > /tmp/lim2.$$
Xif test -s /tmp/lim2.$$
Xthen
X	echo The following externals don\'t differ in the first 6 characters:
X	sh /tmp/lim2.$$
Xelse
X	echo All externals differ in the first 7 characters
Xfi
Xrm -f /tmp/lim1.$$ /tmp/lim2.$$
Bye-Bye