123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- #!/bin/rc
- rfork e
- . /sys/man/fonts
- cmd=n
- sec=()
- S=/sys/man
- d=0
- fn roff {
- preproc=()
- x=`{doctype $2}
- if (~ $1 t) {
- if(~ $x *grap*)
- preproc=($preproc grap)
- if(~ $x *pic*)
- preproc=($preproc pic)
- Nflag=-Tutf
- }
- if not {
- Nflag=-N
- }
- if(~ $x *eqn*)
- preproc=($preproc eqn)
- if(~ $x *tbl*)
- preproc=($preproc tbl)
- switch($#preproc) {
- case 0
- {echo -n $FONTS; cat $2< /dev/null} | troff $Nflag -$MAN
- case 1
- {echo -n $FONTS; cat $2< /dev/null} | $preproc | troff $Nflag -$MAN
- case 2
- {echo -n $FONTS; cat $2< /dev/null} | $preproc(1) | $preproc(2) | troff $Nflag -$MAN
- case 3
- {echo -n $FONTS; cat $2< /dev/null} | $preproc(1) | $preproc(2) | $preproc(3) | | troff $Nflag -$MAN
- case *
- {echo -n $FONTS; cat $2< /dev/null} | $preproc(1) | $preproc(2) | $preproc(3) | | $preproc(4) | troff $Nflag -$MAN
- }
- }
- fn page {
- if(test -d /mnt/wsys/acme)
- /bin/page -w
- if not
- /bin/page
- }
- while(~ $d 0) {
- if(~ $#* 0) {
- echo 'Usage: man [-ntp] [-s sec] [0-9] [0-9] ... name1 name2 ...' >[1=2]
- exit
- }
- if(test -d $S/$1){
- sec=($sec $1)
- shift
- }
- if not switch($1) {
- case -t ; cmd=t ; shift
- case -n ; cmd=n ; shift
- case -p ; cmd=p ; shift
- case -P ; cmd=P ; shift
- case * ; d=1
- }
- }
- if(~ $#sec 0) {
- sec=`{ls -pd $S/[0-9]* }
- }
- ix=$S/$sec/INDEX
- if(~ $#* 1) pat='^'^$1^' '
- if not pat='^('^`{echo $* | sed 's/ /|/g'}^') '
- fils=()
- for(i in $S/$sec){
- if(/bin/test -f $i/INDEX){
- try=`{grep $pat $i/INDEX | sed 's/^[^ ]* //'}
- if(! ~ $#try 0)
- fils=($fils $i/$try)
- }
- }
- # bug: should also do following loop if not all pages found
- if(~ $#fils 0) {
- # nothing in INDEX. try for file of given name
- for(i) {
- for(n in $sec) {
- try=$S/$n/$i
- if (/bin/test -f $try)
- fils=($fils $try)
- }
- }
- if(~ $#fils 0) {
- echo 'man: no manual page' >[1=2]
- exit 'no man'
- }
- }
- for(i in $fils) {
- if(! /bin/test -f $i)
- echo need $i >[1=2]
- if not {
- switch($cmd) {
- case t
- roff t $i
- case p
- roff t $i | proof
- case P
- roff t $i | page
- case n
- roff n $i | sed '
- ${
- /^$/p
- }
- //N
- /^\n$/D'
- }
- }
- }
|