226 #include "ispell_checker.h"
245 ISpellChecker::casecmp (
char *a,
char *b,
int canonical)
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];
252 strtoichar (inta, a,
sizeof inta, canonical);
253 strtoichar (intb, b,
sizeof intb, canonical);
254 for (ap = inta, bp = intb; *ap != 0; ap++, bp++)
259 return m_hashheader.sortorder[*ap];
260 else if (mylower (*ap))
262 if (mylower (*bp) || mytoupper (*ap) != *bp)
263 return static_cast<int>(m_hashheader.sortorder[*ap])
264 - static_cast<int>(m_hashheader.sortorder[*bp]);
268 if (myupper (*bp) || mytolower (*ap) != *bp)
269 return static_cast<int>(m_hashheader.sortorder[*ap])
270 -
static_cast<int>(m_hashheader.sortorder[*bp]);
275 return -
static_cast<int>(m_hashheader.sortorder[*bp]);
276 for (ap = inta, bp = intb; *ap; ap++, bp++)
280 return static_cast<int>(m_hashheader.sortorder[*ap])
281 - static_cast<int>(m_hashheader.sortorder[*bp]);
291 ISpellChecker::makepossibilities (ichar_t *word)
295 for (i = 0; i < MAXPOSSIBLE; i++)
296 m_possibilities[i][0] = 0;
299 m_easypossibilities = 0;
301 #ifndef NO_CAPITALIZATION_SUPPORT
312 if (m_pcount < MAXPOSSIBLE)
313 missingletter (word);
314 if (m_pcount < MAXPOSSIBLE)
315 transposedletter (word);
316 if (m_pcount < MAXPOSSIBLE)
318 if (m_pcount < MAXPOSSIBLE)
321 if ((m_hashheader.compoundflag != COMPOUND_ANYTIME) &&
322 m_pcount < MAXPOSSIBLE)
333 ISpellChecker::insert (ichar_t *word)
336 register char * realword;
338 realword = ichartosstr (word, 0);
339 for (i = 0; i < m_pcount; i++)
341 if (strcmp (m_possibilities[i], realword) == 0)
345 strcpy (m_possibilities[m_pcount++], realword);
346 i = strlen (realword);
347 if (i > m_maxposslen)
349 if (m_pcount >= MAXPOSSIBLE)
355 #ifndef NO_CAPITALIZATION_SUPPORT
360 ISpellChecker::wrongcapital (ichar_t *word)
362 ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN];
369 if (good (word, 0, 1, 0, 0))
371 icharcpy (newword, word);
373 ins_cap (newword, word);
382 ISpellChecker::wrongletter (ichar_t *word)
388 ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN];
391 icharcpy (newword, word);
392 #ifndef NO_CAPITALIZATION_SUPPORT
396 for (i = 0; i < n; i++)
398 savechar = newword[i];
399 for (j=0; j < m_Trynum; ++j)
401 if (m_Try[j] == savechar)
403 else if (isboundarych (m_Try[j]) && (i == 0 || i == n - 1))
405 newword[i] = m_Try[j];
406 if (good (newword, 0, 1, 0, 0))
408 if (ins_cap (newword, word) < 0)
412 newword[i] = savechar;
420 ISpellChecker::extraletter (ichar_t *word)
422 ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN];
423 register ichar_t * p;
424 register ichar_t * r;
426 if (icharlen (word) < 2)
429 icharcpy (newword, word + 1);
430 for (p = word, r = newword; *p != 0; )
432 if (good (newword, 0, 1, 0, 0))
434 if (ins_cap (newword, word) < 0)
445 ISpellChecker::missingletter (ichar_t *word)
447 ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN + 1];
448 register ichar_t * p;
449 register ichar_t * r;
452 icharcpy (newword + 1, word);
453 for (p = word, r = newword; *p != 0; )
455 for (i = 0; i < m_Trynum; i++)
457 if (isboundarych (m_Try[i]) && r == newword)
460 if (good (newword, 0, 1, 0, 0))
462 if (ins_cap (newword, word) < 0)
468 for (i = 0; i < m_Trynum; i++)
470 if (isboundarych (m_Try[i]))
473 if (good (newword, 0, 1, 0, 0))
475 if (ins_cap (newword, word) < 0)
484 void ISpellChecker::missingspace (ichar_t *word)
486 ichar_t firsthalf[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN];
489 ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN + 1];
492 register ichar_t * p;
493 ichar_t secondhalf[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN];
502 nfirsthalf = icharlen (word);
503 if (nfirsthalf < 3 || nfirsthalf >= INPUTWORDLEN + MAXAFFIXLEN - 1)
505 icharcpy (newword + 1, word);
506 for (p = newword + 1; p[1] !=
'\0'; p++)
510 if (good (newword, 0, 1, 0, 0))
519 nfirsthalf = save_cap (newword, word, firsthalf);
520 if (good (p + 1, 0, 1, 0, 0))
522 nsecondhalf = save_cap (p + 1, p + 1, secondhalf);
523 for (firstno = 0; firstno < nfirsthalf; firstno++)
525 firstp = &firsthalf[firstno][p - newword];
526 for (secondno = 0; secondno < nsecondhalf; secondno++)
529 icharcpy (firstp + 1, secondhalf[secondno]);
530 if (insert (firsthalf[firstno]) < 0)
533 if (insert (firsthalf[firstno]) < 0)
547 ISpellChecker::compoundgood (ichar_t *word,
int pfxopts)
549 ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN];
550 register ichar_t * p;
551 register ichar_t savech;
557 if (m_hashheader.compoundflag == COMPOUND_NEVER)
570 if (icharlen (word) < 2 * m_hashheader.compoundmin)
572 icharcpy (newword, word);
573 p = newword + m_hashheader.compoundmin;
574 for ( ; p[m_hashheader.compoundmin - 1] != 0; p++)
578 if (good (newword, 0, 0, pfxopts, FF_COMPOUNDONLY))
581 if (good (p, 0, 1, FF_COMPOUNDONLY, 0)
582 || compoundgood (p, FF_COMPOUNDONLY))
584 secondcap = whatcap (p);
585 switch (whatcap (newword))
590 return secondcap == ANYCASE;
592 return secondcap == ALLCAPS;
606 ISpellChecker::transposedletter (ichar_t *word)
608 ichar_t newword[INPUTWORDLEN + MAXAFFIXLEN];
609 register ichar_t * p;
610 register ichar_t temp;
612 icharcpy (newword, word);
613 for (p = newword; p[1] != 0; p++)
618 if (good (newword, 0, 1, 0, 0))
620 if (ins_cap (newword, word) < 0)
638 ISpellChecker::ins_cap (ichar_t *word, ichar_t *pattern)
642 ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN];
644 nsaved = save_cap (word, pattern, savearea);
645 for (i = 0; i < nsaved; i++)
647 if (insert (savearea[i]) < 0)
663 ISpellChecker::save_cap (ichar_t *word, ichar_t *pattern,
664 ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN])
676 for (hitno = m_numhits, nsaved = 0; --hitno >= 0 && nsaved < MAX_CAPS; )
678 if (m_hits[hitno].prefix)
680 prestrip = m_hits[hitno].prefix->stripl;
681 preadd = m_hits[hitno].prefix->affl;
684 prestrip = preadd = 0;
685 if (m_hits[hitno].suffix)
687 sufstrip = m_hits[hitno].suffix->stripl;
688 sufadd = m_hits[hitno].suffix->affl;
691 sufadd = sufstrip = 0;
692 save_root_cap (word, pattern, prestrip, preadd,
694 m_hits[hitno].dictent, m_hits[hitno].prefix, m_hits[hitno].suffix,
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)
719 ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN];
723 save_root_cap (word, pattern, prestrip, preadd, sufstrip, sufadd,
724 firstdent, pfxent, sufent, savearea, &nsaved);
725 for (i = 0; i < nsaved; i++)
727 if (insert (savearea[i]) < 0)
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],
754 #ifndef NO_CAPITALIZATION_SUPPORT
755 register struct dent * dent;
758 ichar_t newword[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4];
759 #ifndef NO_CAPITALIZATION_SUPPORT
760 register ichar_t * p;
766 if (*nsaved >= MAX_CAPS)
768 icharcpy (newword, word);
769 firstisupper = myupper (pattern[0]);
770 #ifdef NO_CAPITALIZATION_SUPPORT
776 if (myupper (pattern[1]))
781 newword[0] = mytoupper (newword[0]);
786 icharcpy (savearea[*nsaved], newword);
790 #define flagsareok(dent) \
792 || TSTMASKBIT (dent->mask, pfxent->flagbit)) \
794 || TSTMASKBIT (dent->mask, sufent->flagbit)))
797 if ((dent->flagfield & (CAPTYPEMASK | MOREVARIANTS)) == ALLCAPS)
800 icharcpy (savearea[*nsaved], newword);
804 for (p = pattern; *p; p++)
812 icharcpy (savearea[*nsaved], newword);
816 for (p = pattern + 1; *p; p++)
829 if (captype (dent->flagfield) == CAPITALIZED
830 || captype (dent->flagfield) == ANYCASE)
833 newword[0] = mytoupper (newword[0]);
834 icharcpy (savearea[*nsaved], newword);
841 if (captype (dent->flagfield) == ANYCASE)
844 icharcpy (savearea[*nsaved], newword);
849 while (dent->flagfield & MOREVARIANTS)
852 if (captype (dent->flagfield) == FOLLOWCASE
853 || !flagsareok (dent))
857 if (captype (dent->flagfield) == CAPITALIZED)
860 newword[0] = mytoupper (newword[0]);
861 icharcpy (savearea[*nsaved], newword);
868 if (captype (dent->flagfield) == ANYCASE)
871 icharcpy (savearea[*nsaved], newword);
886 p = strtosichar (dent->word, 1);
888 if (dent->flagfield & MOREVARIANTS)
892 if (flagsareok (dent))
894 if (captype (dent->flagfield) != FOLLOWCASE)
897 if (firstisupper || captype (dent->flagfield) == CAPITALIZED)
898 newword[0] = mytoupper (newword[0]);
899 icharcpy (savearea[*nsaved], newword);
901 if (*nsaved >= MAX_CAPS)
907 p = strtosichar (dent->word, 1);
909 reinterpret_cast<char *>(newword + preadd),
910 reinterpret_cast<char *>(p + prestrip),
911 (len - prestrip - sufstrip) *
sizeof (ichar_t));
912 if (myupper (p[prestrip]))
914 for (i = 0; i < preadd; i++)
915 newword[i] = mytoupper (newword[i]);
919 for (i = 0; i < preadd; i++)
920 newword[i] = mytolower (newword[i]);
922 limit = len + preadd + sufadd - prestrip - sufstrip;
923 i = len + preadd - prestrip - sufstrip;
924 p += len - sufstrip - 1;
927 for (p = newword + i; i < limit; i++, p++)
932 for (p = newword + i; i < limit; i++, p++)
935 icharcpy (savearea[*nsaved], newword);
937 if (*nsaved >= MAX_CAPS)
941 if ((dent->flagfield & MOREVARIANTS) == 0)