• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdespell2
 

tdespell2

  • tdespell2
  • plugins
  • ispell
lookup.cpp
1/* tdespell2 - adopted from enchant
2 * Copyright (C) 2003 Dom Lachowicz
3 * Copyright (C) 2004 Zack Rusin <zack@kde.org>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 * In addition, as a special exception, Dom Lachowicz
21 * gives permission to link the code of this program with
22 * non-LGPL Spelling Provider libraries (eg: a MSFT Office
23 * spell checker backend) and distribute linked combinations including
24 * the two. You must obey the GNU General Public License in all
25 * respects for all of the code used other than said providers. If you modify
26 * this file, you may extend this exception to your version of the
27 * file, but you are not obligated to do so. If you do not wish to
28 * do so, delete this exception statement from your version.
29 */
30
31/*
32 * lookup.c - see if a word appears in the dictionary
33 *
34 * Pace Willisson, 1983
35 *
36 * Copyright 1987, 1988, 1989, 1992, 1993, Geoff Kuenning, Granada Hills, CA
37 * All rights reserved.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 *
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All modifications to the source code must be clearly marked as
49 * such. Binary redistributions based on modified source code
50 * must be clearly marked as modified versions in the documentation
51 * and/or other materials provided with the distribution.
52 * 4. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgment:
54 * This product includes software developed by Geoff Kuenning and
55 * other unpaid contributors.
56 * 5. The name of Geoff Kuenning may not be used to endorse or promote
57 * products derived from this software without specific prior
58 * written permission.
59 *
60 * THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND
61 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63 * ARE DISCLAIMED. IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE
64 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 * SUCH DAMAGE.
71 */
72
73/*
74 * $Log$
75 * Revision 1.1 2004/01/31 16:44:12 zrusin
76 * ISpell plugin.
77 *
78 * Revision 1.7 2003/09/25 02:44:48 dom
79 * bug 5813
80 *
81 * Revision 1.6 2003/08/26 13:20:40 dom
82 * ispell crasher fix, implement enchant_dictionary_release
83 *
84 * Revision 1.5 2003/08/26 13:08:03 uwog
85 * Fix segfault when the requested dictionary couldn't be found.
86 *
87 * Revision 1.4 2003/08/14 16:27:36 dom
88 * update some documentation
89 *
90 * Revision 1.3 2003/07/28 20:40:27 dom
91 * fix up the license clause, further win32-registry proof some directory getting functions
92 *
93 * Revision 1.2 2003/07/16 22:52:47 dom
94 * LGPL + exception license
95 *
96 * Revision 1.1 2003/07/15 01:15:07 dom
97 * ispell enchant backend
98 *
99 * Revision 1.3 2003/01/29 05:50:12 hippietrail
100 *
101 * Fixed my mess in EncodingManager.
102 * Changed many C casts to C++ casts.
103 *
104 * Revision 1.2 2003/01/25 03:16:05 hippietrail
105 *
106 * An UT_ICONV_INVALID fix which escaped the last commit.
107 *
108 * Revision 1.1 2003/01/24 05:52:34 hippietrail
109 *
110 * Refactored ispell code. Old ispell global variables had been put into
111 * an allocated structure, a pointer to which was passed to many functions.
112 * I have now made all such functions and variables private members of the
113 * ISpellChecker class. It was C OO, now it's C++ OO.
114 *
115 * I've fixed the makefiles and tested compilation but am unable to test
116 * operation. Please back out my changes if they cause problems which
117 * are not obvious or easy to fix.
118 *
119 * Revision 1.12 2003/01/06 18:48:39 dom
120 * ispell cleanup, start of using new 'add' save features
121 *
122 * Revision 1.11 2002/09/19 05:31:17 hippietrail
123 *
124 * More Ispell cleanup. Conditional globals and DEREF macros are removed.
125 * K&R function declarations removed, converted to Doxygen style comments
126 * where possible. No code has been changed (I hope). Compiles for me but
127 * unable to test.
128 *
129 * Revision 1.10 2002/09/17 03:03:30 hippietrail
130 *
131 * After seeking permission on the developer list I've reformatted all the
132 * spelling source which seemed to have parts which used 2, 3, 4, and 8
133 * spaces for tabs. It should all look good with our standard 4-space
134 * tabs now.
135 * I've concentrated just on indentation in the actual code. More prettying
136 * could be done.
137 * * NO code changes were made *
138 *
139 * Revision 1.9 2002/09/13 17:20:13 mpritchett
140 * Fix more warnings for Linux build
141 *
142 * Revision 1.8 2002/05/03 09:49:43 fjfranklin
143 * o hash downloader update (Gabriel Gerhardsson)
144 * - Comment out the "Can't open <dictionary>" printf.
145 * - Make the progressbar more clean at the begining of the download.
146 * - Add support for tarballs that doesn't have the full path included
147 * - Fix copyright headers on the newly added files (*HashDownloader.*)
148 *
149 * Revision 1.7 2001/08/27 19:06:30 dom
150 * Lots of compilation fixes
151 *
152 * Revision 1.6 2001/08/10 18:32:40 dom
153 * Spelling and iconv updates. god, i hate iconv
154 *
155 * Revision 1.5 2001/08/10 09:57:49 hub
156 * Patch by sobomax@FreeBSD.org
157 * #include "iconv.h" directive is missed from src/other/spell/xp/lookup.c and
158 * src/wp/impexp/xp/ie_imp_RTF.cpp.
159 * See bug 1823
160 *
161 * Revision 1.4 2001/07/18 17:46:01 dom
162 * Module changes, and fix compiler warnings
163 *
164 * Revision 1.3 2001/06/12 21:32:49 dom
165 * More ispell work...
166 *
167 * Revision 1.2 2001/05/12 16:05:42 thomasf
168 * Big pseudo changes to ispell to make it pass around a structure rather
169 * than rely on all sorts of gloabals willy nilly here and there. Also
170 * fixed our spelling class to work with accepting suggestions once more.
171 * This code is dirty, gross and ugly (not to mention still not supporting
172 * multiple hash sized just yet) but it works on my machine and will no
173 * doubt break other machines.
174 *
175 * Revision 1.1 2001/04/15 16:01:24 tomas_f
176 * moving to spell/xp
177 *
178 * Revision 1.7 1999/09/29 23:33:32 justin
179 * Updates to the underlying ispell-based code to support suggested corrections.
180 *
181 * Revision 1.6 1999/04/13 17:12:51 jeff
182 * Applied "Darren O. Benham" <gecko@benham.net> spell check changes.
183 * Fixed crash on Win32 with the new code.
184 *
185 * Revision 1.5 1999/01/07 01:07:48 paul
186 * Fixed spell leaks.
187 *
188 * Revision 1.5 1999/01/07 01:07:48 paul
189 * Fixed spell leaks.
190 *
191 * Revision 1.4 1998/12/29 14:55:33 eric
192 *
193 * I've doctored the ispell code pretty extensively here. It is now
194 * warning-free on Win32. It also *works* on Win32 now, since I
195 * replaced all the I/O calls with ANSI standard ones.
196 *
197 * Revision 1.3 1998/12/28 23:11:30 eric
198 *
199 * modified spell code and integration to build on Windows.
200 * This is still a hack.
201 *
202 * Actually, it doesn't yet WORK on Windows. It just builds.
203 * SpellCheckInit is failing for some reason.
204 *
205 * Revision 1.2 1998/12/28 22:16:22 eric
206 *
207 * These changes begin to incorporate the spell checker into AbiWord. Most
208 * of this is a hack.
209 *
210 * 1. added other/spell to the -I list in config/abi_defs
211 * 2. replaced other/spell/Makefile with one which is more like
212 * our build system.
213 * 3. added other/spell to other/Makefile so that the build will now
214 * dive down and build the spell check library.
215 * 4. added the AbiSpell library to the Makefiles in wp/main
216 * 5. added a call to SpellCheckInit in wp/main/unix/UnixMain.cpp.
217 * This call is a HACK and should be replaced with something
218 * proper later.
219 * 6. added code to fv_View.cpp as follows:
220 * whenever you double-click on a word, the spell checker
221 * verifies that word and prints its status to stdout.
222 *
223 * Caveats:
224 * 1. This will break the Windows build. I'm going to work on fixing it
225 * now.
226 * 2. This only works if your dictionary is in /usr/lib/ispell/american.hash.
227 * The dictionary location is currently hard-coded. This will be
228 * fixed as well.
229 *
230 * Anyway, such as it is, it works.
231 *
232 * Revision 1.1 1998/12/28 18:04:43 davet
233 * Spell checker code stripped from ispell. At this point, there are
234 * two external routines... the Init routine, and a check-a-word routine
235 * which returns a boolean value, and takes a 16 bit char string.
236 * The code resembles the ispell code as much as possible still.
237 *
238 * Revision 1.42 1995/01/08 23:23:42 geoff
239 * Support MSDOS_BINARY_OPEN when opening the hash file to read it in.
240 *
241 * Revision 1.41 1994/01/25 07:11:51 geoff
242 * Get rid of all old RCS log lines in preparation for the 3.1 release.
243 *
244 */
245
246#include <stdlib.h>
247#include <string.h>
248#include <ctype.h>
249
250#include "ispell_checker.h"
251#include "msgs.h"
252
253#ifdef INDEXDUMP
254static void dumpindex P ((struct flagptr * indexp, int depth));
255#endif /* INDEXDUMP */
256
257int gnMaskBits = 64;
258
264int ISpellChecker::linit (char *hashname)
265{
266 FILE* fpHash;
267
268 int i;
269 struct dent * dp;
270 struct flagent * entry;
271 struct flagptr * ind;
272 int nextchar, x;
273 int viazero;
274 ichar_t * cp;
275
276 if ((fpHash = fopen (hashname, "rb")) == NULL)
277 {
278 return (-1);
279 }
280
281 m_hashsize = fread (reinterpret_cast<char *>(&m_hashheader), 1, sizeof m_hashheader, fpHash);
282 if (m_hashsize < static_cast<int>(sizeof(m_hashheader)))
283 {
284 if (m_hashsize < 0)
285 fprintf (stderr, LOOKUP_C_CANT_READ, hashname);
286 else if (m_hashsize == 0)
287 fprintf (stderr, LOOKUP_C_NULL_HASH, hashname);
288 else
289 fprintf (stderr,
290 LOOKUP_C_SHORT_HASH (m_hashname, m_hashsize,
291 static_cast<int>(sizeof m_hashheader)));
292 return (-1);
293 }
294 else if (m_hashheader.magic != MAGIC)
295 {
296 fprintf (stderr,
297 LOOKUP_C_BAD_MAGIC (hashname, static_cast<unsigned int>(MAGIC),
298 static_cast<unsigned int>(m_hashheader.magic)));
299 return (-1);
300 }
301 else if (m_hashheader.magic2 != MAGIC)
302 {
303 fprintf (stderr,
304 LOOKUP_C_BAD_MAGIC2 (hashname, static_cast<unsigned int>(MAGIC),
305 static_cast<unsigned int>(m_hashheader.magic2)));
306 return (-1);
307 }
308/* else if (hashheader.compileoptions != COMPILEOPTIONS*/
309 else if ( 1 != 1
310 || m_hashheader.maxstringchars != MAXSTRINGCHARS
311 || m_hashheader.maxstringcharlen != MAXSTRINGCHARLEN)
312 {
313 fprintf (stderr,
314 LOOKUP_C_BAD_OPTIONS (static_cast<unsigned int>(m_hashheader.compileoptions),
315 m_hashheader.maxstringchars, m_hashheader.maxstringcharlen,
316 static_cast<unsigned int>(COMPILEOPTIONS), MAXSTRINGCHARS, MAXSTRINGCHARLEN));
317 return (-1);
318 }
319
320 {
321 m_hashtbl =
322 (struct dent *)
323 calloc (static_cast<unsigned>(m_hashheader.tblsize), sizeof (struct dent));
324 m_hashsize = m_hashheader.tblsize;
325 m_hashstrings = static_cast<char *>(malloc(static_cast<unsigned>(m_hashheader.stringsize)));
326 }
327 m_numsflags = m_hashheader.stblsize;
328 m_numpflags = m_hashheader.ptblsize;
329 m_sflaglist = (struct flagent *)
330 malloc ((m_numsflags + m_numpflags) * sizeof (struct flagent));
331 if (m_hashtbl == NULL || m_hashstrings == NULL || m_sflaglist == NULL)
332 {
333 fprintf (stderr, LOOKUP_C_NO_HASH_SPACE);
334 return (-1);
335 }
336 m_pflaglist = m_sflaglist + m_numsflags;
337
338 {
339 if( fread ( m_hashstrings, 1, static_cast<unsigned>(m_hashheader.stringsize), fpHash)
340 != static_cast<size_t>(m_hashheader.stringsize) )
341 {
342 fprintf (stderr, LOOKUP_C_BAD_FORMAT);
343 fprintf (stderr, "stringsize err\n" );
344 return (-1);
345 }
346 if ( m_hashheader.compileoptions & 0x04 )
347 {
348 if( fread (reinterpret_cast<char *>(m_hashtbl), 1, static_cast<unsigned>(m_hashheader.tblsize) * sizeof(struct dent), fpHash)
349 != (static_cast<size_t>(m_hashheader.tblsize * sizeof (struct dent))))
350 {
351 fprintf (stderr, LOOKUP_C_BAD_FORMAT);
352 return (-1);
353 }
354 }
355 else
356 {
357 for( x=0; x<m_hashheader.tblsize; x++ )
358 {
359 if( fread ( reinterpret_cast<char*>(m_hashtbl+x), sizeof( struct dent)-sizeof( MASKTYPE ), 1, fpHash)
360 != 1)
361 {
362 fprintf (stderr, LOOKUP_C_BAD_FORMAT);
363 return (-1);
364 }
365 } /*for*/
366 } /*else*/
367 }
368 if (fread (reinterpret_cast<char *>(m_sflaglist), 1,
369 static_cast<unsigned>(m_numsflags+ m_numpflags) * sizeof (struct flagent), fpHash)
370 != (m_numsflags + m_numpflags) * sizeof (struct flagent))
371 {
372 fprintf (stderr, LOOKUP_C_BAD_FORMAT);
373 return (-1);
374 }
375 fclose (fpHash);
376
377 {
378 for (i = m_hashsize, dp = m_hashtbl; --i >= 0; dp++)
379 {
380 if (dp->word == (char *) -1)
381 dp->word = NULL;
382 else
383 dp->word = &m_hashstrings [ reinterpret_cast<size_t>(dp->word) ];
384 if (dp->next == (struct dent *) -1)
385 dp->next = NULL;
386 else
387 dp->next = &m_hashtbl [ reinterpret_cast<size_t>(dp->next) ];
388 }
389 }
390
391 for (i = m_numsflags + m_numpflags, entry = m_sflaglist; --i >= 0; entry++)
392 {
393 if (entry->stripl)
394 entry->strip = reinterpret_cast<ichar_t *>(&m_hashstrings[reinterpret_cast<size_t>(entry->strip)]);
395 else
396 entry->strip = NULL;
397 if (entry->affl)
398 entry->affix = reinterpret_cast<ichar_t *>(&m_hashstrings[reinterpret_cast<size_t>(entry->affix)]);
399 else
400 entry->affix = NULL;
401 }
402 /*
403 ** Warning - 'entry' and 'i' are reset in the body of the loop
404 ** below. Don't try to optimize it by (e.g.) moving the decrement
405 ** of i into the loop condition.
406 */
407 for (i = m_numsflags, entry = m_sflaglist; i > 0; i--, entry++)
408 {
409 if (entry->affl == 0)
410 {
411 cp = NULL;
412 ind = &m_sflagindex[0];
413 viazero = 1;
414 }
415 else
416 {
417 cp = entry->affix + entry->affl - 1;
418 ind = &m_sflagindex[*cp];
419 viazero = 0;
420 while (ind->numents == 0 && ind->pu.fp != NULL)
421 {
422 if (cp == entry->affix)
423 {
424 ind = &ind->pu.fp[0];
425 viazero = 1;
426 }
427 else
428 {
429 ind = &ind->pu.fp[*--cp];
430 viazero = 0;
431 }
432 }
433 }
434 if (ind->numents == 0)
435 ind->pu.ent = entry;
436 ind->numents++;
437 /*
438 ** If this index entry has more than MAXSEARCH flags in
439 ** it, we will split it into subentries to reduce the
440 ** searching. However, the split doesn't make sense in
441 ** two cases: (a) if we are already at the end of the
442 ** current affix, or (b) if all the entries in the list
443 ** have identical affixes. Since the list is sorted, (b)
444 ** is true if the first and last affixes in the list
445 ** are identical.
446 */
447 if (!viazero && ind->numents >= MAXSEARCH
448 && icharcmp (entry->affix, ind->pu.ent->affix) != 0)
449 {
450 /* Sneaky trick: back up and reprocess */
451 entry = ind->pu.ent - 1; /* -1 is for entry++ in loop */
452 i = m_numsflags - (entry - m_sflaglist);
453 ind->pu.fp =
454 (struct flagptr *)
455 calloc (static_cast<unsigned>(SET_SIZE + m_hashheader.nstrchars),
456 sizeof (struct flagptr));
457 if (ind->pu.fp == NULL)
458 {
459 fprintf (stderr, LOOKUP_C_NO_LANG_SPACE);
460 return (-1);
461 }
462 ind->numents = 0;
463 }
464 }
465 /*
466 ** Warning - 'entry' and 'i' are reset in the body of the loop
467 ** below. Don't try to optimize it by (e.g.) moving the decrement
468 ** of i into the loop condition.
469 */
470 for (i = m_numpflags, entry = m_pflaglist; i > 0; i--, entry++)
471 {
472 if (entry->affl == 0)
473 {
474 cp = NULL;
475 ind = &m_pflagindex[0];
476 viazero = 1;
477 }
478 else
479 {
480 cp = entry->affix;
481 ind = &m_pflagindex[*cp++];
482 viazero = 0;
483 while (ind->numents == 0 && ind->pu.fp != NULL)
484 {
485 if (*cp == 0)
486 {
487 ind = &ind->pu.fp[0];
488 viazero = 1;
489 }
490 else
491 {
492 ind = &ind->pu.fp[*cp++];
493 viazero = 0;
494 }
495 }
496 }
497 if (ind->numents == 0)
498 ind->pu.ent = entry;
499 ind->numents++;
500 /*
501 ** If this index entry has more than MAXSEARCH flags in
502 ** it, we will split it into subentries to reduce the
503 ** searching. However, the split doesn't make sense in
504 ** two cases: (a) if we are already at the end of the
505 ** current affix, or (b) if all the entries in the list
506 ** have identical affixes. Since the list is sorted, (b)
507 ** is true if the first and last affixes in the list
508 ** are identical.
509 */
510 if (!viazero && ind->numents >= MAXSEARCH
511 && icharcmp (entry->affix, ind->pu.ent->affix) != 0)
512 {
513 /* Sneaky trick: back up and reprocess */
514 entry = ind->pu.ent - 1; /* -1 is for entry++ in loop */
515 i = m_numpflags - (entry - m_pflaglist);
516 ind->pu.fp =
517 static_cast<struct flagptr *>(calloc(SET_SIZE + m_hashheader.nstrchars,
518 sizeof (struct flagptr)));
519 if (ind->pu.fp == NULL)
520 {
521 fprintf (stderr, LOOKUP_C_NO_LANG_SPACE);
522 return (-1);
523 }
524 ind->numents = 0;
525 }
526 }
527#ifdef INDEXDUMP
528 fprintf (stderr, "Prefix index table:\n");
529 dumpindex (m_pflagindex, 0);
530 fprintf (stderr, "Suffix index table:\n");
531 dumpindex (m_sflagindex, 0);
532#endif
533 if (m_hashheader.nstrchartype == 0)
534 m_chartypes = NULL;
535 else
536 {
537 m_chartypes = (struct strchartype *)
538 malloc (m_hashheader.nstrchartype * sizeof (struct strchartype));
539 if (m_chartypes == NULL)
540 {
541 fprintf (stderr, LOOKUP_C_NO_LANG_SPACE);
542 return (-1);
543 }
544 for (i = 0, nextchar = m_hashheader.strtypestart;
545 i < m_hashheader.nstrchartype;
546 i++)
547 {
548 m_chartypes[i].name = &m_hashstrings[nextchar];
549 nextchar += strlen (m_chartypes[i].name) + 1;
550 m_chartypes[i].deformatter = &m_hashstrings[nextchar];
551 nextchar += strlen (m_chartypes[i].deformatter) + 1;
552 m_chartypes[i].suffixes = &m_hashstrings[nextchar];
553 while (m_hashstrings[nextchar] != '\0')
554 nextchar += strlen (&m_hashstrings[nextchar]) + 1;
555 nextchar++;
556 }
557 }
558
559 initckch(NULL);
560
561 return (0);
562}
563
564#ifndef FREEP
565#define FREEP(p) do { if (p) free(p); } while (0)
566#endif
567
571void ISpellChecker::initckch (char *wchars)
572{
573 ichar_t c;
574 char num[4];
575
576 for (c = 0; c < static_cast<ichar_t>(SET_SIZE+ m_hashheader.nstrchars); ++c)
577 {
578 if (iswordch (c))
579 {
580 if (!mylower (c))
581 {
582 m_Try[m_Trynum] = c;
583 ++m_Trynum;
584 }
585 }
586 else if (isboundarych (c))
587 {
588 m_Try[m_Trynum] = c;
589 ++m_Trynum;
590 }
591 }
592 if (wchars != NULL)
593 {
594 while (m_Trynum < SET_SIZE && *wchars != '\0')
595 {
596 if (*wchars != 'n' && *wchars != '\\')
597 {
598 c = *wchars;
599 ++wchars;
600 }
601 else
602 {
603 ++wchars;
604 num[0] = '\0';
605 num[1] = '\0';
606 num[2] = '\0';
607 num[3] = '\0';
608 if (isdigit (wchars[0]))
609 {
610 num[0] = wchars[0];
611 if (isdigit (wchars[1]))
612 {
613 num[1] = wchars[1];
614 if (isdigit (wchars[2]))
615 num[2] = wchars[2];
616 }
617 }
618 if (wchars[-1] == 'n')
619 {
620 wchars += strlen (num);
621 c = atoi (num);
622 }
623 else
624 {
625 wchars += strlen (num);
626 c = 0;
627 if (num[0])
628 c = num[0] - '0';
629 if (num[1])
630 {
631 c <<= 3;
632 c += num[1] - '0';
633 }
634 if (num[2])
635 {
636 c <<= 3;
637 c += num[2] - '0';
638 }
639 }
640 }
641/* c &= NOPARITY;*/
642 if (!m_hashheader.wordchars[c])
643 {
644 m_hashheader.wordchars[c] = 1;
645 m_hashheader.sortorder[c] = m_hashheader.sortval++;
646 m_Try[m_Trynum] = c;
647 ++m_Trynum;
648 }
649 }
650 }
651}
652
653/*
654 * \param indexp
655 */
656void ISpellChecker::clearindex (struct flagptr *indexp)
657{
658 int i;
659 for (i = 0; i < SET_SIZE + m_hashheader.nstrchars; i++, indexp++)
660 {
661 if (indexp->numents == 0 && indexp->pu.fp != NULL)
662 {
663 clearindex(indexp->pu.fp);
664 free(indexp->pu.fp);
665 }
666 }
667}
668
669#ifdef INDEXDUMP
670static void dumpindex (indexp, depth)
671 struct flagptr * indexp;
672 int depth;
673{
674 int i;
675 int j;
676 int k;
677 char stripbuf[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4];
678
679 for (i = 0; i < SET_SIZE + hashheader.nstrchars; i++, indexp++)
680 {
681 if (indexp->numents == 0 && indexp->pu.fp != NULL)
682 {
683 for (j = depth; --j >= 0; )
684 putc (' ', stderr);
685 if (i >= ' ' && i <= '~')
686 putc (i, stderr);
687 else
688 fprintf (stderr, "0x%x", i);
689 putc ('\n', stderr);
690 dumpindex (indexp->pu.fp, depth + 1);
691 }
692 else if (indexp->numents)
693 {
694 for (j = depth; --j >= 0; )
695 putc (' ', stderr);
696 if (i >= ' ' && i <= '~')
697 putc (i, stderr);
698 else
699 fprintf (stderr, "0x%x", i);
700 fprintf (stderr, " -> %d entries\n", indexp->numents);
701 for (k = 0; k < indexp->numents; k++)
702 {
703 for (j = depth; --j >= 0; )
704 putc (' ', stderr);
705 if (indexp->pu.ent[k].stripl)
706 {
707 ichartostr (stripbuf, indexp->pu.ent[k].strip,
708 sizeof stripbuf, 1);
709 fprintf (stderr, " entry %d (-%s,%s)\n",
710 &indexp->pu.ent[k] - sflaglist,
711 stripbuf,
712 indexp->pu.ent[k].affl
713 ? ichartosstr (indexp->pu.ent[k].affix, 1) : "-");
714 }
715 else
716 fprintf (stderr, " entry %d (%s)\n",
717 &indexp->pu.ent[k] - sflaglist,
718 ichartosstr (indexp->pu.ent[k].affix, 1));
719 }
720 }
721 }
722}
723#endif
724
725/* n is length of s */
726
727/*
728 * \param s
729 * \param dotree
730 *
731 * \return
732 */
733struct dent * ISpellChecker::ispell_lookup (ichar_t *s, int dotree)
734{
735 struct dent * dp;
736 char * s1;
737 char schar[INPUTWORDLEN + MAXAFFIXLEN];
738
739 dp = &m_hashtbl[hash (s, m_hashsize)];
740 if (ichartostr (schar, s, sizeof schar, 1))
741 fprintf (stderr, WORD_TOO_LONG (schar));
742 for ( ; dp != NULL; dp = dp->next)
743 {
744 /* quick strcmp, but only for equality */
745 s1 = dp->word;
746 if (s1 && s1[0] == schar[0] && strcmp (s1 + 1, schar + 1) == 0)
747 return dp;
748#ifndef NO_CAPITALIZATION_SUPPORT
749 while (dp->flagfield & MOREVARIANTS) /* Skip variations */
750 dp = dp->next;
751#endif
752 }
753 return NULL;
754}
755
756void ISpellChecker::alloc_ispell_struct()
757{
758 m_translate_in = 0;
759}
760
761void ISpellChecker::free_ispell_struct()
762{
763}

tdespell2

Skip menu "tdespell2"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

tdespell2

Skip menu "tdespell2"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdespell2 by doxygen 1.9.4
This website is maintained by Timothy Pearson.