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

tdespell2

  • tdespell2
  • plugins
  • ispell
correct.cpp
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* enchant
3  * Copyright (C) 2003 Dom Lachowicz
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 Lesser 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  * correct.c - Routines to manage the higher-level aspects of spell-checking
33  *
34  * This code originally resided in ispell.c, but was moved here to keep
35  * file sizes smaller.
36  *
37  * Copyright (c), 1983, by Pace Willisson
38  *
39  * Copyright 1992, 1993, Geoff Kuenning, Granada Hills, CA
40  * All rights reserved.
41  *
42  * Redistribution and use in source and binary forms, with or without
43  * modification, are permitted provided that the following conditions
44  * are met:
45  *
46  * 1. Redistributions of source code must retain the above copyright
47  * notice, this list of conditions and the following disclaimer.
48  * 2. Redistributions in binary form must reproduce the above copyright
49  * notice, this list of conditions and the following disclaimer in the
50  * documentation and/or other materials provided with the distribution.
51  * 3. All modifications to the source code must be clearly marked as
52  * such. Binary redistributions based on modified source code
53  * must be clearly marked as modified versions in the documentation
54  * and/or other materials provided with the distribution.
55  * 4. All advertising materials mentioning features or use of this software
56  * must display the following acknowledgment:
57  * This product includes software developed by Geoff Kuenning and
58  * other unpaid contributors.
59  * 5. The name of Geoff Kuenning may not be used to endorse or promote
60  * products derived from this software without specific prior
61  * written permission.
62  *
63  * THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND
64  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
66  * ARE DISCLAIMED. IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE
67  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
69  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73  * SUCH DAMAGE.
74  */
75 
76 /*
77  * $Log$
78  * Revision 1.1 2004/01/31 16:44:12 zrusin
79  * ISpell plugin.
80  *
81  * Revision 1.4 2003/08/14 17:51:26 dom
82  * update license - exception clause should be Lesser GPL
83  *
84  * Revision 1.3 2003/07/28 20:40:25 dom
85  * fix up the license clause, further win32-registry proof some directory getting functions
86  *
87  * Revision 1.2 2003/07/16 22:52:35 dom
88  * LGPL + exception license
89  *
90  * Revision 1.1 2003/07/15 01:15:04 dom
91  * ispell enchant backend
92  *
93  * Revision 1.2 2003/01/29 05:50:11 hippietrail
94  *
95  * Fixed my mess in EncodingManager.
96  * Changed many C casts to C++ casts.
97  *
98  * Revision 1.1 2003/01/24 05:52:31 hippietrail
99  *
100  * Refactored ispell code. Old ispell global variables had been put into
101  * an allocated structure, a pointer to which was passed to many functions.
102  * I have now made all such functions and variables private members of the
103  * ISpellChecker class. It was C OO, now it's C++ OO.
104  *
105  * I've fixed the makefiles and tested compilation but am unable to test
106  * operation. Please back out my changes if they cause problems which
107  * are not obvious or easy to fix.
108  *
109  * Revision 1.7 2002/09/19 05:31:15 hippietrail
110  *
111  * More Ispell cleanup. Conditional globals and DEREF macros are removed.
112  * K&R function declarations removed, converted to Doxygen style comments
113  * where possible. No code has been changed (I hope). Compiles for me but
114  * unable to test.
115  *
116  * Revision 1.6 2002/09/17 03:03:28 hippietrail
117  *
118  * After seeking permission on the developer list I've reformatted all the
119  * spelling source which seemed to have parts which used 2, 3, 4, and 8
120  * spaces for tabs. It should all look good with our standard 4-space
121  * tabs now.
122  * I've concentrated just on indentation in the actual code. More prettying
123  * could be done.
124  * * NO code changes were made *
125  *
126  * Revision 1.5 2002/09/13 17:20:12 mpritchett
127  * Fix more warnings for Linux build
128  *
129  * Revision 1.4 2002/03/06 08:27:16 fjfranklin
130  * o Only activate compound handling when the hash file says so (Per Larsson)
131  *
132  * Revision 1.3 2001/05/14 09:52:50 hub
133  * Removed newMain.c from GNUmakefile.am
134  *
135  * C++ comments are not C comment. Changed to C comments
136  *
137  * Revision 1.2 2001/05/12 16:05:42 thomasf
138  * Big pseudo changes to ispell to make it pass around a structure rather
139  * than rely on all sorts of gloabals willy nilly here and there. Also
140  * fixed our spelling class to work with accepting suggestions once more.
141  * This code is dirty, gross and ugly (not to mention still not supporting
142  * multiple hash sized just yet) but it works on my machine and will no
143  * doubt break other machines.
144  *
145  * Revision 1.1 2001/04/15 16:01:24 tomas_f
146  * moving to spell/xp
147  *
148  * Revision 1.2 1999/10/05 16:17:28 paul
149  * Fixed build, and other tidyness.
150  * Spell dialog enabled by default, with keyboard binding of F7.
151  *
152  * Revision 1.1 1999/09/29 23:33:32 justin
153  * Updates to the underlying ispell-based code to support suggested corrections.
154  *
155  * Revision 1.59 1995/08/05 23:19:43 geoff
156  * Fix a bug that caused offsets for long lines to be confused if the
157  * line started with a quoting uparrow.
158  *
159  * Revision 1.58 1994/11/02 06:56:00 geoff
160  * Remove the anyword feature, which I've decided is a bad idea.
161  *
162  * Revision 1.57 1994/10/26 05:12:39 geoff
163  * Try boundary characters when inserting or substituting letters, except
164  * (naturally) at word boundaries.
165  *
166  * Revision 1.56 1994/10/25 05:46:30 geoff
167  * Fix an assignment inside a conditional that could generate spurious
168  * warnings (as well as being bad style). Add support for the FF_ANYWORD
169  * option.
170  *
171  * Revision 1.55 1994/09/16 04:48:24 geoff
172  * Don't pass newlines from the input to various other routines, and
173  * don't assume that those routines leave the input unchanged.
174  *
175  * Revision 1.54 1994/09/01 06:06:41 geoff
176  * Change erasechar/killchar to uerasechar/ukillchar to avoid
177  * shared-library problems on HP systems.
178  *
179  * Revision 1.53 1994/08/31 05:58:38 geoff
180  * Add code to handle extremely long lines in -a mode without splitting
181  * words or reporting incorrect offsets.
182  *
183  * Revision 1.52 1994/05/25 04:29:24 geoff
184  * Fix a bug that caused line widths to be calculated incorrectly when
185  * displaying lines containing tabs. Fix a couple of places where
186  * characters were sign-extended incorrectly, which could cause 8-bit
187  * characters to be displayed wrong.
188  *
189  * Revision 1.51 1994/05/17 06:44:05 geoff
190  * Add support for controlled compound formation and the COMPOUNDONLY
191  * option to affix flags.
192  *
193  * Revision 1.50 1994/04/27 05:20:14 geoff
194  * Allow compound words to be formed from more than two components
195  *
196  * Revision 1.49 1994/04/27 01:50:31 geoff
197  * Add support to correctly capitalize words generated as a result of a
198  * missing-space suggestion.
199  *
200  * Revision 1.48 1994/04/03 23:23:02 geoff
201  * Clean up the code in missingspace() to be a bit simpler and more
202  * efficient.
203  *
204  * Revision 1.47 1994/03/15 06:24:23 geoff
205  * Fix the +/-/~ commands to be independent. Allow the + command to
206  * receive a suffix which is a deformatter type (currently hardwired to
207  * be either tex or nroff/troff).
208  *
209  * Revision 1.46 1994/02/21 00:20:03 geoff
210  * Fix some bugs that could cause bad displays in the interaction between
211  * TeX parsing and string characters. Show_char now will not overrun
212  * the inverse-video display area by accident.
213  *
214  * Revision 1.45 1994/02/14 00:34:51 geoff
215  * Fix correct to accept length parameters for ctok and itok, so that it
216  * can pass them to the to/from ichar routines.
217  *
218  * Revision 1.44 1994/01/25 07:11:22 geoff
219  * Get rid of all old RCS log lines in preparation for the 3.1 release.
220  *
221  */
222 
223 #include <stdlib.h>
224 #include <string.h>
225 #include <ctype.h>
226 #include "ispell_checker.h"
227 #include "msgs.h"
228 
229 /*
230 extern void upcase P ((ichar_t * string));
231 extern void lowcase P ((ichar_t * string));
232 extern ichar_t * strtosichar P ((char * in, int canonical));
233 
234 int compoundflag = COMPOUND_CONTROLLED;
235 */
236 
237 /*
238  * \param a
239  * \param b
240  * \param canonical NZ for canonical string chars
241  *
242  * \return
243  */
244 int
245 ISpellChecker::casecmp (char *a, char *b, int canonical)
246 {
247  register ichar_t * ap;
248  register ichar_t * bp;
249  ichar_t inta[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4];
250  ichar_t intb[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4];
251 
252  strtoichar (inta, a, sizeof inta, canonical);
253  strtoichar (intb, b, sizeof intb, canonical);
254  for (ap = inta, bp = intb; *ap != 0; ap++, bp++)
255  {
256  if (*ap != *bp)
257  {
258  if (*bp == '\0')
259  return m_hashheader.sortorder[*ap];
260  else if (mylower (*ap))
261  {
262  if (mylower (*bp) || mytoupper (*ap) != *bp)
263  return static_cast<int>(m_hashheader.sortorder[*ap])
264  - static_cast<int>(m_hashheader.sortorder[*bp]);
265  }
266  else
267  {
268  if (myupper (*bp) || mytolower (*ap) != *bp)
269  return static_cast<int>(m_hashheader.sortorder[*ap])
270  - static_cast<int>(m_hashheader.sortorder[*bp]);
271  }
272  }
273  }
274  if (*bp != '\0')
275  return -static_cast<int>(m_hashheader.sortorder[*bp]);
276  for (ap = inta, bp = intb; *ap; ap++, bp++)
277  {
278  if (*ap != *bp)
279  {
280  return static_cast<int>(m_hashheader.sortorder[*ap])
281  - static_cast<int>(m_hashheader.sortorder[*bp]);
282  }
283  }
284  return 0;
285 }
286 
287 /*
288  * \param word
289  */
290 void
291 ISpellChecker::makepossibilities (ichar_t *word)
292 {
293  register int i;
294 
295  for (i = 0; i < MAXPOSSIBLE; i++)
296  m_possibilities[i][0] = 0;
297  m_pcount = 0;
298  m_maxposslen = 0;
299  m_easypossibilities = 0;
300 
301 #ifndef NO_CAPITALIZATION_SUPPORT
302  wrongcapital (word);
303 #endif
304 
305 /*
306  * according to Pollock and Zamora, CACM April 1984 (V. 27, No. 4),
307  * page 363, the correct order for this is:
308  * OMISSION = TRANSPOSITION > INSERTION > SUBSTITUTION
309  * thus, it was exactly backwards in the old version. -- PWP
310  */
311 
312  if (m_pcount < MAXPOSSIBLE)
313  missingletter (word); /* omission */
314  if (m_pcount < MAXPOSSIBLE)
315  transposedletter (word); /* transposition */
316  if (m_pcount < MAXPOSSIBLE)
317  extraletter (word); /* insertion */
318  if (m_pcount < MAXPOSSIBLE)
319  wrongletter (word); /* substitution */
320 
321  if ((m_hashheader.compoundflag != COMPOUND_ANYTIME) &&
322  m_pcount < MAXPOSSIBLE)
323  missingspace (word); /* two words */
324 
325 }
326 
327 /*
328  * \param word
329  *
330  * \return
331  */
332 int
333 ISpellChecker::insert (ichar_t *word)
334 {
335  register int i;
336  register char * realword;
337 
338  realword = ichartosstr (word, 0);
339  for (i = 0; i < m_pcount; i++)
340  {
341  if (strcmp (m_possibilities[i], realword) == 0)
342  return (0);
343  }
344 
345  strcpy (m_possibilities[m_pcount++], realword);
346  i = strlen (realword);
347  if (i > m_maxposslen)
348  m_maxposslen = i;
349  if (m_pcount >= MAXPOSSIBLE)
350  return (-1);
351  else
352  return (0);
353 }
354 
355 #ifndef NO_CAPITALIZATION_SUPPORT
356 /*
357  * \param word
358  */
359 void
360 ISpellChecker::wrongcapital (ichar_t *word)
361 {
362  ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN];
363 
364  /*
365  ** When the third parameter to "good" is nonzero, it ignores
366  ** case. If the word matches this way, "ins_cap" will recapitalize
367  ** it correctly.
368  */
369  if (good (word, 0, 1, 0, 0))
370  {
371  icharcpy (newword, word);
372  upcase (newword);
373  ins_cap (newword, word);
374  }
375 }
376 #endif
377 
378 /*
379  * \param word
380  */
381 void
382 ISpellChecker::wrongletter (ichar_t *word)
383 {
384  register int i;
385  register int j;
386  register int n;
387  ichar_t savechar;
388  ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN];
389 
390  n = icharlen (word);
391  icharcpy (newword, word);
392 #ifndef NO_CAPITALIZATION_SUPPORT
393  upcase (newword);
394 #endif
395 
396  for (i = 0; i < n; i++)
397  {
398  savechar = newword[i];
399  for (j=0; j < m_Trynum; ++j)
400  {
401  if (m_Try[j] == savechar)
402  continue;
403  else if (isboundarych (m_Try[j]) && (i == 0 || i == n - 1))
404  continue;
405  newword[i] = m_Try[j];
406  if (good (newword, 0, 1, 0, 0))
407  {
408  if (ins_cap (newword, word) < 0)
409  return;
410  }
411  }
412  newword[i] = savechar;
413  }
414 }
415 
416 /*
417  * \param word
418  */
419 void
420 ISpellChecker::extraletter (ichar_t *word)
421 {
422  ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN];
423  register ichar_t * p;
424  register ichar_t * r;
425 
426  if (icharlen (word) < 2)
427  return;
428 
429  icharcpy (newword, word + 1);
430  for (p = word, r = newword; *p != 0; )
431  {
432  if (good (newword, 0, 1, 0, 0))
433  {
434  if (ins_cap (newword, word) < 0)
435  return;
436  }
437  *r++ = *p++;
438  }
439 }
440 
441 /*
442  * \param word
443  */
444 void
445 ISpellChecker::missingletter (ichar_t *word)
446 {
447  ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN + 1];
448  register ichar_t * p;
449  register ichar_t * r;
450  register int i;
451 
452  icharcpy (newword + 1, word);
453  for (p = word, r = newword; *p != 0; )
454  {
455  for (i = 0; i < m_Trynum; i++)
456  {
457  if (isboundarych (m_Try[i]) && r == newword)
458  continue;
459  *r = m_Try[i];
460  if (good (newword, 0, 1, 0, 0))
461  {
462  if (ins_cap (newword, word) < 0)
463  return;
464  }
465  }
466  *r++ = *p++;
467  }
468  for (i = 0; i < m_Trynum; i++)
469  {
470  if (isboundarych (m_Try[i]))
471  continue;
472  *r = m_Try[i];
473  if (good (newword, 0, 1, 0, 0))
474  {
475  if (ins_cap (newword, word) < 0)
476  return;
477  }
478  }
479 }
480 
481 /*
482  * \param word
483  */
484 void ISpellChecker::missingspace (ichar_t *word)
485 {
486  ichar_t firsthalf[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN];
487  int firstno; /* Index into first */
488  ichar_t * firstp; /* Ptr into current firsthalf word */
489  ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN + 1];
490  int nfirsthalf; /* No. words saved in 1st half */
491  int nsecondhalf; /* No. words saved in 2nd half */
492  register ichar_t * p;
493  ichar_t secondhalf[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN];
494  int secondno; /* Index into second */
495 
496  /*
497  ** We don't do words of length less than 3; this keeps us from
498  ** splitting all two-letter words into two single letters. We
499  ** also don't do maximum-length words, since adding the space
500  ** would exceed the size of the "possibilities" array.
501  */
502  nfirsthalf = icharlen (word);
503  if (nfirsthalf < 3 || nfirsthalf >= INPUTWORDLEN + MAXAFFIXLEN - 1)
504  return;
505  icharcpy (newword + 1, word);
506  for (p = newword + 1; p[1] != '\0'; p++)
507  {
508  p[-1] = *p;
509  *p = '\0';
510  if (good (newword, 0, 1, 0, 0))
511  {
512  /*
513  * Save_cap must be called before good() is called on the
514  * second half, because it uses state left around by
515  * good(). This is unfortunate because it wastes a bit of
516  * time, but I don't think it's a significant performance
517  * problem.
518  */
519  nfirsthalf = save_cap (newword, word, firsthalf);
520  if (good (p + 1, 0, 1, 0, 0))
521  {
522  nsecondhalf = save_cap (p + 1, p + 1, secondhalf);
523  for (firstno = 0; firstno < nfirsthalf; firstno++)
524  {
525  firstp = &firsthalf[firstno][p - newword];
526  for (secondno = 0; secondno < nsecondhalf; secondno++)
527  {
528  *firstp = ' ';
529  icharcpy (firstp + 1, secondhalf[secondno]);
530  if (insert (firsthalf[firstno]) < 0)
531  return;
532  *firstp = '-';
533  if (insert (firsthalf[firstno]) < 0)
534  return;
535  }
536  }
537  }
538  }
539  }
540 }
541 
542 /*
543  * \param word
544  * \param pfxopts Options to apply to prefixes
545  */
546 int
547 ISpellChecker::compoundgood (ichar_t *word, int pfxopts)
548 {
549  ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN];
550  register ichar_t * p;
551  register ichar_t savech;
552  long secondcap; /* Capitalization of 2nd half */
553 
554  /*
555  ** If compoundflag is COMPOUND_NEVER, compound words are never ok.
556  */
557  if (m_hashheader.compoundflag == COMPOUND_NEVER)
558  return 0;
559  /*
560  ** Test for a possible compound word (for languages like German that
561  ** form lots of compounds).
562  **
563  ** This is similar to missingspace, except we quit on the first hit,
564  ** and we won't allow either member of the compound to be a single
565  ** letter.
566  **
567  ** We don't do words of length less than 2 * compoundmin, since
568  ** both halves must at least compoundmin letters.
569  */
570  if (icharlen (word) < 2 * m_hashheader.compoundmin)
571  return 0;
572  icharcpy (newword, word);
573  p = newword + m_hashheader.compoundmin;
574  for ( ; p[m_hashheader.compoundmin - 1] != 0; p++)
575  {
576  savech = *p;
577  *p = 0;
578  if (good (newword, 0, 0, pfxopts, FF_COMPOUNDONLY))
579  {
580  *p = savech;
581  if (good (p, 0, 1, FF_COMPOUNDONLY, 0)
582  || compoundgood (p, FF_COMPOUNDONLY))
583  {
584  secondcap = whatcap (p);
585  switch (whatcap (newword))
586  {
587  case ANYCASE:
588  case CAPITALIZED:
589  case FOLLOWCASE: /* Followcase can have l.c. suffix */
590  return secondcap == ANYCASE;
591  case ALLCAPS:
592  return secondcap == ALLCAPS;
593  }
594  }
595  }
596  else
597  *p = savech;
598  }
599  return 0;
600 }
601 
602 /*
603  * \param word
604  */
605 void
606 ISpellChecker::transposedletter (ichar_t *word)
607 {
608  ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN];
609  register ichar_t * p;
610  register ichar_t temp;
611 
612  icharcpy (newword, word);
613  for (p = newword; p[1] != 0; p++)
614  {
615  temp = *p;
616  *p = p[1];
617  p[1] = temp;
618  if (good (newword, 0, 1, 0, 0))
619  {
620  if (ins_cap (newword, word) < 0)
621  return;
622  }
623  temp = *p;
624  *p = p[1];
625  p[1] = temp;
626  }
627 }
628 
637 int
638 ISpellChecker::ins_cap (ichar_t *word, ichar_t *pattern)
639 {
640  int i; /* Index into savearea */
641  int nsaved; /* No. of words saved */
642  ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN];
643 
644  nsaved = save_cap (word, pattern, savearea);
645  for (i = 0; i < nsaved; i++)
646  {
647  if (insert (savearea[i]) < 0)
648  return -1;
649  }
650  return 0;
651 }
652 
662 int
663 ISpellChecker::save_cap (ichar_t *word, ichar_t *pattern,
664  ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN])
665 {
666  int hitno; /* Index into hits array */
667  int nsaved; /* Number of words saved */
668  int preadd; /* No. chars added to front of root */
669  int prestrip; /* No. chars stripped from front */
670  int sufadd; /* No. chars added to back of root */
671  int sufstrip; /* No. chars stripped from back */
672 
673  if (*word == 0)
674  return 0;
675 
676  for (hitno = m_numhits, nsaved = 0; --hitno >= 0 && nsaved < MAX_CAPS; )
677  {
678  if (m_hits[hitno].prefix)
679  {
680  prestrip = m_hits[hitno].prefix->stripl;
681  preadd = m_hits[hitno].prefix->affl;
682  }
683  else
684  prestrip = preadd = 0;
685  if (m_hits[hitno].suffix)
686  {
687  sufstrip = m_hits[hitno].suffix->stripl;
688  sufadd = m_hits[hitno].suffix->affl;
689  }
690  else
691  sufadd = sufstrip = 0;
692  save_root_cap (word, pattern, prestrip, preadd,
693  sufstrip, sufadd,
694  m_hits[hitno].dictent, m_hits[hitno].prefix, m_hits[hitno].suffix,
695  savearea, &nsaved);
696  }
697  return nsaved;
698 }
699 
700 /*
701  * \param word
702  * \param pattern
703  * \param prestrip
704  * \param preadd
705  * \param sufstrip
706  * \param sufadd
707  * \param firstdent
708  * \param pfxent
709  * \param sufent
710  *
711  * \return
712  */
713 int
714 ISpellChecker::ins_root_cap (ichar_t *word, ichar_t *pattern,
715  int prestrip, int preadd, int sufstrip, int sufadd,
716  struct dent *firstdent, struct flagent *pfxent, struct flagent *sufent)
717 {
718  int i; /* Index into savearea */
719  ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN];
720  int nsaved; /* Number of words saved */
721 
722  nsaved = 0;
723  save_root_cap (word, pattern, prestrip, preadd, sufstrip, sufadd,
724  firstdent, pfxent, sufent, savearea, &nsaved);
725  for (i = 0; i < nsaved; i++)
726  {
727  if (insert (savearea[i]) < 0)
728  return -1;
729  }
730  return 0;
731 }
732 
733 /* ARGSUSED */
747 void
748 ISpellChecker::save_root_cap (ichar_t *word, ichar_t *pattern,
749  int prestrip, int preadd, int sufstrip, int sufadd,
750  struct dent *firstdent, struct flagent *pfxent, struct flagent *sufent,
751  ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN],
752  int * nsaved)
753 {
754 #ifndef NO_CAPITALIZATION_SUPPORT
755  register struct dent * dent;
756 #endif /* NO_CAPITALIZATION_SUPPORT */
757  int firstisupper;
758  ichar_t newword[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4];
759 #ifndef NO_CAPITALIZATION_SUPPORT
760  register ichar_t * p;
761  int len;
762  int i;
763  int limit;
764 #endif /* NO_CAPITALIZATION_SUPPORT */
765 
766  if (*nsaved >= MAX_CAPS)
767  return;
768  icharcpy (newword, word);
769  firstisupper = myupper (pattern[0]);
770 #ifdef NO_CAPITALIZATION_SUPPORT
771  /*
772  ** Apply the old, simple-minded capitalization rules.
773  */
774  if (firstisupper)
775  {
776  if (myupper (pattern[1]))
777  upcase (newword);
778  else
779  {
780  lowcase (newword);
781  newword[0] = mytoupper (newword[0]);
782  }
783  }
784  else
785  lowcase (newword);
786  icharcpy (savearea[*nsaved], newword);
787  (*nsaved)++;
788  return;
789 #else /* NO_CAPITALIZATION_SUPPORT */
790 #define flagsareok(dent) \
791  ((pfxent == NULL \
792  || TSTMASKBIT (dent->mask, pfxent->flagbit)) \
793  && (sufent == NULL \
794  || TSTMASKBIT (dent->mask, sufent->flagbit)))
795 
796  dent = firstdent;
797  if ((dent->flagfield & (CAPTYPEMASK | MOREVARIANTS)) == ALLCAPS)
798  {
799  upcase (newword); /* Uppercase required */
800  icharcpy (savearea[*nsaved], newword);
801  (*nsaved)++;
802  return;
803  }
804  for (p = pattern; *p; p++)
805  {
806  if (mylower (*p))
807  break;
808  }
809  if (*p == 0)
810  {
811  upcase (newword); /* Pattern was all caps */
812  icharcpy (savearea[*nsaved], newword);
813  (*nsaved)++;
814  return;
815  }
816  for (p = pattern + 1; *p; p++)
817  {
818  if (myupper (*p))
819  break;
820  }
821  if (*p == 0)
822  {
823  /*
824  ** The pattern was all-lower or capitalized. If that's
825  ** legal, insert only that version.
826  */
827  if (firstisupper)
828  {
829  if (captype (dent->flagfield) == CAPITALIZED
830  || captype (dent->flagfield) == ANYCASE)
831  {
832  lowcase (newword);
833  newword[0] = mytoupper (newword[0]);
834  icharcpy (savearea[*nsaved], newword);
835  (*nsaved)++;
836  return;
837  }
838  }
839  else
840  {
841  if (captype (dent->flagfield) == ANYCASE)
842  {
843  lowcase (newword);
844  icharcpy (savearea[*nsaved], newword);
845  (*nsaved)++;
846  return;
847  }
848  }
849  while (dent->flagfield & MOREVARIANTS)
850  {
851  dent = dent->next;
852  if (captype (dent->flagfield) == FOLLOWCASE
853  || !flagsareok (dent))
854  continue;
855  if (firstisupper)
856  {
857  if (captype (dent->flagfield) == CAPITALIZED)
858  {
859  lowcase (newword);
860  newword[0] = mytoupper (newword[0]);
861  icharcpy (savearea[*nsaved], newword);
862  (*nsaved)++;
863  return;
864  }
865  }
866  else
867  {
868  if (captype (dent->flagfield) == ANYCASE)
869  {
870  lowcase (newword);
871  icharcpy (savearea[*nsaved], newword);
872  (*nsaved)++;
873  return;
874  }
875  }
876  }
877  }
878  /*
879  ** Either the sample had complex capitalization, or the simple
880  ** capitalizations (all-lower or capitalized) are illegal.
881  ** Insert all legal capitalizations, including those that are
882  ** all-lower or capitalized. If the prototype is capitalized,
883  ** capitalized all-lower samples. Watch out for affixes.
884  */
885  dent = firstdent;
886  p = strtosichar (dent->word, 1);
887  len = icharlen (p);
888  if (dent->flagfield & MOREVARIANTS)
889  dent = dent->next; /* Skip place-holder entry */
890  for ( ; ; )
891  {
892  if (flagsareok (dent))
893  {
894  if (captype (dent->flagfield) != FOLLOWCASE)
895  {
896  lowcase (newword);
897  if (firstisupper || captype (dent->flagfield) == CAPITALIZED)
898  newword[0] = mytoupper (newword[0]);
899  icharcpy (savearea[*nsaved], newword);
900  (*nsaved)++;
901  if (*nsaved >= MAX_CAPS)
902  return;
903  }
904  else
905  {
906  /* Followcase is the tough one. */
907  p = strtosichar (dent->word, 1);
908  memmove (
909  reinterpret_cast<char *>(newword + preadd),
910  reinterpret_cast<char *>(p + prestrip),
911  (len - prestrip - sufstrip) * sizeof (ichar_t));
912  if (myupper (p[prestrip]))
913  {
914  for (i = 0; i < preadd; i++)
915  newword[i] = mytoupper (newword[i]);
916  }
917  else
918  {
919  for (i = 0; i < preadd; i++)
920  newword[i] = mytolower (newword[i]);
921  }
922  limit = len + preadd + sufadd - prestrip - sufstrip;
923  i = len + preadd - prestrip - sufstrip;
924  p += len - sufstrip - 1;
925  if (myupper (*p))
926  {
927  for (p = newword + i; i < limit; i++, p++)
928  *p = mytoupper (*p);
929  }
930  else
931  {
932  for (p = newword + i; i < limit; i++, p++)
933  *p = mytolower (*p);
934  }
935  icharcpy (savearea[*nsaved], newword);
936  (*nsaved)++;
937  if (*nsaved >= MAX_CAPS)
938  return;
939  }
940  }
941  if ((dent->flagfield & MOREVARIANTS) == 0)
942  break; /* End of the line */
943  dent = dent->next;
944  }
945  return;
946 #endif /* NO_CAPITALIZATION_SUPPORT */
947 }
948 
949 

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.8.11
This website is maintained by Timothy Pearson.