#! /bin/sh

func=$1
CPP=cc
CPPFLAGS="-E -qlanglvl=ansi"
ac_ext=c
cat conftest.out_proto | awk "{ if (/[^a-z0-9]${func}[^a-z0-9]/) { s=10 }; if ( s > 0 ) { s -= 1; print; } }" | egrep -v '^#' | tr '\n' ' ' | tr -s '/' |  tr ';' '\n'  | grep -v "__${func}" | egrep "[^a-z0-9]${func}[^a-z0-9]" | tr -s '[:blank:]' | sed -e 's/extern//'

exit

cnt=0
while test $cnt -lt $paramcnt; do
	if test $cnt -eq 0; then
		cat conftest.out_proto | sed -e "s/${func}.*//" | sed -e 's/^[ 	]*//' | sed -e 's/[ 	]*$//g' > conftest.out_param
	else
		cat conftest.out_proto | sed -e "s/.*${func}//" | sed -e "s/[\(\)]//g" | cut -d, -f $cnt | sed -e 's/^[ 	]*//' | sed -e 's/[ 	]*$//g' > conftest.out_param
	fi

	cat conftest.out_param | tr -s '[:blank:]' > conftest.out_nospace
	if test -s conftest.out_nospace; then
		cp -f conftest.out_param conftest.out_param_${cnt}
	else
		echo "not found" > conftest.out_param_${cnt}
		echo "warning: found no argument"
	fi

	#XXX avoid subshell
	case $cnt in
		0) cnt=1;;
		1) cnt=2;;
		2) cnt=3;;
		3) cnt=4;;
		4) cnt=5;;
		5) cnt=6;;
		6) cnt=7;;
		7) cnt=8;;
		8) cnt=9;;
		9) cnt=10;;
		10) cnt=11;;
	esac

done


	#return value
	
_arg=0
_param=conftest.out_param_0
_func=$func
_ucfunc=$ucfunc

unset _nofunc

for val in "int"
do
	cat ${_param} | egrep "^${val}" > /dev/null
	test $? -eq 0 && _nofunc="" && break
	_nofunc=t
done
if test "x${_nofunc}" = xt; then
	if test "x$failure" != x; then
		failure="$failure|"
	fi
	failure="$failure ${_func} (${_arg}): (`cat ${_param}`)"
else
	cat >> confdefs.h <<EOF
#define HAVE_PROT_${_ucfunc}_${_arg} ${val}
EOF

fi

	#first argument
	
_arg=1
_param=conftest.out_param_1
_func=$func
_ucfunc=$ucfunc

unset _nofunc

for val in "int"
do
	cat ${_param} | egrep "^${val}" > /dev/null
	test $? -eq 0 && _nofunc="" && break
	_nofunc=t
done
if test "x${_nofunc}" = xt; then
	if test "x$failure" != x; then
		failure="$failure|"
	fi
	failure="$failure ${_func} (${_arg}): (`cat ${_param}`)"
else
	cat >> confdefs.h <<EOF
#define HAVE_PROT_${_ucfunc}_${_arg} ${val}
EOF

fi

	#second argument
	
_arg=2
_param=conftest.out_param_2
_func=$func
_ucfunc=$ucfunc

unset _nofunc

for val in "struct sockaddr *" "__SOCKADDR_ARG" "__const struct sockaddr *" "void *"
do
	cat ${_param} | egrep "^${val}" > /dev/null
	test $? -eq 0 && _nofunc="" && break
	_nofunc=t
done
if test "x${_nofunc}" = xt; then
	if test "x$failure" != x; then
		failure="$failure|"
	fi
	failure="$failure ${_func} (${_arg}): (`cat ${_param}`)"
else
	cat >> confdefs.h <<EOF
#define HAVE_PROT_${_ucfunc}_${_arg} ${val}
EOF

fi

	#third argument
	
_arg=3
_param=conftest.out_param_3
_func=$func
_ucfunc=$ucfunc

unset _nofunc

for val in "socklen_t *" "int *" "Psocklen_t" "size_t"
do
	cat ${_param} | egrep "^${val}" > /dev/null
	test $? -eq 0 && _nofunc="" && break
	_nofunc=t
done
if test "x${_nofunc}" = xt; then
	if test "x$failure" != x; then
		failure="$failure|"
	fi
	failure="$failure ${_func} (${_arg}): (`cat ${_param}`)"
else
	cat >> confdefs.h <<EOF
#define HAVE_PROT_${_ucfunc}_${_arg} ${val}
EOF

fi





#failure
if test "x$failure" != x; then
echo "$ac_t""failure" 1>&6

echo "$failure" | tr '|' '\n'

 failproto=t
else
	echo "$ac_t""ok" 1>&6
fi

rm -f conftest.*

