Blob


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