#!/bin/csh
#
#
#     $Id: applist,v 1.1 1998/03/16 20:02:49 avvede Exp $
#     $Log: applist,v $
#     Revision 1.1  1998/03/16 20:02:49  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:
#		applist
#
#	Description:
#		Procedure to create a list of applications
#		See usage line below.
#
#	Change				Reason
#	No.	Date		Name	for Change
#
#	0	24-jul-92	lmg	Original.
#
#
if ($?0 == 0) then
	set cmd=applist
else
	set cmd=$0
endif
#
#	check argument count
#
if ($#argv != 3) then
usage:
	echo "usage: $cmd {-L liblink | -C libcall} applist"
	exit 1
endif
#
#	Get actual values
#	Note that instead of libnames we can use any qualifiers
#
set libtype="$1"
set lib=$2
set applist=$3
#
# Look for application, which is using the library
# Pass PID, aplication_name, phone and line numbers to AMU.
#
set what=`which ps | grep ucb`
if ( "$what" == "" ) then
	set arg=-ef
else
	set arg=-ax
endif
ps $arg | \
egrep -e "(${libtype}).*(${lib})" | egrep -v "grep|csh|-s" > $applist.tmp
if ( -z $applist.tmp ) then			# Applications were not found
	/bin/rm -f $applist.tmp
	exit 0
endif
#
# We need this $applist.tmp file in case of empty list.
# Otherwize awk complains
#
cat $applist.tmp | awk '{ ORS = " "; \
print "\n" $1 " "  $5 ; \
for ( i = 5; i <= NF; i++ ) if ( $i == "-p" || $i == "-v" ) print $i " " $(i+1) }' > $applist
/bin/rm -f $applist.tmp
exit 0
