Subject: populating section 9.
To: None <tech-kern@netbsd.org>
From: Darren Reed <darrenr@reed.wattle.id.au>
List: tech-kern
Date: 02/19/2000 18:55:45
There are a number of man pages, missing, from section 9, for functions
provided by libkern which also appear in section 3.

I've included a script, below, which goes to /sys/lib, looks at what's
there and then attempts to find man pages in /usr/share/man/man3 for
what's in /sys/lib and `converts' the man page from (3) to (9).  It
dumps all the various section 9 man pages in /sys/lib, presently :-)

Whilst some people might want to say "no need for duplicate man pages",
unless functions have man pages are in section 9, they (a) don't have
a publicly documented presence in the kernel as being part of the
interface available and (b) there's no other good way to tell what is
and isn't in libca vs the kernel.  I think it is good for us to include
things like bcmp, etc, in section 9 as well as 3.

My personal preference would be to have this script run as part of
building the installation tree (once it has been cleaned up that is :).

The script isn't that optimized for speed, but it appears to work rather
well with -current :)

Comments ?

Darren

#!/bin/ksh
# man3to9 - convert man3 pages to man9 for kernel functions that are common
# to libc but otherwise undocumented.
#
EXCLUDE='rpc'
SHARE=/usr/share
DESTD=.
TMP=tmpman
cd /sys/lib
#
# initial scan
#
find . -name \*.c -print | sed -e 's@./[^/]*/@@' | grep -v "$EXCLUDE" | \
while read f; do
	g=`basename $f .c`
	h=`ls -1 $SHARE/man/man3*/${g}.3* 2>&1`
	if [[ $? -eq 0 && ! -f $SHARE/man/man9/${g}.9 ]] ; then
		echo $h >> convertlist
	fi
done

sort -u convertlist | while read manpage; do
	outfile=`basename $manpage|sed -e 's/\.3/\.9/'`
#
# pass one.
#
	cp /dev/null seealso
	cat $manpage | sed -e '/.Sh LIBRARY/d' -e '/.Lb.*/d' \
			   -e '/.*#include.*/d' \
			   -e 's/\(.Dt .*\) 3.*/\1 9/' \
			   -e '/^.Xr .*/w seealso' -e '/^.Xr.*/d' > $TMP
#
# check x-refs
#
	cp /dev/null seenalso
	nl=
	com=
	cat seealso | sed -e 's/.Xr \([^ ]*\) .*/\1/' | while read i; do
		h=`ls -1 $SHARE/man/man9/${i}.9* 2>&1`
		if [[ $? -eq 0 ]] ; then
			printf "${com}${nl}.Xr ${i} 9" >> seenalso
			nl="\n"
			com=" ,"
		else
			grep -q $i convertlist
			if [[ $? -eq 0 ]] ; then
				printf "${com}${nl}.Xr ${i} 9" >> seenalso
				nl="\n"
				com=" ,"
			fi
		fi
	done
	if [[ -s seenalso ]] ; then
		echo >> seenalso
	fi
#
# pass two.
#
	sed -e '/.Sh SYNOPSIS/a\
.Fd #include <sys\/systm.h>
' -e '/.Sh SEE ALSO/r seenalso' $TMP > $outfile
	echo "$manpage --> $outfile"
done
/bin/rm -f seenalso seealso convertlist $TMPMAN
exit 0