Check C identifiers for uniqueness

steven at boring.UUCP steven at boring.UUCP
Thu Jun 20 07:32:17 AEST 1985


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 at 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



More information about the Comp.sources.unix mailing list