source: trunk/third/ispell/subset.X @ 10334

Revision 10334, 6.4 KB checked in by ghudson, 27 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r10333, which included commits to RCS files with non-trunk default branches.
  • Property svn:executable set to *
Line 
1: Use /bin/sh
2#
3# $Id: subset.X,v 1.1.1.1 1997-09-03 21:08:12 ghudson Exp $
4#
5# Copyright 1992, 1993, Geoff Kuenning, Granada Hills, CA
6# All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11#
12# 1. Redistributions of source code must retain the above copyright
13#    notice, this list of conditions and the following disclaimer.
14# 2. Redistributions in binary form must reproduce the above copyright
15#    notice, this list of conditions and the following disclaimer in the
16#    documentation and/or other materials provided with the distribution.
17# 3. All modifications to the source code must be clearly marked as
18#    such.  Binary redistributions based on modified source code
19#    must be clearly marked as modified versions in the documentation
20#    and/or other materials provided with the distribution.
21# 4. All advertising materials mentioning features or use of this software
22#    must display the following acknowledgment:
23#      This product includes software developed by Geoff Kuenning and
24#      other unpaid contributors.
25# 5. The name of Geoff Kuenning may not be used to endorse or promote
26#    products derived from this software without specific prior
27#    written permission.
28#
29# THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND
30# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32# ARE DISCLAIMED.  IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE
33# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39# SUCH DAMAGE.
40#
41#       Combine and resolve various dictionaries so they are proper
42#       subsets of one another, and so that maximal use is made of
43#       flags in the smaller ones.
44#
45#       Usage:
46#
47#       subset [-b base] [-l langfile] small-dict bigger-dict ... biggest-dict
48#
49#       The output is a an equal number of successively-larger
50#       dictionaries.  The smallest is written to "dict.0".  Successive
51#       files are named "dict.1", "dict.2", and so forth, and each contains
52#       a list of words which should be added to the previous files to
53#       generate a dictionary.  Words which are in smaller dictionaries are
54#       effectively propagated to the larger ones, so that the smaller ones
55#       are proper subsets of their siblings.  If dictionaries are
56#       completely disjoint, this may result in an empty output dictionary.
57#       Affix flags are propagated to the smallest dictionary containing
58#       the root word;  this expands the effectiveness of small dictionaries
59#       at no cost in hash table space.
60#
61#       The -b switch is used to specify a different base name for the
62#       output files than "dict".  (In other words, "-b english" would
63#       produce output in english.0, english.1, etc.).
64#
65#       If the -l switch is specified, the language tables are gotten
66#       from the specified file;  otherwise they come from $LIBDIR/!!DEFLANG!!.
67#
68#       Input dictionaries should be "clean";  if non-word characters
69#       appear in the dictionaries, the script may produce incorrect output.
70#
71# $Log: not supported by cvs2svn $
72# Revision 1.15  1995/01/08  23:23:47  geoff
73# Support variable hashfile suffixes for DOS purposes.
74#
75# Revision 1.14  1994/01/25  07:12:10  geoff
76# Get rid of all old RCS log lines in preparation for the 3.1 release.
77#
78#
79LIBDIR=!!LIBDIR!!
80TDIR=${TMPDIR-/usr/tmp}
81TMP=${TDIR}/sset$$.
82SORTTMP="-T ${TDIR}"                    # !!SORTTMP!!
83USAGE="Usage:  subset [-b base] [-l langfile] dict-0 dict-1 ..."
84
85langtabs=${LIBDIR}/!!DEFLANG!!
86outbase=dict
87while :
88do
89    case "$1" in
90        -b)
91            outbase="$2"
92            shift; shift
93            ;;
94        -l)
95            langtabs="$2"
96            shift; shift
97            ;;
98        -*)
99            echo "$USAGE" 1>&2
100            exit 1
101            ;;
102        *)
103            break
104            ;;
105    esac
106done
107
108if [ $# -lt 2 ]
109then
110    echo "$USAGE" 1>&2
111    exit 1
112fi
113
114# Temp files
115MUNCHOUTPUT=${TMP}a
116MISSINGWORDS=${TMP}b
117TEMPDICT=${TMP}c
118FAKEDICT=${TMP}d
119FAKEHASH=${TMP}e!!HASHSUFFIX!!
120
121trap "/bin/rm -f ${TMP}*; exit 1" 1 2 15
122trap "/bin/rm -f ${TMP}*; exit 0" 13
123
124#
125# Create a dummy dictionary to hold a compiled copy of the language
126# tables.
127#
128echo 'QQQQQQQQ' > $FAKEDICT
129buildhash -s $FAKEDICT $langtabs $FAKEHASH \
130  ||  (echo "Couldn't create fake hash file" 1>&2; /bin/rm -f ${TMP}*; exit 1) \
131  ||  exit 1
132/bin/rm -f ${FAKEDICT}*
133#
134# Figure out what the flag-marking character is.
135#
136flagmarker=`ispell -D -d $FAKEHASH \
137  | sed -n '/^flagmarker/s/flagmarker //p'`
138case "$flagmarker" in
139    \\*)
140        flagmarker=`expr "$flagmarker" : '.\(.\)'`
141        ;;
142esac   
143#
144#       (1) Use munchlist to create a list of roots and maximal suffixes.
145#
146munchlist -l $langtabs "$@" | sort $SORTTMP > $MUNCHOUTPUT
147#
148#       (2) Use join to add the maximal suffixes to each dictionary's roots.
149#           Re-expand this, combine with the original, and save for later.
150#
151newline='
152'
153dictno=0
154for dictfile
155do
156    ispell -e -d $FAKEHASH < $dictfile | tr ' ' "$newline" \
157      | sort -u $SORTTMP | join "-t$flagmarker" -a1 - $MUNCHOUTPUT \
158      | ispell -e -d $FAKEHASH | tr ' ' "$newline" \
159      | sort -u $SORTTMP > ${TEMPDICT}.$dictno
160    dictno=`expr $dictno + 1`
161done
162/bin/rm -f $MUNCHOUTPUT
163#
164#       (3) For each adjacent pair of dictionaries, use comm to find words
165#           in the smaller that are missing from the larger, and add them
166#           to the larger.
167#
168firstdict="$1"
169shift
170lastdict="${TEMPDICT}.0"
171dictno=1
172for dictfile
173do
174    comm -23 $lastdict ${TEMPDICT}.$dictno > $MISSINGWORDS.$dictno
175    if [ -s $MISSINGWORDS.$dictno ]
176    then
177        sort $SORTTMP -o ${TEMPDICT}.$dictno \
178          ${TEMPDICT}.$dictno $MISSINGWORDS.$dictno
179    fi
180    lastdict="${TEMPDICT}.$dictno"
181    dictno=`expr $dictno + 1`
182done
183/bin/rm -f $MISSINGWORDS.*
184#
185#       (4) For each pair of dictionaries, use comm to eliminate words in
186#           the smaller from the larger, and shrink the result with munchlist.
187#           From this point out, we ignore interrupts.
188#
189munchlist ${TEMPDICT}.0 > $outbase.0
190lastdict="${TEMPDICT}.0"
191dictno=1
192trap "" 1 2 13 15
193for dictfile
194do
195    comm -13 $lastdict ${TEMPDICT}.$dictno \
196      | munchlist -l $langtabs > $outbase.$dictno
197    /bin/rm -f $lastdict
198    lastdict="${TEMPDICT}.$dictno"
199    dictno=`expr $dictno + 1`
200done
201/bin/rm -f ${TMP}*
Note: See TracBrowser for help on using the repository browser.