1 | #ifndef lint |
---|
2 | static char Rcs_Id[] = |
---|
3 | "$Id: icombine.c,v 1.1.1.1 1997-09-03 21:08:08 ghudson Exp $"; |
---|
4 | #endif |
---|
5 | |
---|
6 | #define MAIN |
---|
7 | |
---|
8 | /* |
---|
9 | * icombine: combine multiple ispell dictionary entries into a single |
---|
10 | * entry with the options of all entries |
---|
11 | * |
---|
12 | * The original version of this program was written by Gary Puckering at |
---|
13 | * Cognos, Inc. The current version is a complete replacement, created by |
---|
14 | * reducing Pace Willisson's buildhash program. By using routines common |
---|
15 | * to buildhash and ispell, we can be sure that the rules for combining |
---|
16 | * capitalizations are compatible. |
---|
17 | * |
---|
18 | * Copyright 1992, 1993, Geoff Kuenning, Granada Hills, CA |
---|
19 | * All rights reserved. |
---|
20 | * |
---|
21 | * Redistribution and use in source and binary forms, with or without |
---|
22 | * modification, are permitted provided that the following conditions |
---|
23 | * are met: |
---|
24 | * |
---|
25 | * 1. Redistributions of source code must retain the above copyright |
---|
26 | * notice, this list of conditions and the following disclaimer. |
---|
27 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
28 | * notice, this list of conditions and the following disclaimer in the |
---|
29 | * documentation and/or other materials provided with the distribution. |
---|
30 | * 3. All modifications to the source code must be clearly marked as |
---|
31 | * such. Binary redistributions based on modified source code |
---|
32 | * must be clearly marked as modified versions in the documentation |
---|
33 | * and/or other materials provided with the distribution. |
---|
34 | * 4. All advertising materials mentioning features or use of this software |
---|
35 | * must display the following acknowledgment: |
---|
36 | * This product includes software developed by Geoff Kuenning and |
---|
37 | * other unpaid contributors. |
---|
38 | * 5. The name of Geoff Kuenning may not be used to endorse or promote |
---|
39 | * products derived from this software without specific prior |
---|
40 | * written permission. |
---|
41 | * |
---|
42 | * THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND |
---|
43 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
44 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
45 | * ARE DISCLAIMED. IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE |
---|
46 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
47 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
48 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
49 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
50 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
51 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
52 | * SUCH DAMAGE. |
---|
53 | */ |
---|
54 | |
---|
55 | /* |
---|
56 | * $Log: not supported by cvs2svn $ |
---|
57 | * Revision 2.24 1994/01/25 07:11:35 geoff |
---|
58 | * Get rid of all old RCS log lines in preparation for the 3.1 release. |
---|
59 | * |
---|
60 | */ |
---|
61 | |
---|
62 | #include <ctype.h> |
---|
63 | #include "config.h" |
---|
64 | #include "ispell.h" |
---|
65 | #include "proto.h" |
---|
66 | #include "msgs.h" |
---|
67 | |
---|
68 | char * Lfile; /* Language-description file */ |
---|
69 | |
---|
70 | int main P ((int argc, char * argv[])); |
---|
71 | static void usage P ((void)); |
---|
72 | VOID * mymalloc P ((unsigned int size)); |
---|
73 | VOID * myrealloc P ((VOID * ptr, unsigned int size, |
---|
74 | unsigned int oldsize)); |
---|
75 | void myfree P ((VOID * ptr)); |
---|
76 | static void combinedict P ((void)); |
---|
77 | static void combineout P ((void)); |
---|
78 | |
---|
79 | int main (argc, argv) |
---|
80 | int argc; |
---|
81 | char * argv[]; |
---|
82 | { |
---|
83 | char * argp; |
---|
84 | char * preftype = NULL; |
---|
85 | |
---|
86 | while (argc > 1 && argv[1][0] == '-') |
---|
87 | { |
---|
88 | argc--; |
---|
89 | argv++; |
---|
90 | switch (argv[0][1]) |
---|
91 | { |
---|
92 | case 'T': |
---|
93 | argp = (*argv)+2; |
---|
94 | if (*argp == '\0') |
---|
95 | { |
---|
96 | argv++; argc--; |
---|
97 | if (argc == 0) |
---|
98 | usage (); |
---|
99 | argp = *argv; |
---|
100 | } |
---|
101 | preftype = argp; |
---|
102 | break; |
---|
103 | default: |
---|
104 | usage (); |
---|
105 | break; |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | if (argc > 1) /* Figure out what language to use */ |
---|
110 | Lfile = argv[1]; |
---|
111 | else |
---|
112 | Lfile = DEFLANG; |
---|
113 | |
---|
114 | if (yyopen (Lfile)) /* Open the language file */ |
---|
115 | return 1; |
---|
116 | yyinit (); /* Set up for the parse */ |
---|
117 | if (yyparse ()) /* Parse the language tables */ |
---|
118 | exit (1); |
---|
119 | |
---|
120 | if (preftype != NULL) |
---|
121 | { |
---|
122 | defdupchar = findfiletype (preftype, 1, (int *) NULL); |
---|
123 | if (defdupchar < 0 |
---|
124 | && strcmp (preftype, "tex") != 0 |
---|
125 | && strcmp (preftype, "nroff") != 0) |
---|
126 | { |
---|
127 | (void) fprintf (stderr, ICOMBINE_C_BAD_TYPE, preftype); |
---|
128 | exit (1); |
---|
129 | } |
---|
130 | } |
---|
131 | if (defdupchar < 0) |
---|
132 | defdupchar = 0; |
---|
133 | |
---|
134 | combinedict (); /* Combine words */ |
---|
135 | |
---|
136 | return 0; |
---|
137 | } |
---|
138 | |
---|
139 | static void usage () |
---|
140 | { |
---|
141 | |
---|
142 | (void) fprintf (stderr, ICOMBINE_C_USAGE); |
---|
143 | exit (1); |
---|
144 | } |
---|
145 | |
---|
146 | VOID * mymalloc (size) |
---|
147 | unsigned int size; |
---|
148 | { |
---|
149 | return malloc (size); |
---|
150 | } |
---|
151 | |
---|
152 | /* ARGSUSED */ |
---|
153 | VOID * myrealloc (ptr, size, oldsize) |
---|
154 | VOID * ptr; |
---|
155 | unsigned int size; |
---|
156 | unsigned int oldsize; |
---|
157 | { |
---|
158 | |
---|
159 | return realloc (ptr, size); |
---|
160 | } |
---|
161 | |
---|
162 | void myfree (ptr) |
---|
163 | VOID * ptr; |
---|
164 | { |
---|
165 | free (ptr); |
---|
166 | } |
---|
167 | |
---|
168 | static void combinedict () |
---|
169 | { |
---|
170 | struct dent d; |
---|
171 | register struct dent * dp; |
---|
172 | char lbuf[INPUTWORDLEN + MAXAFFIXLEN + 2 * MASKBITS]; |
---|
173 | ichar_t ucbuf[INPUTWORDLEN + MAXAFFIXLEN + 2 * MASKBITS]; |
---|
174 | ichar_t lastbuf[INPUTWORDLEN + MAXAFFIXLEN + 2 * MASKBITS]; |
---|
175 | |
---|
176 | lastbuf[0] = '\0'; |
---|
177 | hashtbl = (struct dent *) mymalloc (sizeof (struct dent)); |
---|
178 | hashtbl->flagfield = 0; |
---|
179 | hashtbl->word = 0; |
---|
180 | while (fgets (lbuf, sizeof lbuf, stdin) != NULL) |
---|
181 | { |
---|
182 | if (ichartostr (lbuf, strtosichar (lbuf, 0), sizeof lbuf, 1)) |
---|
183 | (void) fprintf (stderr, WORD_TOO_LONG (lbuf)); |
---|
184 | if (makedent (ichartosstr (strtosichar (lbuf, 0), 1), |
---|
185 | ICHARTOSSTR_SIZE, &d) |
---|
186 | < 0) |
---|
187 | continue; |
---|
188 | |
---|
189 | if (strtoichar (ucbuf, d.word, sizeof ucbuf, 1)) |
---|
190 | (void) fprintf (stderr, WORD_TOO_LONG (lbuf)); |
---|
191 | upcase (ucbuf); |
---|
192 | if (icharcmp (ucbuf, lastbuf) != 0) |
---|
193 | { |
---|
194 | /* |
---|
195 | ** We have a new word. Put the old one out. |
---|
196 | */ |
---|
197 | combineout (); |
---|
198 | (void) icharcpy (lastbuf, ucbuf); |
---|
199 | } |
---|
200 | |
---|
201 | dp = hashtbl; |
---|
202 | if ((dp->flagfield & USED) == 0) |
---|
203 | { |
---|
204 | *dp = d; |
---|
205 | #ifndef NO_CAPITALIZATION_SUPPORT |
---|
206 | /* |
---|
207 | ** If it's a followcase word, we need to make this a |
---|
208 | ** special dummy entry, and add a second with the |
---|
209 | ** correct capitalization. |
---|
210 | */ |
---|
211 | if (captype (d.flagfield) == FOLLOWCASE) |
---|
212 | { |
---|
213 | if (addvheader (dp)) |
---|
214 | exit (1); |
---|
215 | } |
---|
216 | #endif |
---|
217 | } |
---|
218 | else |
---|
219 | { |
---|
220 | /* |
---|
221 | ** A different capitalization is already in |
---|
222 | ** the dictionary. Combine capitalizations. |
---|
223 | */ |
---|
224 | if (combinecaps (dp, &d) < 0) |
---|
225 | exit (1); |
---|
226 | } |
---|
227 | } |
---|
228 | combineout (); |
---|
229 | } |
---|
230 | |
---|
231 | static void combineout () |
---|
232 | { |
---|
233 | register struct dent * ndp; |
---|
234 | register struct dent * tdp; |
---|
235 | |
---|
236 | /* |
---|
237 | ** Put out the dictionary entry on stdout in text format, |
---|
238 | ** freeing it as we go. |
---|
239 | **/ |
---|
240 | if (hashtbl->flagfield & USED) |
---|
241 | { |
---|
242 | for (tdp = hashtbl; tdp != NULL; tdp = ndp) |
---|
243 | { |
---|
244 | toutent (stdout, tdp, 0); |
---|
245 | myfree (tdp->word); |
---|
246 | ndp = tdp->next; |
---|
247 | #ifndef NO_CAPITALIZATION_SUPPORT |
---|
248 | while (tdp->flagfield & MOREVARIANTS) |
---|
249 | { |
---|
250 | if (tdp != hashtbl) |
---|
251 | myfree ((char *) tdp); |
---|
252 | tdp = ndp; |
---|
253 | if (tdp->word) |
---|
254 | myfree (tdp->word); |
---|
255 | ndp = tdp->next; |
---|
256 | } |
---|
257 | #endif |
---|
258 | if (tdp != hashtbl) |
---|
259 | myfree ((char *) tdp); |
---|
260 | } |
---|
261 | } |
---|
262 | hashtbl->flagfield = 0; |
---|
263 | hashtbl->word = NULL; |
---|
264 | } |
---|