#! /bin/sh
PLATFORM=`Splus PLATFORM 2>/dev/null`
if [ $# = 0 ] 
then
	echo "Syntax : $0 files ..." 1>&2
	exit 1
fi
for file
do
	case $PLATFORM in
	SUNOS4_SPARC|SUN3|VAX|DECSTATION|LINUX)
		nm -og $file
		;;
        SUNOS5_SPARC*)
                nm -Rhp $file |
                sed -e 's/^\(.*\) \([^ ]*:\)\([^:]*\)$/\2\1 \3/'
                ;;
        LINUX*)
                nm -o $file |
                sed -e 's/^\(.*\) \([^ ]*:\)\([^:]*\)$/\2\1 \3/'
                ;;
        OSF1_DECALPHA)
                nm -Bog $file
                ;;
	IRIS4D)
		nm -Bog $file | grep -v ' [AN] '
		;;
	APOLLO|HP300)
		nm -pog $file
		;;
	HP700|HP800)
# object files & executables ok, need to process libraries with awk
# (use awk to see if it is library)
		nm -pr $file | sed 's/:/ /g' | grep -v ' [a-z] ' |
			awk '/^..*$/ { \
				if ( $0 ~ /\[.*\] $/ ) { \
					obj = $0 \
				} else { \
					if (obj != "") { \
						print obj, $2, $3, $4 \
					} else { \
						print $0 \
					} \
				} \
			}'
		
		;;
	IBMRS6000)
		case `uname -v` in
		3)
# must use /usr/ucb/nm (which is mangled version of Berkeley nm)
# -o means different things for libraries and objects/executables
# use exit status of 'ar t' to see if file is library
                   islib=`if ar t $file >/dev/null 2>&1 ; then echo yes ; else echo no ; fi`
                   echo "islib = \"$islib\""
# string equality is -eq in ibm, not the usual =.
                   if [ islib -eq "yes" ]
                     then
                       echo "library $file"
                       tfile=`echo $file | sed -e "s/\//./g"`
                       echo "tfile=$tfile"
                       /usr/ucb/nm -og $file | sed -e "s/^/$tfile:/"
                     else
                       echo "not a library $file"
                       /usr/ucb/nm -og $file
                     fi
	             ;;
	          *) nm -ABog $file 
		     ;;
		  esac
		  ;;
	CONVEX|UNIX386)
		echo "NM : not implemented on $PLATFORM"
		exit 1
		;;
	*)
		echo "Unrecognized PLATFORM: $PLATFORM" 1>&2
		exit 1
		;;
	esac
done
exit 0
