1
0

man 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. while(~ $d 0) {
  45. if(~ $#* 0) {
  46. echo 'Usage: man [-ntp] [-s sec] [0-9] [0-9] ... name1 name2 ...' >[1=2]
  47. exit
  48. }
  49. if(test -d $S/$1){
  50. sec=($sec $1)
  51. shift
  52. }
  53. if not switch($1) {
  54. case -t ; cmd=t ; shift
  55. case -n ; cmd=n ; shift
  56. case -p ; cmd=p ; shift
  57. case -P ; cmd=P ; shift
  58. case * ; d=1
  59. }
  60. }
  61. if(~ $#sec 0) {
  62. sec=`{ls -pd $S/[0-9]* }
  63. }
  64. ix=$S/$sec/INDEX
  65. if(~ $#* 1) pat='^'^$1^' '
  66. if not pat='^('^`{echo $* | sed 's/ /|/g'}^') '
  67. fils=()
  68. for(i in $S/$sec){
  69. if(/bin/test -f $i/INDEX){
  70. try=`{grep $pat $i/INDEX | sed 's/^[^ ]* //'}
  71. if(! ~ $#try 0)
  72. fils=($fils $i/$try)
  73. }
  74. }
  75. # bug: should also do following loop if not all pages found
  76. if(~ $#fils 0) {
  77. # nothing in INDEX. try for file of given name
  78. for(i) {
  79. for(n in $sec) {
  80. try=$S/$n/$i
  81. if (/bin/test -f $try)
  82. fils=($fils $try)
  83. }
  84. }
  85. if(~ $#fils 0) {
  86. echo 'man: no manual page' >[1=2]
  87. exit 'no man'
  88. }
  89. }
  90. for(i in $fils) {
  91. if(! /bin/test -f $i)
  92. echo need $i >[1=2]
  93. if not {
  94. switch($cmd) {
  95. case t
  96. roff t $i
  97. case p
  98. roff t $i | proof
  99. case P
  100. roff t $i | page
  101. case n
  102. roff n $i | sed '
  103. ${
  104. /^$/p
  105. }
  106. //N
  107. /^\n$/D'
  108. }
  109. }
  110. }