lookman 687 B

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