#!/bin/csh
#	@(#)listlib	1.3	08/30/94
#
#
#
#     $Id: listlib,v 1.1 1998/03/16 20:02:54 avvede Exp $
#     $Log: listlib,v $
#     Revision 1.1  1998/03/16 20:02:54  avvede
#     Initial move to CVS
#
#
#
#	Copyright (c) 1986, 1987, 1988 by
#	Periphonics Corporation
#	4000 Veterans Memorial Highway
#	Bohemia
#	NY 11716
#
#	This software is furnished under a license and may be used and
#	copied only in accordance with the terms of such license and with
#	the inclusion of the above copyright notice. This software or any
#	other copies thereof, may not be provided or otherwise made available
#	to anyone other than the licensee. Title to and ownership of this
#	software remains with the Periphonics Corporation.
#
#	The information in this document is subject to change without notice
#	and should not be construed as a commitment by Periphonics.
#
#	Periphonics assumes no responsibility for the use or reliability of
#	its software on equipment that is not supplied by Periphonics.
#
#	File Name:
#		listlib
#
#	Description:
#		Procedure to get list of a shared library.
#		See usage line below.
#
#	Change				Reason
#	No.	Date		Name	for Change
#
#	0	01-jul-92	lmg	Original.
#	1	14-aug-92	lmg	Enhanced.
#	2	18-aug-92	lmg	Fixed name in nm -o.
#	3	20-aug-92	lmg	Changed format for colomn aligment.
#	4	20-aug-92	lmg	Changed _ to - for VRAM.
#	5	18-sep-92	lmg	Fixed for a case when cf_ prefix is used with
#					something being not a function.
#	6	29-sep-92	lmg	Changed ' ' to \t.
#	7	05-nov-92	lmg	Fixed datasize display and stoped to print names with '-'.
#	8	06-jan-92	lmg	Added display of the size of the obect.
#	9	13-dec-93	lmg	Removed -L, unexisting in rel5.
#	10	30-aug-94	lmg	Fixed $2 argument.
#
if ($?0 == 0) then
	set cmd=listlib
else
	set cmd=$0
endif
#
#	check argument count
#
if ($#argv == 2 && "$1" != "-C") then
usage:
	echo "usage: $cmd [-C] libcall"
	exit 1
endif
if ($#argv > 2 || $#argv < 1) then
	goto usage
endif
#
#	check library name
#
if ("$1" == "-C") then
	shift
endif

if ($1:e != "a" || `echo $1:t | grep ^lib` == "") then
	echo "${cmd}: invalid user's library name" $1
	exit 1
endif
set lib=$1

#
# 	check library existence
#
if ( ! -r $lib ) then
	echo Library $lib inaccessible.
	goto ending
endif
#	figure out the application names
#	$entryname contains Entry_point, Object_name, Entry_point, ...
#
echo " "
set type=call
set und=___										# Change all ___ to _
set sedcmd="{ /cf_/\!d; /T/\!d; s/.*a://; s/\:.*T _//; s/.ocf/ cf/; s/.o\:/ /; s/^\([^ ]*\) \(.*\)/\2 \1/; }"
set entrylist=`sh -c "nm -R -p -x ${lib} 2> /dev/null" | sed -e "$sedcmd"`		# Supress stderr
#
#	check if shared library exists and if it's not empty
#
if ( ! -r "$1:r".so ) then
	echo Shared part "$1:r".so inaccessible.
	echo Run make$type befory using
	echo " "
endif
if ( $#entrylist == 0 ) then
	echo Library $lib empty
	goto ending
endif
#
#	print
#
@ k = 1
echo "Size        Date          Module (Program/function)"
while ( $k <= $#entrylist )
	set entryname=${entrylist[$k]}			# Current entry point
	@ m = $k + 1
	set objectname=${entrylist[$m]}			# Corresponding object file name

	if ( $type == link ) then			# I want my '-' back
		set entryname=`echo $entryname | sed -e "s/_/-/g"`
	endif

	if ( ${entryname} != ${objectname} ) then	# Print entry name only if it differs
		set info="(${entryname})"
	else
		set info=
	endif
	echo "`ar tv $lib $objectname.o` $info" | sed -e "s/   //" -e "s/    //" -e "s/-- /--/" -e "s/^\([^ ]* \)\(.*\)/\2/" -e "s/\.o/	/" -e "s/	//" -e "s/^[ ]*//" -e "s/${und}/-/g" -e "s/ /	/"
	@ k = $k + 2					# Get next pair
end
echo Total:
size "$lib:r".so
#
#	leaving
#
ending:
	echo " "
	exit 0
