Blob


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