tman - plan9port - [fork] Plan 9 from user space
 (HTM) git clone git://src.adamsgaard.dk/plan9port
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       tman (2654B)
       ---
            1 #!/usr/local/plan9/bin/rc
            2 
            3 . 9.rc
            4 . $PLAN9/man/fonts
            5 
            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)
           26 
           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 }
           40 
           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 | 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 }
           66 
           67 #
           68 # parse flags and sections
           69 #
           70 fn usage { echo 'Usage: man [-hnpPtw] [-s sec] [0-9] [0-9] ... [--] name1 name2 ...' >[1=2] }
           71 cmd=donroff
           72 sec=()
           73 S=$PLAN9/man
           74 d=0
           75 while(~ $d 0) {
           76         if(~ $#* 0) {
           77                 usage
           78                 exit 1
           79         }
           80         if(test -d $S/man$1){
           81                 sec=($sec $1)
           82                 shift
           83         }
           84         if not switch($1) {
           85                 case -t ; cmd=dotroff ; shift
           86                 case -n ; cmd=donroff ; shift
           87                 case -p ; cmd=doproof ; shift
           88                 case -P ; cmd=dopage ; shift
           89                 case -w ; cmd=doecho ; shift
           90                 case -h ; cmd=dohtml ; shift
           91                 case -- ; d=1 ; shift
           92                 case -* ; usage ; exit 1
           93                 case * ; d=1
           94         }
           95 }
           96 if(~ $#sec 0) {
           97         sec=`{ls -pd $S/man[0-9]* | sed 's/man//'}
           98 }
           99 
          100 #
          101 # search index
          102 #
          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)
          113                 }
          114         }
          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]*)
          119                 }
          120         }
          121         if(~ $#files 0){
          122                 echo 'man: no manual page' $word >[1=2]
          123                 missing=yes
          124         }
          125         allfiles=($allfiles $files)
          126 }
          127 if(~ $#allfiles 0)
          128         exit 'no man'
          129 # complicated sort order: want 9p.3, 9p-cmdbuf.3, 9pclient.3
          130 allfiles=`{ls $allfiles | sed 's/[.\-]/ &/g;s/\./ &/g' | sort -u | tr -d ' '}
          131 
          132 files=()
          133 for(i in $allfiles){
          134         if(test -f $i)
          135                 files=($files $i)
          136         if not
          137                 echo need $i >[1=2]
          138 }
          139 
          140 #
          141 # format pages
          142 # 
          143 for(i in $files)
          144         $cmd $i
          145