#!/bin/sh # # makewhatis 2.2 - make whatis(5) database. Author: Kees J. Bot. # # Make the whatis database of a man directory from the manual pages. match $1 { with -* set -$Flags x x } match $Argc { with 1 with * echo "Usage: $0 " >&2 exit 1 } cd $1 || exit do { # First pass, gathering the .SH NAME lines in various forms. # First the man[1-9] directories, the titles are under the .SH NAME # section header. for chap in [1 2 3 4 5 6 7 8 9] { for page in [man$chap/*.$chap] { if test -f $page { # (Old sh barfs on 'continue') sed -e 's/ / /g s/"NAME"/NAME/g s/^\.Sh/\.SH/g /^\.SH NAME/,/^\.SH /!d /^\.SH /d s/\\f.//g s/\\s[+-].//g s/\\s.//g s/\\// '"s/ - / ($chap) - /" < "$page" } } } # The Minix "Book style" documents, look for .CD for page in [man1x/*.1x] { if test -f $page { sed -e 's/ / /g /^\.CD /!d s/^[^"]*"// s/"[^"]*$// s/\\(en/-/g s/\\f.//g s/\\s[+-].//g s/\\s.//g s/\\\*(M2/MINIX/g s/\\// '"s/ - / (1x) - /" < "$page" } } # Some people throw extra flat text files into the cat[1-9] # directories. It would be nice if man(1) can find them. trap 'rm -f /tmp/mkw[cmn]$$; exit 1' 1 2 15 for chap in [1 2 3 4 5 6 7 8 9] { ls cat$chap 2>/dev/null >/tmp/mkwc$$ ls man$chap 2>/dev/null >/tmp/mkwm$$ comm -23 /tmp/mkwc$Pid /tmp/mkwm$Pid >/tmp/mkwn$$ sed -e "/.*\\.$chap\$/!d s/\\.$chap\$/ ($chap) - ???/" < /tmp/mkwn$$ } rm -f /tmp/mkw[cmn]$Pid } | do { # Second pass, remove empty lines, leading and trailing spaces, # multiple spaces to one space, remove lines without a dash. sed -e 's/ */ /g s/^ // s/ $// /^$/d /-/!d' } | do { # Third pass, sort by section. sort -t'(' +1 -o whatis }