Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83 (MC840302); site boring.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!harvard!seismo!mcvax!boring!steven From: steven@boring.UUCP Newsgroups: net.sources Subject: Check C identifiers for uniqueness Message-ID: <6468@boring.UUCP> Date: Wed, 19-Jun-85 17:32:17 EDT Article-I.D.: boring.6468 Posted: Wed Jun 19 17:32:17 1985 Date-Received: Fri, 21-Jun-85 00:07:19 EDT Reply-To: steven@mcvax.UUCP (Steven Pemberton) Organization: CWI, Amsterdam Lines: 60 Apparently-To: rnews@mcvax.LOCAL 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/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/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