#!/bin/sh

# $XFree86: mit/server/ddx/x386/etc/mkwhatis.bsd,v 1.3 1993/03/27 09:31:33 dawes Exp $

# Whenever you install additional preformatted man pages you should
# run this script that updates whatis.db.  This makes 'man -k' report
# info on the new pages.

for file in `find . -name '*.0' -print`; do
  sed -n -f /usr/share/man/makewhatis.sed $file;
done | col -b | sort -u | awk '
# Cut the whatis entries into lines less than 256 characters long.
# Otherwise man complains. Rich@rice.edu
{
# scan for the parenthesized manpage name.
 for (i=1; i<=NF; i++) {if (match($(i), "\(")) {n = i;}};
# get the tail of the entry
 tail = "";
 for (i=n+2; i<=NF; i++) {
# elide hyphens
   if (sub(/-$/, "", $(i))) {
     tail = (tail $(i));
   } else {
     tail = (tail $(i) " ");
   }
 }
 tail = ($(n) " " $(n+1) " " tail $(i));
 taillen = length (tail);
# get the subroutine names
 for (i=1; i<n; i++) {foo[i] = $(i);};
# build lines shorter than a given maximum.
 i = 1;
 while (i < n) {
# set the maximum line length here
   while ((i < n) && (len + length(foo[i]) + taillen < 256)) {
     line = (line foo[i++] " ");
     len = length (line);
   }
   sub(/, $/, " ", line);
   print line tail "";
   line = "";
   len = length (line);
 }
}
' > whatis.db

