#!/bin/csh
#	@(#)dellib	1.9	9/25/92
#
#
#     $Id: dellib,v 1.1 1998/03/16 20:02:52 avvede Exp $
#     $Log: dellib,v $
#     Revision 1.1  1998/03/16 20:02:52  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:
#		dellib
#
#	Description:
#		Procedure to remove from shared libs.
#		See usage line below.
#
#	Change				Reason
#	No.	Date		Name	for Change
#
#	0	01-jul-92	lmg	Original.
#	1	07-jul-92	lmg	Added library lock.
#	2	10-jul-92	lmg	Moved lock to reduce the window.
#	3	24-jul-92	lmg	Switched to applist procedure instead of liblock.
#	4	14-aug-92	lmg	Changed to file locking mechanism.
#	5	19-aug-92	lmg	Added $shlib. lock.
#	6	25-sep-92	lmg	Got rid of library list (was too long).
#	7	16-mar-95	amu	Got rid of liblink option for 4.5.
#	8	22-mar-95	amu	Made [-C] optional.
#
if ($?0 == 0) then
	set cmd=dellib
else
	set cmd=$0
endif
#
#	check argument count
#
if ($#argv == 3 && "$1" != "-C") then
usage:
	echo "usage: $cmd [-C] libcall module_name"
	exit 1
endif
if ($#argv > 3 || $#argv < 2) then
	goto usage
endif
if ($#argv == 2  && "$1" == "-C") then
	goto usage
endif
if ("$1" == "-C") then
	shift
endif
set exitval=0
if ($1:e != "a" || `echo $1:t | grep ^lib` == "") then
	echo "${cmd}: invalid user's library name" $1
	exit 1
endif
set lib=$1
set msg=Function
set type=call
#
#	figure out the application name and what to delete
#
if ($#argv < 1) then
	goto usage
endif
#
# Set lists of names
#
set appname=$argv[$#argv]
set onlyname="$appname:r"
set shortname=`echo ${appname}`
if ( "${shortname}" != "${onlyname}" ) then
	echo " "
	echo "${cmd} Warning: Trying to truncate name ${appname} in the library"
	echo " "
	set onlyname=$shortname
endif
set object="$onlyname".o
set found=`ar t $lib | grep "^$object"`
#
# Remove if there is something
#
if ( $found != "" ) then
	unalias cd
	set shlib="$lib:r".so
	set tempdir=/tmp/DELLIB$$		# temp dir to keep all stuff
	set libpath=`dirname $lib`		# directory path, may be with '.'
	set fullpath=`pushd $libpath`		# convert it to absolute path
	set fullib="$fullpath[1]"/"$lib:t"	# make a full library name with abs path
	set mydir=$cwd

	set tabfile=

	cp ${shlib} ${shlib}.			# executable copy
	chmod +w $shlib				# signal applications to switch

	onintr goodbye
	mkdir $tempdir				# work begins here
	cd $tempdir
	ar x $fullib
	"rm" -f $object $tabfile __.SYMDEF
	set list=`ls`
	if ( "$list" == "" ) then
		liblocker $fullib "ld -G -o '$fullib:r'.so -z text"
	else
		liblocker $fullib "ld -G -o '$fullib:r'.so -z text *.o"
	endif
	ar d $fullib $object $tabfile
	cd $mydir
#	ranlib $lib
	liblocker -f ${shlib}. "'rm' -f ${shlib}."
else
	echo $msg \"$appname\" was not found in the library $lib
	set exitval=1
endif
#
# Cleaning
#
goodbye:
if (${?tempdir} == "1") then
	"rm" -rf ${tempdir}
endif
exit $exitval
