man 2.6 KB

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