I wanted to add a dumb manpages completion to my OpenBSD's ksh, and this is how i generated a complete list of the installed manpages:
makewhatis -QDn | awk '{ sub(/\(.+/, ""); gsub(/, /, "\n"); print }'
Exploiting mandoc.db(5) directly may be faster, but anyway creating a 11k+ elements array in ksh is slow !