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