1
0

lookman 730 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/rc
  2. # Usage: lookman key ...
  3. # prints out the names of all manual pages containing all the given keywords
  4. rfork e
  5. index=/sys/lib/man/lookman/index
  6. t1=/tmp/look1.$pid
  7. t2=/tmp/look2.$pid
  8. fn sigexit {
  9. rm -f $t1 $t2
  10. exit
  11. }
  12. fn sigint sighup sigterm {
  13. rm -f $t1 $t2
  14. exit note
  15. }
  16. *=`{echo $*|tr A-Z a-z|tr -dc 'a-z0-9_. \012'} # fold case, delete funny chars
  17. if(~ $#* 0){
  18. echo Usage: lookman key ... >/fd/2
  19. exit usage
  20. }
  21. look $1 $index | sed 's/.* //' | sort -u >$t1
  22. shift
  23. for(i in $*){
  24. look $i $index | sed 's/.* //' | sort -u |
  25. awk 'BEGIN {
  26. while (getline < "'$t1'" > 0)
  27. table[$0] = 1
  28. }
  29. { if (table[$0]) print }
  30. ' > $t2
  31. mv $t2 $t1
  32. }
  33. sort $t1 | sed 's;/sys/man/;;
  34. s;(.*)/(.*);man \1 \2 # \2(\1);'
  35. exit ''