man 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #!/bin/rc
  2. rfork e
  3. . /sys/man/fonts
  4. cmd=n
  5. sec=()
  6. S=/sys/man
  7. d=0
  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. }
  38. fn page {
  39. if(test -d /mnt/wsys/acme)
  40. /bin/page -w
  41. if not
  42. /bin/page
  43. }
  44. search=yes
  45. while(~ $d 0) {
  46. if(~ $#* 0) {
  47. echo 'Usage: man [-bntpPSw] [0-9] [0-9] ... name1 name2 ...' >[1=2]
  48. exit
  49. }
  50. if(test -d $S/$1){
  51. sec=($sec $1)
  52. shift
  53. }
  54. if not switch($1) {
  55. case -t ; cmd=t ; shift
  56. case -n ; cmd=n ; shift
  57. case -p ; cmd=p ; shift
  58. case -P ; cmd=P ; shift
  59. case -w ; cmd=w ; shift
  60. case -b ; cmd=b ; shift
  61. case -S ; search=no ; shift
  62. case * ; d=1
  63. }
  64. }
  65. if(~ $#sec 0) {
  66. sec=`{ls -pd $S/[0-9]* }
  67. }
  68. ix=$S/$sec/INDEX
  69. if(~ $#* 1) pat='^'^$1^' '
  70. if not pat='^('^`{echo $* | sed 's/ /|/g'}^') '
  71. fils=()
  72. if(~ $search yes)
  73. for(i in $S/$sec){
  74. if(/bin/test -f $i/INDEX){
  75. try=`{grep -i $pat $i/INDEX | sed 's/^[^ ]* //'}
  76. if(! ~ $#try 0)
  77. fils=($fils $i/$try)
  78. }
  79. }
  80. # bug: should also do following loop if not all pages found
  81. if(~ $#fils 0) {
  82. # nothing in INDEX. try for file of given name
  83. for(i) {
  84. if(~ $i intro) i=0intro
  85. for(n in $sec) {
  86. try=`{echo $S/$n/$i | tr A-Z a-z}
  87. if (/bin/test -f $try)
  88. fils=($fils $try)
  89. }
  90. }
  91. if(~ $#fils 0) {
  92. echo 'man: no manual page' >[1=2]
  93. exit 'no man'
  94. }
  95. }
  96. for(i in $fils) {
  97. if(! /bin/test -f $i)
  98. echo need $i >[1=2]
  99. if not {
  100. switch($cmd) {
  101. case w
  102. echo $i
  103. case t
  104. roff t $i
  105. case p
  106. roff t $i | proof
  107. case P
  108. roff t $i | page
  109. case n
  110. roff n $i | sed '
  111. ${
  112. /^$/p
  113. }
  114. //N
  115. /^\n$/D'
  116. case b
  117. x=`{echo $i | sed 's;/sys/man/(.*)/(.*);\1 \2;'}
  118. if(~ $x(2) 0intro) x=($x(1) intro)
  119. roff n $i | sed '
  120. ${
  121. /^$/p
  122. }
  123. //N
  124. /^\n$/D' |
  125. plumb -i -d edit -a 'action=showdata filename=/man/'$x(2)^'('$x(1)^')'
  126. }
  127. }
  128. }