source: trunk/minix/commands/scripts/makewhatis.sh@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 1.7 KB
Line 
1#!/bin/sh
2#
3# makewhatis 2.0 - make whatis(5) database. Author: Kees J. Bot.
4#
5# Make the whatis database of a man directory from the manual pages.
6
7case $1 in
8-*) set -$- x x
9esac
10
11case $# in
121) ;;
13*) echo "Usage: $0 <mandir>" >&2
14 exit 1
15esac
16
17cd $1 || exit
18
19{
20 # First pass, gathering the .SH NAME lines in various forms.
21
22 # First the man[1-8] directories, the titles are under the .SH NAME
23 # section header.
24 for chap in 1 2 3 4 5 6 7 8
25 do
26 for page in man$chap/*.$chap
27 do
28 if test -f "$page"; then # (Old sh barfs on 'continue')
29
30 sed -e 's/ / /g
31 s/"NAME"/NAME/g
32 /^\.SH NAME/,/^\.SH /!d
33 /^\.SH /d
34 s/\\f.//g # should not be needed
35 s/\\s[+-].//g
36 s/\\s.//g
37 s/\\//
38 '"s/ - / ($chap) - /" < "$page"
39 fi
40 done
41 done
42
43 # The Minix "Book style" documents, look for .CD
44 for page in man9/*.9
45 do
46 if test -f "$page"; then
47
48 sed -e 's/ / /g
49 /^\.CD /!d
50 s/^[^"]*"//
51 s/"[^"]*$//
52 s/\\(en/-/g
53 s/\\f.//g
54 s/\\s[+-].//g
55 s/\\s.//g
56 s/\\\*(M2/MINIX/g
57 s/\\//
58 '"s/ - / (9) - /" < "$page"
59 fi
60 done
61
62 # Some people throw extra flat text files into the cat[1-9]
63 # directories. It would be nice if man(1) can find them.
64 trap 'rm -f /tmp/mkw[cmn]$$; exit 1' 1 2 15
65 for chap in 1 2 3 4 5 6 7 8 9
66 do
67 ls cat$chap 2>/dev/null >/tmp/mkwc$$
68 ls man$chap 2>/dev/null >/tmp/mkwm$$
69 comm -23 /tmp/mkwc$$ /tmp/mkwm$$ >/tmp/mkwn$$
70 sed -e "/.*\\.$chap\$/!d
71 s/\\.$chap\$/ ($chap) - ???/" < /tmp/mkwn$$
72 done
73 rm -f /tmp/mkw[cmn]$$
74} | {
75 # Second pass, remove empty lines, leading and trailing spaces,
76 # multiple spaces to one space, remove lines without a dash.
77 sed -e 's/ */ /g
78 s/^ //
79 s/ $//
80 /^$/d
81 /-/!d'
82} | {
83 # Third pass, sort by section.
84 sort -t'(' +1 -o whatis
85}
Note: See TracBrowser for help on using the repository browser.