home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Product / Product.zip / ISPSRC.ZIP / fixdict.X < prev    next >
Text File  |  1992-08-14  |  4KB  |  125 lines

  1. : Use /bin/sh
  2. #
  3. # $Id: fixdict.X,v 1.10 91/07/03 18:20:35 geoff Exp $
  4. #
  5. # Copyright 1987, 1988, 1989, by Geoff Kuenning, Manhattan Beach, CA
  6. # Permission for non-profit use is hereby granted.
  7. # All other rights reserved.
  8. # See "version.h" for a more complete copyright notice.
  9. #
  10. # $Log:    fixdict.X,v $
  11. # Revision 1.10  91/07/03  18:20:35  geoff
  12. # Don't use the ":-" notation in defining TMPDIR, since some
  13. # braindamaged Bourne shells don't handle it.
  14. # Revision 1.9  89/04/28  01:07:58  geoff
  15. # Change Header to Id;  nobody cares about my pathnames.
  16. # Revision 1.8  88/12/26  02:24:36  geoff
  17. # Update the copyright notice.
  18. # Revision 1.7  88/02/20  23:10:48  geoff
  19. # Fix the usage of the -e switch to specify standard input properly.
  20. # Remove an unneeded sort.
  21. # Revision 1.6  87/09/24  23:24:03  geoff
  22. # Get rid of colons in the optional-variable setting (Israel Pinkas).
  23. # Revision 1.5  87/09/14  22:38:28  geoff
  24. # Add copyright comments
  25. # Revision 1.4  87/07/20  23:21:16  geoff
  26. # Get rid of the EXPAND stuff;  it's obsolete.  Add DEFHASH and SORTTMP
  27. # support.  Look in the current directory for DEFHASH first.
  28. # Revision 1.3  87/06/07  14:47:22  geoff
  29. # Make LIBDIR auto-configurable
  30. # Revision 1.2  87/05/27  23:16:08  geoff
  31. # Update expand script usage
  32. # Revision 1.1  87/04/19  22:25:04  geoff
  33. # Initial revision
  34. #
  35. #    Add capitalization information to an ispell dictionary
  36. #
  37. #    Usage:
  38. #
  39. #    fixdict dict-file
  40. #
  41. #    Requires availability of UNIX spell.  The new dictionary is
  42. #    rewritten in place.  A list of words that couldn't be
  43. #    resolved (because spell doesn't know them) is written to
  44. #    standard output.  This list appears in lowercase in the
  45. #    dictionary, and if there are any errors the must be edited
  46. #    by hand.
  47. #
  48. #    The final dictionary appears in expanded form and must be
  49. #    passed through munchlist to regenerate suffixes.
  50. #
  51. LIBDIR=!!LIBDIR!!
  52. DEFHASH=!!DEFHASH!!
  53. SORTTMP="-T ${TMPDIR-/usr/tmp}"        # !!SORTTMP!!
  54. TDIR=${TMPDIR-/tmp}
  55. TMP=${TDIR}/fix$$
  56.  
  57. #
  58. #    Figure out where to get the hash file.  The preference is
  59. #    for one in the current directory, if it exists, since this script
  60. #    is intended primarily to be used during installation.
  61. #
  62. DICT="$DEFHASH"
  63. [ -r "$DICT" ]  ||  DICT="$LIBDIR/$DEFHASH"
  64.  
  65. trap "/bin/rm -f ${TMP}*; exit 1" 1 2 15
  66. ispell -e -d $DICT -p /dev/null < $1 \
  67.   | tr '[A-Z]' '[a-z]' \
  68.   | spell > ${TMP}a
  69. #
  70. # ${TMP}a contains all the words that spell doesn't like.
  71. # Now figure out which of those are because spell doesn't know them at
  72. # all, and leave those in ${TMP}b.
  73. #
  74. tr '[a-z]' '[A-Z]' < ${TMP}a | spell | tr '[A-Z]' '[a-z]' > ${TMP}b
  75. #
  76. # The wrongly-capitalized words are those that spell didn't object to
  77. # in the last step.  Produce a list of them in, and capitalize the
  78. # first letter of each.  Save this list in ${TMP}c.
  79. #
  80. comm -23 ${TMP}a ${TMP}b \
  81.   | sed 's/^a/A/;s/^b/B/;s/^c/C/;s/^d/D/;s/^e/E/;s/^f/F/;s/^g/G/;s/^h/H/
  82.      s/^i/I/;s/^j/J/;s/^k/K/;s/^l/L/;s/^m/M/;s/^n/N/;s/^o/O/;s/^p/P/
  83.      s/^q/Q/;s/^r/R/;s/^s/S/;s/^t/T/;s/^u/U/;s/^v/V/;s/^w/W/;s/^x/X/
  84.      s/^y/Y/;s/^z/Z/' > ${TMP}c
  85. #
  86. # Find out which of those spell objects to, saving the failures in ${TMP}d.
  87. #
  88. spell ${TMP}c > ${TMP}d
  89. #
  90. # Extract the words which were correctly capitalized at the first letter,
  91. # combine them with an all-capitals version of the ones that weren't, and
  92. # put the result into ${TMP}e.
  93. #
  94. (comm -23 ${TMP}c ${TMP}d;  tr '[a-z]' '[A-Z]' < ${TMP}d) \
  95.   | sort $SORTTMP -o ${TMP}e
  96. #
  97. # At this point, ${TMP}b contains the words that spell just plain doesn't
  98. # like, and ${TMP}e contains the words that are now capitalized correctly.
  99. #
  100. /bin/rm ${TMP}[cd]
  101. #
  102. # Put it all together, rewriting the dictionary in place.
  103. #
  104. ispell -e -d $DICT -p /dev/null < $1 \
  105.   | tr '[A-Z]' '[a-z]' \
  106.   | sort $SORTTMP \
  107.   | comm -23 - ${TMP}a \
  108.   | sort $SORTTMP -f -o $1 - ${TMP}b ${TMP}e
  109. #
  110. # Finally, write the list of words that have questionable capitalization
  111. # to the standard output.
  112. #
  113. cat ${TMP}b
  114. /bin/rm ${TMP}*
  115.