1
0

man 2.6 KB

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