man 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/bin/rc
  2. # man - print manual pages
  3. rfork e
  4. . /sys/man/fonts
  5. cmd=n
  6. sec=()
  7. S=/sys/man
  8. d=0
  9. fn roff {
  10. preproc=()
  11. postproc=cat
  12. x=`{doctype $2}
  13. if (~ $1 t) {
  14. if(~ $x *grap*)
  15. preproc=($preproc grap)
  16. if(~ $x *pic*)
  17. preproc=($preproc pic)
  18. Nflag=-Tutf
  19. }
  20. if not {
  21. Nflag=-N
  22. if (grep -s '^\.2C' $2)
  23. postproc=col
  24. }
  25. if(~ $x *eqn*)
  26. preproc=($preproc eqn)
  27. if(~ $x *tbl*)
  28. preproc=($preproc tbl)
  29. {echo -n $FONTS; cat $2 </dev/null} |
  30. switch($#preproc) {
  31. case 0
  32. troff $Nflag -$MAN
  33. case 1
  34. $preproc | troff $Nflag -$MAN
  35. case 2
  36. $preproc(1) | $preproc(2) | troff $Nflag -$MAN
  37. case 3
  38. $preproc(1) | $preproc(2) | $preproc(3) |
  39. troff $Nflag -$MAN
  40. case *
  41. $preproc(1) | $preproc(2) | $preproc(3) |
  42. $preproc(4) | troff $Nflag -$MAN
  43. } | $postproc
  44. }
  45. fn page {
  46. if(test -d /mnt/wsys/acme)
  47. /bin/page -w
  48. if not
  49. /bin/page
  50. }
  51. search=yes
  52. while(~ $d 0) {
  53. if(~ $#* 0) {
  54. echo 'Usage: man [-bntpPSw] [0-9] [0-9] ... name1 name2 ...' >[1=2]
  55. exit
  56. }
  57. if(test -d $S/$1){
  58. sec=($sec $1)
  59. shift
  60. }
  61. if not
  62. switch($1) {
  63. case -t ; cmd=t ; shift
  64. case -n ; cmd=n ; shift
  65. case -p ; cmd=p ; shift
  66. case -P ; cmd=P ; shift
  67. case -w ; cmd=w ; shift
  68. case -b ; cmd=b ; shift
  69. case -S ; search=no ; shift
  70. case * ; d=1
  71. }
  72. }
  73. if(~ $#sec 0) {
  74. sec=`{ls -pd $S/[0-9]* }
  75. }
  76. ix=$S/$sec/INDEX
  77. if(~ $#* 1) pat='^'^$1^' '
  78. if not pat='^('^`{echo $* | sed 's/ /|/g'}^') '
  79. fils=()
  80. if(~ $search yes)
  81. for(i in $S/$sec){
  82. if(/bin/test -f $i/INDEX){
  83. try=`{grep -i $pat $i/INDEX | sed 's/^[^ ]* //' | sort -u}
  84. if(! ~ $#try 0)
  85. fils=($fils $i/$try)
  86. }
  87. }
  88. # bug: should also do following loop if not all pages found
  89. if(~ $#fils 0) {
  90. # nothing in INDEX. try for file of given name
  91. for(i) {
  92. if(~ $i intro) i=0intro
  93. for(n in $sec) {
  94. try=`{echo $S/$n/$i | tr A-Z a-z}
  95. if (/bin/test -f $try)
  96. fils=($fils $try)
  97. }
  98. }
  99. if(~ $#fils 0) {
  100. echo 'man: no manual page' >[1=2]
  101. exit 'no man'
  102. }
  103. }
  104. for(i in $fils) {
  105. if(! /bin/test -f $i)
  106. echo need $i >[1=2]
  107. if not {
  108. switch($cmd) {
  109. case w
  110. echo $i
  111. case t
  112. roff t $i
  113. case p
  114. roff t $i | grep -v '^x X html' | proof
  115. case P
  116. roff t $i | page
  117. case n
  118. roff n $i | sed '
  119. ${
  120. /^$/p
  121. }
  122. //N
  123. /^\n$/D'
  124. case b
  125. x=`{echo $i | sed 's;/sys/man/(.*)/(.*);\1 \2;'}
  126. if(~ $x(2) 0intro) x=($x(1) intro)
  127. roff n $i | sed '
  128. ${
  129. /^$/p
  130. }
  131. //N
  132. /^\n$/D' |
  133. plumb -i -d edit -a 'action=showdata filename=/man/'$x(2)^'('$x(1)^')'
  134. }
  135. }
  136. }