#! /bin/sh
# 
# Do_nlist 
#
#	     Given  some  C  source  file  which  fills  a
#	(struct  nlist)[]  with  certain symbol names, and
#	later does  nlist("/vmunix")  to  fill  the  table
#	(e.g,  ps.c,  w.c), this script produces on stdout
#	the listing of this C  file  with  current  values
#	from  /vmunix  pasted into the table, and the call
#	to nlist() removed. If the  output  is  saved  and
#	compiled  in  the same way as the original C file,
#	then the result will be a program whose  behaviour
#	will be indentical to the original, except that it
#	won't do the nlist("/vmunix")  every  time  it  is
#	run.  This  saves some time since nlist("/vmunix")
#	is an expensive operation.
#	
#	
#	Do_nlist should be run every time /vmunix is changed.
#
# Usage: do_nlist <C source file>
#
# Example: 
#	 do_nlist ps.c > xps.c
#	 cc <ps-flags> xps.c -o xps
#

PATH="/usr/ucb:/bin:/usr/bin"
export PATH

if test $# -lt 1
then
	echo "Usage: make_xps <C source file>"
	exit
fi

# init variables
ps=$1
sedcom="/tmp/ss.$$"
nm="/tmp/nm.$$"

nm -pg /vmunix > $nm
cat $ps |
sed -ne s/'{.*"\(_.*\)".*},'/'\1\$'/p |
while read x
do
	y=`
	grep $x $nm |
	awk ' { printf("{ \"%s\", N_ABS, 0, 0, 0x%s },\n", $3, $1) } '
	`
	z=`echo $y | awk -F\" ' { print $2 } '`
	echo s/'{.*"'$z'".*},'/"$y"/ >> $sedcom
done
echo 's/nlist(.*,.*).*;//' >> $sedcom
sed -f $sedcom $ps

rm $sedcom $nm
