home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2628 < prev    next >
Encoding:
Internet Message Format  |  1991-01-31  |  2.6 KB

  1. From: de5@ornl.gov (Dave Sill)
  2. Newsgroups: alt.sources,comp.misc,alt.folklore.computers
  3. Subject: Acronym lookup tool
  4. Message-ID: <1991Jan29.194237.12551@cs.utk.edu>
  5. Date: 29 Jan 91 19:42:37 GMT
  6.  
  7. Disclaimer: provided without warranty as a public service.  Use at
  8. your own risk.
  9.  
  10. Send comments/additions to de5@ornl.gov.
  11.  
  12. --8<--cut-here----
  13. #!/bin/sh
  14. #
  15. # NAME
  16. #      whats - lookup acronym/abbreviation in database
  17. #
  18. # SYNOPSIS
  19. #      whats [acronym [defn...]]
  20. #
  21. # DESCRIPTION
  22. #      Whats, without any arguments, prompts for an acronym to look up.
  23. #
  24. #      With one argument, whats prints all entries from the database
  25. #      that match the argument.  If no matches are found, whats
  26. #      prompts for expansion of the acronym or abbreviation.
  27. #
  28. #      With more than one argument, whats scans the database for
  29. #      entries matching the first argument.  If any matches are found,
  30. #      whats prints the matching entries and asks if the remaining
  31. #      arguments should be added as a new entry.  If no matches are
  32. #      found, a new entry is created for the first argument with the
  33. #      remaining arguments forming the expansion.
  34. #
  35. # FILES
  36. #      acron or $ACRON
  37. #
  38. # BUGS/DEFICIENCIES
  39. #      Not blindingly fast.
  40. #      Not tested under System V.  (Uses "echo -n", "grep -i")
  41. #
  42. # AUTHOR
  43. #      Dave Sill (dsill@nswc-oas.arpa) (de5@ornl.gov as of 6/90)
  44. #      Naval Surface Warfare Center (NSWC), Dahlgren, VA
  45. #
  46. n='-n'    # Use '' if your echo uses '\c'
  47. c=''    # Use '\c' if your echo uses it
  48. q='-i'    # Use '' or your grep's "ignore case" flag
  49.  
  50. if [ -z "$1" ]
  51. then
  52.     echo $n "What is what? $c"
  53.     read ac
  54. else
  55.     ac=$1
  56. fi
  57. ac=`echo ${ac} | tr "[a-z]" "[A-Z]"`
  58.  
  59. if [ ! -f acron ]
  60. then
  61.     acron=${ACRON}
  62. else
  63.     acron=acron
  64. fi
  65. i=`grep $q -c "^${ac}    " ${acron}`
  66.  
  67. if [ -z "$2" -a $i -ne 0 ]
  68. then
  69.     # No definition passed and is on file, so just do a lookup.
  70.     grep $q "^${ac}    " ${acron}
  71.     exit
  72. elif [ $i -ne 0 ]
  73. then
  74.     # Is on file and a definition was passed, check before adding.
  75.     echo $i occurrences found.
  76.     grep $q "^${ac}    " ${acron}
  77.     echo $n "Still want to add ${ac}? $c"
  78.     read reply
  79.     if [ "${reply}" = n -o "${reply}" = N ]
  80.     then
  81.     exit
  82.     fi
  83. fi
  84. if [ -z "$2" ]
  85. then
  86.     echo $n "What does ${ac} stand for? $c"
  87.     read def
  88.     if [ -z "${def}" ]
  89.     then
  90.     exit
  91.     fi
  92. else
  93.     shift
  94.     def=$*
  95. fi
  96. echo "${ac}    - ${def}" >>${acron}
  97. echo "${ac}    - ${def}"
  98. --8<--cut-here----
  99.  
  100. --
  101. Dave Sill (de5@ornl.gov)      It will be a great day when our schools have
  102. Martin Marietta Energy Systems    all the money they need and the Air Force
  103. Workstation Support               has to hold a bake sale to buy a new bomber.
  104.