case $1 in -*) mod=$1; shift;; esac
for i in $*
do
	if test ! -r $i; then echo Cannot read documentation file $i; continue; fi
	bg=`grep "^.BG" $i`
	case $bg in
		.BG) where=.help;;
		.BG?D|.BG?M) where=sdata/.help
			if test -d sdata -a ! -d sdata/.help; then mkdir sdata/.help; fi
			;;
		*) echo "Documentation file $i improper format (no .BG line)"; continue;;
	esac
	if test ! -d $where; then echo Directory $where does not exist; continue; fi
	sed -n "/^.FN /s///p" $i >tmp1.$$	;: find all function names applying to this file
	fn=`sed -n 1p tmp1.$$`	;: first function name is file name
	cat $i >$where/$fn
	case $mod in -*u*) continue;; esac
	sed "s:.*:/^&	/d:" tmp1.$$ >tmp3.$$	;: names to be deleted from fun.tab
	sed -f tmp3.$$ $where/fun.tab 2>/dev/null >tmp2.$$	;: delete lines that match one of the current FNs
	sed "1d
s/^/$fn	/" tmp1.$$ >>tmp2.$$
	mv tmp2.$$ $where/fun.tab
done
rm tmp?.$$
