#!/usr/local/plan9/bin/rc
# Usage: sig key ...
#	prints out function signatures by grepping the manual

. 9.rc
*=`{echo $*|tr A-Z a-z|tr -dc 'a-z0-9_ \012'}	# fold case, delete funny chars
if(~ $#* 0){
	echo Usage: sig function ... >[1=2]
	exit 1
}

for (i) {
	files=`{grep -il '[ 	]\*?'$i'\(' $PLAN9/man/man3/*.3*}
	for(j in $files) {
		{echo .nr LL 20i; 9 sed -n '/^.SH SYNOPSIS/,/^.SH.*DESCR/p'  $j } |
			nroff -man |
			sed '
				:a
				/,$/ {
					N
					s/\n//
				}
				ta
				s/[ 	]+/ /g' |
			grep -i -e '[ 	]\*?'$i'\(' | sed 's/^[ +]/	/'
	}
}

exit 0
