man 2.0 KB

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