230 #include "ispell_checker.h"
243 void ISpellChecker::chk_aff (ichar_t *word, ichar_t *ucword,
244 int len,
int ignoreflagbits,
int allhits,
int pfxopts,
int sfxopts)
247 struct flagptr * ind;
249 pfx_list_chk (word, ucword, len, pfxopts, sfxopts, &m_pflagindex[0],
250 ignoreflagbits, allhits);
253 if (*cp >= (SET_SIZE + MAXSTRINGCHARS))
255 ind = &m_pflagindex[*cp++];
256 while (ind->numents == 0 && ind->pu.fp != NULL)
260 if (ind->pu.fp[0].numents)
262 pfx_list_chk (word, ucword, len, pfxopts, sfxopts, &ind->pu.fp[0],
263 ignoreflagbits, allhits);
264 if (m_numhits && !allhits && !ignoreflagbits)
268 if (*cp >= (SET_SIZE + MAXSTRINGCHARS))
270 ind = &ind->pu.fp[*cp++];
272 pfx_list_chk (word, ucword, len, pfxopts, sfxopts, ind, ignoreflagbits,
274 if (m_numhits && !allhits && !ignoreflagbits)
276 chk_suf (word, ucword, len, sfxopts, static_cast<struct flagent *>(NULL),
277 ignoreflagbits, allhits);
292 void ISpellChecker::pfx_list_chk (ichar_t *word, ichar_t *ucword,
int len,
int optflags,
293 int sfxopts,
struct flagptr * ind,
int ignoreflagbits,
int allhits)
303 ichar_t tword[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4];
304 ichar_t tword2[
sizeof tword];
306 for (flent = ind->pu.ent, entcount = ind->numents;
314 if ((flent->flagflags & FF_COMPOUNDONLY) != 0
315 && (optflags & FF_COMPOUNDONLY) == 0)
321 tlen = len - flent->affl;
324 || icharncmp (flent->affix, ucword, flent->affl) == 0)
325 && tlen + flent->stripl >= flent->numconds)
332 icharcpy (tword, flent->strip);
333 icharcpy (tword + flent->stripl, ucword + flent->affl);
335 for (cond = 0; cond < flent->numconds; cond++)
337 if ((flent->conds[*cp++] & (1 << cond)) == 0)
340 if (cond >= flent->numconds)
346 tlen += flent->stripl;
350 if ((dent = ispell_lookup (tword, 1)) != NULL)
355 icharcpy (cp, flent->affix);
359 preadd = cp - tword2;
360 icharcpy (cp, tword);
365 icharcpy (cp, flent->strip);
369 else if ((dent = ispell_lookup (tword, 1)) != NULL
370 && TSTMASKBIT (dent->mask, flent->flagbit))
372 if (m_numhits < MAX_HITS)
374 m_hits[m_numhits].dictent = dent;
375 m_hits[m_numhits].prefix = flent;
376 m_hits[m_numhits].suffix = NULL;
381 #ifndef NO_CAPITALIZATION_SUPPORT
382 if (cap_ok (word, &m_hits[0], len))
393 if (flent->flagflags & FF_CROSSPRODUCT)
394 chk_suf (word, tword, tlen, sfxopts | FF_CROSSPRODUCT,
395 flent, ignoreflagbits, allhits);
413 ISpellChecker::chk_suf (ichar_t *word, ichar_t *ucword,
414 int len,
int optflags,
struct flagent *pfxent,
415 int ignoreflagbits,
int allhits)
418 struct flagptr * ind;
420 suf_list_chk (word, ucword, len, &m_sflagindex[0], optflags, pfxent,
421 ignoreflagbits, allhits);
422 cp = ucword + len - 1;
424 if (*cp >= (SET_SIZE + MAXSTRINGCHARS))
426 ind = &m_sflagindex[*cp];
427 while (ind->numents == 0 && ind->pu.fp != NULL)
431 if (ind->pu.fp[0].numents)
433 suf_list_chk (word, ucword, len, &ind->pu.fp[0],
434 optflags, pfxent, ignoreflagbits, allhits);
435 if (m_numhits != 0 && !allhits && !ignoreflagbits)
439 if (*(cp-1) >= (SET_SIZE + MAXSTRINGCHARS))
441 ind = &ind->pu.fp[*--cp];
443 suf_list_chk (word, ucword, len, ind, optflags, pfxent,
444 ignoreflagbits, allhits);
457 void ISpellChecker::suf_list_chk (ichar_t *word, ichar_t *ucword,
458 int len,
struct flagptr *ind,
int optflags,
459 struct flagent *pfxent,
int ignoreflagbits,
int allhits)
469 ichar_t tword[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4];
470 ichar_t tword2[
sizeof tword];
472 icharcpy (tword, ucword);
473 for (flent = ind->pu.ent, entcount = ind->numents;
477 if ((optflags & FF_CROSSPRODUCT) != 0
478 && (flent->flagflags & FF_CROSSPRODUCT) == 0)
484 if ((flent->flagflags & FF_COMPOUNDONLY) != 0
485 && (optflags & FF_COMPOUNDONLY) == 0)
491 tlen = len - flent->affl;
494 || icharcmp (flent->affix, ucword + tlen) == 0)
495 && tlen + flent->stripl >= flent->numconds)
501 icharcpy (tword, ucword);
505 icharcpy (cp, flent->strip);
506 tlen += flent->stripl;
511 for (cond = flent->numconds; --cond >= 0; )
513 if ((flent->conds[*--cp] & (1 << cond)) == 0)
524 if ((dent = ispell_lookup (tword, 1)) != NULL)
527 if ((optflags & FF_CROSSPRODUCT)
528 && pfxent->affl != 0)
530 icharcpy (cp, pfxent->affix);
534 preadd = cp - tword2;
535 icharcpy (cp, tword);
537 if ((optflags & FF_CROSSPRODUCT)
538 && pfxent->stripl != 0)
541 icharcpy (cp, pfxent->strip);
542 cp += pfxent->stripl;
547 icharcpy (cp, flent->strip);
553 icharcpy (cp, flent->affix);
558 else if ((dent = ispell_lookup (tword, 1)) != NULL
559 && TSTMASKBIT (dent->mask, flent->flagbit)
560 && ((optflags & FF_CROSSPRODUCT) == 0
561 || TSTMASKBIT (dent->mask, pfxent->flagbit)))
563 if (m_numhits < MAX_HITS)
565 m_hits[m_numhits].dictent = dent;
566 m_hits[m_numhits].prefix = pfxent;
567 m_hits[m_numhits].suffix = flent;
572 #ifndef NO_CAPITALIZATION_SUPPORT
573 if (cap_ok (word, &m_hits[0], len))
597 int ISpellChecker::expand_pre (
char *croot, ichar_t *rootword, MASKTYPE mask[],
598 int option,
char *extra)
605 for (flent = m_pflaglist, entcount = m_numpflags, explength = 0;
609 if (TSTMASKBIT (mask, flent->flagbit))
611 pr_pre_expansion (croot, rootword, flent, mask, option, extra);
628 int ISpellChecker::pr_pre_expansion (
char *croot, ichar_t *rootword,
629 struct flagent *flent, MASKTYPE mask[],
int option,
635 ichar_t tword[INPUTWORDLEN + MAXAFFIXLEN];
637 tlen = icharlen (rootword);
638 if (flent->numconds > tlen)
640 tlen -= flent->stripl;
644 for (cond = 0, nextc = rootword; cond < flent->numconds; cond++)
646 if ((flent->conds[mytoupper (*nextc++)] & (1 << cond)) == 0)
664 icharcpy (tword, flent->affix);
665 nextc = tword + flent->affl;
667 icharcpy (nextc, rootword + flent->stripl);
668 if (myupper (rootword[0]))
671 for (nextc = rootword + 1; *nextc; nextc++)
673 if (!myupper (*nextc))
679 for ( ; *nextc; nextc++)
681 if (myupper (*nextc))
687 if (!myupper (tword[flent->affl]))
688 forcelc (tword, flent->affl);
693 forcelc (tword + 1, tlen - 1);
700 if (!myupper (*nextc))
701 forcelc (tword, flent->affl);
704 printf (
"\n%s", croot);
706 printf (
" %s%s", ichartosstr (tword, 1), extra);
707 if (flent->flagflags & FF_CROSSPRODUCT)
709 + expand_suf (croot, tword, mask, FF_CROSSPRODUCT, option, extra);
726 int ISpellChecker::expand_suf (
char *croot, ichar_t *rootword, MASKTYPE mask[],
727 int optflags,
int option,
char *extra)
734 for (flent = m_sflaglist, entcount = m_numsflags, explength = 0;
738 if (TSTMASKBIT (mask, flent->flagbit))
740 if ((optflags & FF_CROSSPRODUCT) == 0
741 || (flent->flagflags & FF_CROSSPRODUCT))
743 pr_suf_expansion (croot, rootword, flent, option, extra);
760 int ISpellChecker::pr_suf_expansion (
char *croot, ichar_t *rootword,
761 struct flagent *flent,
int option,
char *extra)
766 ichar_t tword[INPUTWORDLEN + MAXAFFIXLEN];
768 tlen = icharlen (rootword);
769 cond = flent->numconds;
772 if (tlen - flent->stripl <= 0)
774 for (nextc = rootword + tlen; --cond >= 0; )
776 if ((flent->conds[mytoupper (*--nextc)] & (1 << cond)) == 0)
784 icharcpy (tword, rootword);
785 nextc = tword + tlen - flent->stripl;
788 icharcpy (nextc, flent->affix);
789 if (!myupper (nextc[-1]))
790 forcelc (nextc, flent->affl);
795 printf (
"\n%s", croot);
797 printf (
" %s%s", ichartosstr (tword, 1), extra);
798 return tlen + flent->affl - flent->stripl;
805 void ISpellChecker::forcelc (ichar_t *dst,
int len)
808 for ( ; --len >= 0; dst++)
809 *dst = mytolower (*dst);