225 #include "ispell_checker.h"
244 ISpellChecker::casecmp (
char *a,
char *b,
int canonical)
248 ichar_t inta[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4];
249 ichar_t intb[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4];
251 strtoichar (inta, a,
sizeof inta, canonical);
252 strtoichar (intb, b,
sizeof intb, canonical);
253 for (ap = inta, bp = intb; *ap != 0; ap++, bp++)
258 return m_hashheader.sortorder[*ap];
259 else if (mylower (*ap))
261 if (mylower (*bp) || mytoupper (*ap) != *bp)
262 return static_cast<int>(m_hashheader.sortorder[*ap])
263 -
static_cast<int>(m_hashheader.sortorder[*bp]);
267 if (myupper (*bp) || mytolower (*ap) != *bp)
268 return static_cast<int>(m_hashheader.sortorder[*ap])
269 -
static_cast<int>(m_hashheader.sortorder[*bp]);
274 return -
static_cast<int>(m_hashheader.sortorder[*bp]);
275 for (ap = inta, bp = intb; *ap; ap++, bp++)
279 return static_cast<int>(m_hashheader.sortorder[*ap])
280 -
static_cast<int>(m_hashheader.sortorder[*bp]);
290 ISpellChecker::makepossibilities (ichar_t *word)
294 for (i = 0; i < MAXPOSSIBLE; i++)
295 m_possibilities[i][0] = 0;
298 m_easypossibilities = 0;
300 #ifndef NO_CAPITALIZATION_SUPPORT
311 if (m_pcount < MAXPOSSIBLE)
312 missingletter (word);
313 if (m_pcount < MAXPOSSIBLE)
314 transposedletter (word);
315 if (m_pcount < MAXPOSSIBLE)
317 if (m_pcount < MAXPOSSIBLE)
320 if ((m_hashheader.compoundflag != COMPOUND_ANYTIME) &&
321 m_pcount < MAXPOSSIBLE)
332 ISpellChecker::insert (ichar_t *word)
337 realword = ichartosstr (word, 0);
338 for (i = 0; i < m_pcount; i++)
340 if (strcmp (m_possibilities[i], realword) == 0)
344 strcpy (m_possibilities[m_pcount++], realword);
345 i = strlen (realword);
346 if (i > m_maxposslen)
348 if (m_pcount >= MAXPOSSIBLE)
354 #ifndef NO_CAPITALIZATION_SUPPORT
359 ISpellChecker::wrongcapital (ichar_t *word)
361 ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN];
368 if (good (word, 0, 1, 0, 0))
370 icharcpy (newword, word);
372 ins_cap (newword, word);
381 ISpellChecker::wrongletter (ichar_t *word)
387 ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN];
390 icharcpy (newword, word);
391 #ifndef NO_CAPITALIZATION_SUPPORT
395 for (i = 0; i < n; i++)
397 savechar = newword[i];
398 for (j=0; j < m_Trynum; ++j)
400 if (m_Try[j] == savechar)
402 else if (isboundarych (m_Try[j]) && (i == 0 || i == n - 1))
404 newword[i] = m_Try[j];
405 if (good (newword, 0, 1, 0, 0))
407 if (ins_cap (newword, word) < 0)
411 newword[i] = savechar;
419 ISpellChecker::extraletter (ichar_t *word)
421 ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN];
425 if (icharlen (word) < 2)
428 icharcpy (newword, word + 1);
429 for (p = word, r = newword; *p != 0; )
431 if (good (newword, 0, 1, 0, 0))
433 if (ins_cap (newword, word) < 0)
444 ISpellChecker::missingletter (ichar_t *word)
446 ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN + 1];
451 icharcpy (newword + 1, word);
452 for (p = word, r = newword; *p != 0; )
454 for (i = 0; i < m_Trynum; i++)
456 if (isboundarych (m_Try[i]) && r == newword)
459 if (good (newword, 0, 1, 0, 0))
461 if (ins_cap (newword, word) < 0)
467 for (i = 0; i < m_Trynum; i++)
469 if (isboundarych (m_Try[i]))
472 if (good (newword, 0, 1, 0, 0))
474 if (ins_cap (newword, word) < 0)
483 void ISpellChecker::missingspace (ichar_t *word)
485 ichar_t firsthalf[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN];
488 ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN + 1];
492 ichar_t secondhalf[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN];
501 nfirsthalf = icharlen (word);
502 if (nfirsthalf < 3 || nfirsthalf >= INPUTWORDLEN + MAXAFFIXLEN - 1)
504 icharcpy (newword + 1, word);
505 for (p = newword + 1; p[1] !=
'\0'; p++)
509 if (good (newword, 0, 1, 0, 0))
518 nfirsthalf = save_cap (newword, word, firsthalf);
519 if (good (p + 1, 0, 1, 0, 0))
521 nsecondhalf = save_cap (p + 1, p + 1, secondhalf);
522 for (firstno = 0; firstno < nfirsthalf; firstno++)
524 firstp = &firsthalf[firstno][p - newword];
525 for (secondno = 0; secondno < nsecondhalf; secondno++)
528 icharcpy (firstp + 1, secondhalf[secondno]);
529 if (insert (firsthalf[firstno]) < 0)
532 if (insert (firsthalf[firstno]) < 0)
546 ISpellChecker::compoundgood (ichar_t *word,
int pfxopts)
548 ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN];
556 if (m_hashheader.compoundflag == COMPOUND_NEVER)
569 if (icharlen (word) < 2 * m_hashheader.compoundmin)
571 icharcpy (newword, word);
572 p = newword + m_hashheader.compoundmin;
573 for ( ; p[m_hashheader.compoundmin - 1] != 0; p++)
577 if (good (newword, 0, 0, pfxopts, FF_COMPOUNDONLY))
580 if (good (p, 0, 1, FF_COMPOUNDONLY, 0)
581 || compoundgood (p, FF_COMPOUNDONLY))
583 secondcap = whatcap (p);
584 switch (whatcap (newword))
589 return secondcap == ANYCASE;
591 return secondcap == ALLCAPS;
605 ISpellChecker::transposedletter (ichar_t *word)
607 ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN];
611 icharcpy (newword, word);
612 for (p = newword; p[1] != 0; p++)
617 if (good (newword, 0, 1, 0, 0))
619 if (ins_cap (newword, word) < 0)
637 ISpellChecker::ins_cap (ichar_t *word, ichar_t *pattern)
641 ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN];
643 nsaved = save_cap (word, pattern, savearea);
644 for (i = 0; i < nsaved; i++)
646 if (insert (savearea[i]) < 0)
662 ISpellChecker::save_cap (ichar_t *word, ichar_t *pattern,
663 ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN])
675 for (hitno = m_numhits, nsaved = 0; --hitno >= 0 && nsaved < MAX_CAPS; )
677 if (m_hits[hitno].prefix)
679 prestrip = m_hits[hitno].prefix->stripl;
680 preadd = m_hits[hitno].prefix->affl;
683 prestrip = preadd = 0;
684 if (m_hits[hitno].suffix)
686 sufstrip = m_hits[hitno].suffix->stripl;
687 sufadd = m_hits[hitno].suffix->affl;
690 sufadd = sufstrip = 0;
691 save_root_cap (word, pattern, prestrip, preadd,
693 m_hits[hitno].dictent, m_hits[hitno].prefix, m_hits[hitno].suffix,
713 ISpellChecker::ins_root_cap (ichar_t *word, ichar_t *pattern,
714 int prestrip,
int preadd,
int sufstrip,
int sufadd,
715 struct dent *firstdent,
struct flagent *pfxent,
struct flagent *sufent)
718 ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN];
722 save_root_cap (word, pattern, prestrip, preadd, sufstrip, sufadd,
723 firstdent, pfxent, sufent, savearea, &nsaved);
724 for (i = 0; i < nsaved; i++)
726 if (insert (savearea[i]) < 0)
747 ISpellChecker::save_root_cap (ichar_t *word, ichar_t *pattern,
748 int prestrip,
int preadd,
int sufstrip,
int sufadd,
749 struct dent *firstdent,
struct flagent *pfxent,
struct flagent *sufent,
750 ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN],
753 #ifndef NO_CAPITALIZATION_SUPPORT
757 ichar_t newword[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4];
758 #ifndef NO_CAPITALIZATION_SUPPORT
765 if (*nsaved >= MAX_CAPS)
767 icharcpy (newword, word);
768 firstisupper = myupper (pattern[0]);
769 #ifdef NO_CAPITALIZATION_SUPPORT
775 if (myupper (pattern[1]))
780 newword[0] = mytoupper (newword[0]);
785 icharcpy (savearea[*nsaved], newword);
789 #define flagsareok(dent) \
791 || TSTMASKBIT (dent->mask, pfxent->flagbit)) \
793 || TSTMASKBIT (dent->mask, sufent->flagbit)))
796 if ((dent->flagfield & (CAPTYPEMASK | MOREVARIANTS)) == ALLCAPS)
799 icharcpy (savearea[*nsaved], newword);
803 for (p = pattern; *p; p++)
811 icharcpy (savearea[*nsaved], newword);
815 for (p = pattern + 1; *p; p++)
828 if (captype (dent->flagfield) == CAPITALIZED
829 || captype (dent->flagfield) == ANYCASE)
832 newword[0] = mytoupper (newword[0]);
833 icharcpy (savearea[*nsaved], newword);
840 if (captype (dent->flagfield) == ANYCASE)
843 icharcpy (savearea[*nsaved], newword);
848 while (dent->flagfield & MOREVARIANTS)
851 if (captype (dent->flagfield) == FOLLOWCASE
852 || !flagsareok (dent))
856 if (captype (dent->flagfield) == CAPITALIZED)
859 newword[0] = mytoupper (newword[0]);
860 icharcpy (savearea[*nsaved], newword);
867 if (captype (dent->flagfield) == ANYCASE)
870 icharcpy (savearea[*nsaved], newword);
885 p = strtosichar (dent->word, 1);
887 if (dent->flagfield & MOREVARIANTS)
891 if (flagsareok (dent))
893 if (captype (dent->flagfield) != FOLLOWCASE)
896 if (firstisupper || captype (dent->flagfield) == CAPITALIZED)
897 newword[0] = mytoupper (newword[0]);
898 icharcpy (savearea[*nsaved], newword);
900 if (*nsaved >= MAX_CAPS)
906 p = strtosichar (dent->word, 1);
908 reinterpret_cast<char *
>(newword + preadd),
909 reinterpret_cast<char *
>(p + prestrip),
910 (len - prestrip - sufstrip) *
sizeof (ichar_t));
911 if (myupper (p[prestrip]))
913 for (i = 0; i < preadd; i++)
914 newword[i] = mytoupper (newword[i]);
918 for (i = 0; i < preadd; i++)
919 newword[i] = mytolower (newword[i]);
921 limit = len + preadd + sufadd - prestrip - sufstrip;
922 i = len + preadd - prestrip - sufstrip;
923 p += len - sufstrip - 1;
926 for (p = newword + i; i < limit; i++, p++)
931 for (p = newword + i; i < limit; i++, p++)
934 icharcpy (savearea[*nsaved], newword);
936 if (*nsaved >= MAX_CAPS)
940 if ((dent->flagfield & MOREVARIANTS) == 0)