Blob


1 #!/usr/local/plan9/bin/rc
3 . 9.rc
4 whatis path
5 whatis troff
6 . $PLAN9/man/fonts
8 #
9 # formatters
10 #
11 fn roff {
12 preproc=()
13 x=`{doctype $2}
14 if (~ $1 t) {
15 if(~ $x *grap*)
16 preproc=($preproc grap)
17 if(~ $x *pic*)
18 preproc=($preproc pic)
19 Nflag=-Tutf
20 }
21 if not {
22 Nflag=-N
23 }
24 if(~ $x *eqn*)
25 preproc=($preproc eqn)
26 if(~ $x *tbl*)
27 preproc=($preproc tbl)
29 switch($#preproc) {
30 case 0
31 {echo -n $FONTS; cat $2< /dev/null} | troff $Nflag -$MAN
32 case 1
33 {echo -n $FONTS; cat $2< /dev/null} | $preproc | troff $Nflag -$MAN
34 case 2
35 {echo -n $FONTS; cat $2< /dev/null} | $preproc(1) | $preproc(2) | troff $Nflag -$MAN
36 case 3
37 {echo -n $FONTS; cat $2< /dev/null} | $preproc(1) | $preproc(2) | $preproc(3) | | troff $Nflag -$MAN
38 case *
39 {echo -n $FONTS; cat $2< /dev/null} | $preproc(1) | $preproc(2) | $preproc(3) | | $preproc(4) | troff $Nflag -$MAN
40 }
41 }
43 fn doecho { echo $1 }
44 fn dotroff { roff t $1 }
45 fn doproof { roff t $1 | proof }
46 fn dopage { roff t $1 | tr2post | psfonts | page }
47 fn donroff {
48 roff n $1 | sed '
49 ${
50 /^$/p
51 }
52 //N
53 /^\n$/D
54 '
55 }
56 seq=0
57 fn dohtml {
58 MAN=manhtml
59 b=`{echo $1 | sed 's/\.[0-9].*//'}
60 if(test -f $b.html)
61 web $b.html
62 if not{
63 roff t $1 | troff2html >/tmp/man.$pid.$seq.html
64 web /tmp/man.$pid.$seq.html
65 seq=`{echo 1+$seq | hoc}
66 }
67 }
69 #
70 # parse flags and sections
71 #
72 cmd=donroff
73 sec=()
74 S=$PLAN9/man
75 d=0
76 while(~ $d 0) {
77 if(~ $#* 0) {
78 echo 'Usage: man [-ntp] [-s sec] [0-9] [0-9] ... name1 name2 ...' >[1=2]
79 exit
80 }
81 if(test -d $S/man$1){
82 sec=($sec $1)
83 shift
84 }
85 if not switch($1) {
86 case -t ; fmt=dotroff ; shift
87 case -n ; cmd=donroff ; shift
88 case -p ; cmd=doproof ; shift
89 case -P ; cmd=dopage ; shift
90 case -w ; cmd=doecho ; shift
91 case -h ; cmd=dohtml ; shift
92 case -- ; d=1 ; shift
93 case * ; d=1
94 }
95 }
96 if(~ $#sec 0) {
97 sec=`{ls -pd $S/man[0-9]* | sed 's/man//'}
98 }
101 # search index
103 allfiles=()
104 missing=no
105 for(word){
106 files=()
107 regexp='^'^$word^' '
108 for(i in $S/man$sec){
109 if(test -f $i/INDEX){
110 try=`{grep $regexp $i/INDEX | sed 's/^[^ ]* //'}
111 if(! ~ $#try 0)
112 files=($files $i/$try)
115 if(~ $#files 0){
116 for(i in $S/man$sec){
117 if(test -f $i/$word.[0-9]*)
118 files=($files $i/$word.[0-9]*)
121 if(~ $#files 0){
122 echo 'man: no manual page' $word >[1=2]
123 missing=yes
125 allfiles=($allfiles $files)
127 if(~ $#allfiles 0)
128 exit 'no man'
129 allfiles=`{ls $allfiles | sort -u >[2]/dev/null}
131 files=()
132 for(i in $allfiles){
133 if(test -f $i)
134 files=($files $i)
135 if not
136 echo need $i >[1=2]
140 # format pages
142 for(i in $files)
143 $cmd $i