229 #include "ispell_checker.h"
242 void ISpellChecker::chk_aff (ichar_t *word, ichar_t *ucword,
243 int len,
int ignoreflagbits,
int allhits,
int pfxopts,
int sfxopts)
246 struct flagptr * ind;
248 pfx_list_chk (word, ucword, len, pfxopts, sfxopts, &m_pflagindex[0],
249 ignoreflagbits, allhits);
252 if (*cp >= (SET_SIZE + MAXSTRINGCHARS))
254 ind = &m_pflagindex[*cp++];
255 while (ind->numents == 0 && ind->pu.fp != NULL)
259 if (ind->pu.fp[0].numents)
261 pfx_list_chk (word, ucword, len, pfxopts, sfxopts, &ind->pu.fp[0],
262 ignoreflagbits, allhits);
263 if (m_numhits && !allhits && !ignoreflagbits)
267 if (*cp >= (SET_SIZE + MAXSTRINGCHARS))
269 ind = &ind->pu.fp[*cp++];
271 pfx_list_chk (word, ucword, len, pfxopts, sfxopts, ind, ignoreflagbits,
273 if (m_numhits && !allhits && !ignoreflagbits)
275 chk_suf (word, ucword, len, sfxopts,
static_cast<struct flagent *
>(NULL),
276 ignoreflagbits, allhits);
291 void ISpellChecker::pfx_list_chk (ichar_t *word, ichar_t *ucword,
int len,
int optflags,
292 int sfxopts,
struct flagptr * ind,
int ignoreflagbits,
int allhits)
302 ichar_t tword[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4];
303 ichar_t tword2[
sizeof tword];
305 for (flent = ind->pu.ent, entcount = ind->numents;
313 if ((flent->flagflags & FF_COMPOUNDONLY) != 0
314 && (optflags & FF_COMPOUNDONLY) == 0)
320 tlen = len - flent->affl;
323 || icharncmp (flent->affix, ucword, flent->affl) == 0)
324 && tlen + flent->stripl >= flent->numconds)
331 icharcpy (tword, flent->strip);
332 icharcpy (tword + flent->stripl, ucword + flent->affl);
334 for (cond = 0; cond < flent->numconds; cond++)
336 if ((flent->conds[*cp++] & (1 << cond)) == 0)
339 if (cond >= flent->numconds)
345 tlen += flent->stripl;
349 if ((dent = ispell_lookup (tword, 1)) != NULL)
354 icharcpy (cp, flent->affix);
358 preadd = cp - tword2;
359 icharcpy (cp, tword);
364 icharcpy (cp, flent->strip);
368 else if ((dent = ispell_lookup (tword, 1)) != NULL
369 && TSTMASKBIT (dent->mask, flent->flagbit))
371 if (m_numhits < MAX_HITS)
373 m_hits[m_numhits].dictent = dent;
374 m_hits[m_numhits].prefix = flent;
375 m_hits[m_numhits].suffix = NULL;
380 #ifndef NO_CAPITALIZATION_SUPPORT
381 if (cap_ok (word, &m_hits[0], len))
392 if (flent->flagflags & FF_CROSSPRODUCT)
393 chk_suf (word, tword, tlen, sfxopts | FF_CROSSPRODUCT,
394 flent, ignoreflagbits, allhits);
412 ISpellChecker::chk_suf (ichar_t *word, ichar_t *ucword,
413 int len,
int optflags,
struct flagent *pfxent,
414 int ignoreflagbits,
int allhits)
417 struct flagptr * ind;
419 suf_list_chk (word, ucword, len, &m_sflagindex[0], optflags, pfxent,
420 ignoreflagbits, allhits);
421 cp = ucword + len - 1;
423 if (*cp >= (SET_SIZE + MAXSTRINGCHARS))
425 ind = &m_sflagindex[*cp];
426 while (ind->numents == 0 && ind->pu.fp != NULL)
430 if (ind->pu.fp[0].numents)
432 suf_list_chk (word, ucword, len, &ind->pu.fp[0],
433 optflags, pfxent, ignoreflagbits, allhits);
434 if (m_numhits != 0 && !allhits && !ignoreflagbits)
438 if (*(cp-1) >= (SET_SIZE + MAXSTRINGCHARS))
440 ind = &ind->pu.fp[*--cp];
442 suf_list_chk (word, ucword, len, ind, optflags, pfxent,
443 ignoreflagbits, allhits);
456 void ISpellChecker::suf_list_chk (ichar_t *word, ichar_t *ucword,
457 int len,
struct flagptr *ind,
int optflags,
458 struct flagent *pfxent,
int ignoreflagbits,
int allhits)
468 ichar_t tword[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4];
469 ichar_t tword2[
sizeof tword];
471 icharcpy (tword, ucword);
472 for (flent = ind->pu.ent, entcount = ind->numents;
476 if ((optflags & FF_CROSSPRODUCT) != 0
477 && (flent->flagflags & FF_CROSSPRODUCT) == 0)
483 if ((flent->flagflags & FF_COMPOUNDONLY) != 0
484 && (optflags & FF_COMPOUNDONLY) == 0)
490 tlen = len - flent->affl;
493 || icharcmp (flent->affix, ucword + tlen) == 0)
494 && tlen + flent->stripl >= flent->numconds)
500 icharcpy (tword, ucword);
504 icharcpy (cp, flent->strip);
505 tlen += flent->stripl;
510 for (cond = flent->numconds; --cond >= 0; )
512 if ((flent->conds[*--cp] & (1 << cond)) == 0)
523 if ((dent = ispell_lookup (tword, 1)) != NULL)
526 if ((optflags & FF_CROSSPRODUCT)
527 && pfxent->affl != 0)
529 icharcpy (cp, pfxent->affix);
533 preadd = cp - tword2;
534 icharcpy (cp, tword);
536 if ((optflags & FF_CROSSPRODUCT)
537 && pfxent->stripl != 0)
540 icharcpy (cp, pfxent->strip);
541 cp += pfxent->stripl;
546 icharcpy (cp, flent->strip);
552 icharcpy (cp, flent->affix);
557 else if ((dent = ispell_lookup (tword, 1)) != NULL
558 && TSTMASKBIT (dent->mask, flent->flagbit)
559 && ((optflags & FF_CROSSPRODUCT) == 0
560 || TSTMASKBIT (dent->mask, pfxent->flagbit)))
562 if (m_numhits < MAX_HITS)
564 m_hits[m_numhits].dictent = dent;
565 m_hits[m_numhits].prefix = pfxent;
566 m_hits[m_numhits].suffix = flent;
571 #ifndef NO_CAPITALIZATION_SUPPORT
572 if (cap_ok (word, &m_hits[0], len))
596 int ISpellChecker::expand_pre (
char *croot, ichar_t *rootword, MASKTYPE mask[],
597 int option,
char *extra)
604 for (flent = m_pflaglist, entcount = m_numpflags, explength = 0;
608 if (TSTMASKBIT (mask, flent->flagbit))
610 pr_pre_expansion (croot, rootword, flent, mask, option, extra);
627 int ISpellChecker::pr_pre_expansion (
char *croot, ichar_t *rootword,
628 struct flagent *flent, MASKTYPE mask[],
int option,
634 ichar_t tword[INPUTWORDLEN + MAXAFFIXLEN];
636 tlen = icharlen (rootword);
637 if (flent->numconds > tlen)
639 tlen -= flent->stripl;
643 for (cond = 0, nextc = rootword; cond < flent->numconds; cond++)
645 if ((flent->conds[mytoupper (*nextc++)] & (1 << cond)) == 0)
663 icharcpy (tword, flent->affix);
664 nextc = tword + flent->affl;
666 icharcpy (nextc, rootword + flent->stripl);
667 if (myupper (rootword[0]))
670 for (nextc = rootword + 1; *nextc; nextc++)
672 if (!myupper (*nextc))
678 for ( ; *nextc; nextc++)
680 if (myupper (*nextc))
686 if (!myupper (tword[flent->affl]))
687 forcelc (tword, flent->affl);
692 forcelc (tword + 1, tlen - 1);
699 if (!myupper (*nextc))
700 forcelc (tword, flent->affl);
703 printf (
"\n%s", croot);
705 printf (
" %s%s", ichartosstr (tword, 1), extra);
706 if (flent->flagflags & FF_CROSSPRODUCT)
708 + expand_suf (croot, tword, mask, FF_CROSSPRODUCT, option, extra);
725 int ISpellChecker::expand_suf (
char *croot, ichar_t *rootword, MASKTYPE mask[],
726 int optflags,
int option,
char *extra)
733 for (flent = m_sflaglist, entcount = m_numsflags, explength = 0;
737 if (TSTMASKBIT (mask, flent->flagbit))
739 if ((optflags & FF_CROSSPRODUCT) == 0
740 || (flent->flagflags & FF_CROSSPRODUCT))
742 pr_suf_expansion (croot, rootword, flent, option, extra);
759 int ISpellChecker::pr_suf_expansion (
char *croot, ichar_t *rootword,
760 struct flagent *flent,
int option,
char *extra)
765 ichar_t tword[INPUTWORDLEN + MAXAFFIXLEN];
767 tlen = icharlen (rootword);
768 cond = flent->numconds;
771 if (tlen - flent->stripl <= 0)
773 for (nextc = rootword + tlen; --cond >= 0; )
775 if ((flent->conds[mytoupper (*--nextc)] & (1 << cond)) == 0)
783 icharcpy (tword, rootword);
784 nextc = tword + tlen - flent->stripl;
787 icharcpy (nextc, flent->affix);
788 if (!myupper (nextc[-1]))
789 forcelc (nextc, flent->affl);
794 printf (
"\n%s", croot);
796 printf (
" %s%s", ichartosstr (tword, 1), extra);
797 return tlen + flent->affl - flent->stripl;
804 void ISpellChecker::forcelc (ichar_t *dst,
int len)
807 for ( ; --len >= 0; dst++)
808 *dst = mytolower (*dst);