man 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/dis/sh.dis
  2. # Plan 9 man script adaptation for Inferno
  3. # for more details see the real man(1)
  4. load std
  5. fils=()
  6. cmd=n
  7. sec=()
  8. S=/man
  9. d=0
  10. x=$* # see sh(1) for details about s/$*/$x/.
  11. x=`{echo $x|tr A-Z a-z|tr -dc 'a-z0-9_ \012-/'} # fold case, delete funny chars
  12. search=yes
  13. while {~ $d 0}{
  14. #echo d$d search$search cmd$cmd fils$fils: $"x
  15. if {no $x}{
  16. echo 'Usage: man [-bnSwpf] [0-9] [0-9] ... name1 name2 ...'
  17. exit
  18. }
  19. if{ftest -d $S/${hd $x}}{
  20. sec=($sec ${hd $x}); x=${tl $x};
  21. }{
  22. if{~ ${hd $x} '-n'}{
  23. cmd=n; x=${tl $x};
  24. }{~ ${hd $x} '-w'}{
  25. cmd=w; x=${tl $x};
  26. }{~ ${hd $x} '-b'}{
  27. cmd=b; x=${tl $x};
  28. }{~ ${hd $x} '-p'}{
  29. cmd=p; x=${tl $x};
  30. }{~ ${hd $x} '-s'}{
  31. search=no; x=${tl $x};
  32. }{~ ${hd $x} '-f'}{
  33. search=no; x=${tl $x};
  34. if {ftest -f ${hd $x}}{
  35. fils=(${hd $x});
  36. }{
  37. echo 'man: bad option -f '${hd $x}
  38. exit 'no file'
  39. }
  40. }{
  41. d=1;
  42. }
  43. if{no $x}{
  44. d=1;
  45. }
  46. }
  47. }
  48. if{no $sec} {
  49. sec=`{ls -pd $S/[0-9]* }
  50. }
  51. ix=$S/$sec/INDEX
  52. if{~ $#x 1} {pat='^'^$x^' '}
  53. {pat='^('^`{echo $x | sed 's/ /|/g'}^') '}
  54. if{~ $search yes} {
  55. for i in $S/$sec {
  56. if {ftest -f $i/INDEX}{
  57. try=`{grep -i $pat $i/INDEX | sed 's/^[^ ]*//'}
  58. if {! no $try}{
  59. fils=($fils $i/$try)
  60. }
  61. }
  62. }
  63. }
  64. if{no $fils} {
  65. # nothing in INDEX. try for file or given name
  66. for i in $x {
  67. if{~ $i intro} {i=0intro}
  68. for n in $sec {
  69. try=`{echo $S/$n/$i | tr A-Z a-z}
  70. if {ftest -f $try} {
  71. fils=($fils $try)
  72. }
  73. }
  74. }
  75. if{~ $#fils 0} {
  76. echo 'man: no manual page'
  77. exit 'no man'
  78. }
  79. }
  80. for i in $fils {
  81. if {! ftest -f $i}{
  82. echo need:$i
  83. }{
  84. if {~ $cmd n}{
  85. man2txt $i
  86. }{~ $cmd w}{
  87. echo $i
  88. }{~ $cmd p}{
  89. wm/man -f $i
  90. }{~ $cmd b}{
  91. if{~ $i '/man/*/0intro'}{
  92. x=`{echo $i | sed 's;/man/(.*)/.*;\1 intro;'}
  93. }{~ $i '/man/*/*'}{
  94. x=`{echo $i | sed 's;/man/(.*)/(.*);\1 \2;'}
  95. }{
  96. x=($i '')
  97. }
  98. man2txt $i |
  99. plumb -i -d edit -a action showdata -a filename '/man/'^${tl $x}^'('^${hd $x}^')'
  100. }
  101. }
  102. }