wtf.in 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. #
  3. # $NetBSD: wtf,v 1.11 2003/04/25 19:08:31 jmmv Exp $
  4. #
  5. # Public domain
  6. #
  7. usage() {
  8. echo "usage: `basename $0` [-f dbfile] [-t type] [is] <acronym>"
  9. exit 1
  10. }
  11. acronyms=${ACRONYMDB:-@wtf_acronymfile@}
  12. args=`getopt f:t: $*`
  13. if [ $? -ne 0 ]; then
  14. usage
  15. fi
  16. set -- $args
  17. while [ $# -gt 0 ]; do
  18. case "$1" in
  19. -f)
  20. acronyms=$2; shift
  21. ;;
  22. -t)
  23. acronyms=@wtf_acronymfile@.$2; shift
  24. ;;
  25. --)
  26. shift; break
  27. ;;
  28. esac
  29. shift
  30. done
  31. if [ X"$1" = X"is" ] ; then
  32. shift
  33. fi
  34. if [ $# -lt 1 ] ; then
  35. usage
  36. fi
  37. if [ ! -f $acronyms ]; then
  38. echo "`basename $0`: cannot open acronyms database file \`$acronyms'"
  39. exit 1
  40. fi
  41. rv=0
  42. while [ $# -gt 0 ] ; do
  43. target=`echo $1 | tr '[a-z]' '[A-Z]'`
  44. ans=`fgrep $target < $acronyms 2>/dev/null \
  45. | sed -ne "\|^$target[[:space:]]|s|^$target[[:space:]]*||p"`
  46. if [ "$ans" != "" ] ; then
  47. echo "$target: $ans"
  48. else
  49. ans=`whatis $1 2> /dev/null | egrep "^$1[, ]" 2> /dev/null`
  50. if [ $? -eq 0 ] ; then
  51. echo "$1: $ans"
  52. else
  53. echo "Gee... I don't know what $1 means..." 1>&2
  54. rv=1
  55. fi
  56. fi
  57. shift
  58. done
  59. exit $rv