00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 #include <ctype.h>
00227 #include <stdlib.h>
00228 #include <string.h>
00229
00230 #include "ispell_checker.h"
00231
00243 void ISpellChecker::chk_aff (ichar_t *word, ichar_t *ucword,
00244 int len, int ignoreflagbits, int allhits, int pfxopts, int sfxopts)
00245 {
00246 register ichar_t * cp;
00247 struct flagptr * ind;
00248
00249 pfx_list_chk (word, ucword, len, pfxopts, sfxopts, &m_pflagindex[0],
00250 ignoreflagbits, allhits);
00251 cp = ucword;
00252
00253 if (*cp >= (SET_SIZE + MAXSTRINGCHARS))
00254 return;
00255 ind = &m_pflagindex[*cp++];
00256 while (ind->numents == 0 && ind->pu.fp != NULL)
00257 {
00258 if (*cp == 0)
00259 return;
00260 if (ind->pu.fp[0].numents)
00261 {
00262 pfx_list_chk (word, ucword, len, pfxopts, sfxopts, &ind->pu.fp[0],
00263 ignoreflagbits, allhits);
00264 if (m_numhits && !allhits && !ignoreflagbits)
00265 return;
00266 }
00267
00268 if (*cp >= (SET_SIZE + MAXSTRINGCHARS))
00269 return;
00270 ind = &ind->pu.fp[*cp++];
00271 }
00272 pfx_list_chk (word, ucword, len, pfxopts, sfxopts, ind, ignoreflagbits,
00273 allhits);
00274 if (m_numhits && !allhits && !ignoreflagbits)
00275 return;
00276 chk_suf (word, ucword, len, sfxopts, static_cast<struct flagent *>(NULL),
00277 ignoreflagbits, allhits);
00278 }
00279
00292 void ISpellChecker::pfx_list_chk (ichar_t *word, ichar_t *ucword, int len, int optflags,
00293 int sfxopts, struct flagptr * ind, int ignoreflagbits, int allhits)
00294 {
00295 int cond;
00296 register ichar_t * cp;
00297 struct dent * dent;
00298 int entcount;
00299 register struct flagent *
00300 flent;
00301 int preadd;
00302 register int tlen;
00303 ichar_t tword[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4];
00304 ichar_t tword2[sizeof tword];
00305
00306 for (flent = ind->pu.ent, entcount = ind->numents;
00307 entcount > 0;
00308 flent++, entcount--)
00309 {
00310
00311
00312
00313
00314 if ((flent->flagflags & FF_COMPOUNDONLY) != 0
00315 && (optflags & FF_COMPOUNDONLY) == 0)
00316 continue;
00317
00318
00319
00320
00321 tlen = len - flent->affl;
00322 if (tlen > 0
00323 && (flent->affl == 0
00324 || icharncmp (flent->affix, ucword, flent->affl) == 0)
00325 && tlen + flent->stripl >= flent->numconds)
00326 {
00327
00328
00329
00330
00331 if (flent->stripl)
00332 icharcpy (tword, flent->strip);
00333 icharcpy (tword + flent->stripl, ucword + flent->affl);
00334 cp = tword;
00335 for (cond = 0; cond < flent->numconds; cond++)
00336 {
00337 if ((flent->conds[*cp++] & (1 << cond)) == 0)
00338 break;
00339 }
00340 if (cond >= flent->numconds)
00341 {
00342
00343
00344
00345
00346 tlen += flent->stripl;
00347
00348 if (ignoreflagbits)
00349 {
00350 if ((dent = ispell_lookup (tword, 1)) != NULL)
00351 {
00352 cp = tword2;
00353 if (flent->affl)
00354 {
00355 icharcpy (cp, flent->affix);
00356 cp += flent->affl;
00357 *cp++ = '+';
00358 }
00359 preadd = cp - tword2;
00360 icharcpy (cp, tword);
00361 cp += tlen;
00362 if (flent->stripl)
00363 {
00364 *cp++ = '-';
00365 icharcpy (cp, flent->strip);
00366 }
00367 }
00368 }
00369 else if ((dent = ispell_lookup (tword, 1)) != NULL
00370 && TSTMASKBIT (dent->mask, flent->flagbit))
00371 {
00372 if (m_numhits < MAX_HITS)
00373 {
00374 m_hits[m_numhits].dictent = dent;
00375 m_hits[m_numhits].prefix = flent;
00376 m_hits[m_numhits].suffix = NULL;
00377 m_numhits++;
00378 }
00379 if (!allhits)
00380 {
00381 #ifndef NO_CAPITALIZATION_SUPPORT
00382 if (cap_ok (word, &m_hits[0], len))
00383 return;
00384 m_numhits = 0;
00385 #else
00386 return;
00387 #endif
00388 }
00389 }
00390
00391
00392
00393 if (flent->flagflags & FF_CROSSPRODUCT)
00394 chk_suf (word, tword, tlen, sfxopts | FF_CROSSPRODUCT,
00395 flent, ignoreflagbits, allhits);
00396 }
00397 }
00398 }
00399 }
00400
00412 void
00413 ISpellChecker::chk_suf (ichar_t *word, ichar_t *ucword,
00414 int len, int optflags, struct flagent *pfxent,
00415 int ignoreflagbits, int allhits)
00416 {
00417 register ichar_t * cp;
00418 struct flagptr * ind;
00419
00420 suf_list_chk (word, ucword, len, &m_sflagindex[0], optflags, pfxent,
00421 ignoreflagbits, allhits);
00422 cp = ucword + len - 1;
00423
00424 if (*cp >= (SET_SIZE + MAXSTRINGCHARS))
00425 return;
00426 ind = &m_sflagindex[*cp];
00427 while (ind->numents == 0 && ind->pu.fp != NULL)
00428 {
00429 if (cp == ucword)
00430 return;
00431 if (ind->pu.fp[0].numents)
00432 {
00433 suf_list_chk (word, ucword, len, &ind->pu.fp[0],
00434 optflags, pfxent, ignoreflagbits, allhits);
00435 if (m_numhits != 0 && !allhits && !ignoreflagbits)
00436 return;
00437 }
00438
00439 if (*(cp-1) >= (SET_SIZE + MAXSTRINGCHARS))
00440 return;
00441 ind = &ind->pu.fp[*--cp];
00442 }
00443 suf_list_chk (word, ucword, len, ind, optflags, pfxent,
00444 ignoreflagbits, allhits);
00445 }
00446
00457 void ISpellChecker::suf_list_chk (ichar_t *word, ichar_t *ucword,
00458 int len, struct flagptr *ind, int optflags,
00459 struct flagent *pfxent, int ignoreflagbits, int allhits)
00460 {
00461 register ichar_t * cp;
00462 int cond;
00463 struct dent * dent;
00464 int entcount;
00465 register struct flagent *
00466 flent;
00467 int preadd;
00468 register int tlen;
00469 ichar_t tword[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4];
00470 ichar_t tword2[sizeof tword];
00471
00472 icharcpy (tword, ucword);
00473 for (flent = ind->pu.ent, entcount = ind->numents;
00474 entcount > 0;
00475 flent++, entcount--)
00476 {
00477 if ((optflags & FF_CROSSPRODUCT) != 0
00478 && (flent->flagflags & FF_CROSSPRODUCT) == 0)
00479 continue;
00480
00481
00482
00483
00484 if ((flent->flagflags & FF_COMPOUNDONLY) != 0
00485 && (optflags & FF_COMPOUNDONLY) == 0)
00486 continue;
00487
00488
00489
00490
00491 tlen = len - flent->affl;
00492 if (tlen > 0
00493 && (flent->affl == 0
00494 || icharcmp (flent->affix, ucword + tlen) == 0)
00495 && tlen + flent->stripl >= flent->numconds)
00496 {
00497
00498
00499
00500
00501 icharcpy (tword, ucword);
00502 cp = tword + tlen;
00503 if (flent->stripl)
00504 {
00505 icharcpy (cp, flent->strip);
00506 tlen += flent->stripl;
00507 cp = tword + tlen;
00508 }
00509 else
00510 *cp = '\0';
00511 for (cond = flent->numconds; --cond >= 0; )
00512 {
00513 if ((flent->conds[*--cp] & (1 << cond)) == 0)
00514 break;
00515 }
00516 if (cond < 0)
00517 {
00518
00519
00520
00521
00522 if (ignoreflagbits)
00523 {
00524 if ((dent = ispell_lookup (tword, 1)) != NULL)
00525 {
00526 cp = tword2;
00527 if ((optflags & FF_CROSSPRODUCT)
00528 && pfxent->affl != 0)
00529 {
00530 icharcpy (cp, pfxent->affix);
00531 cp += pfxent->affl;
00532 *cp++ = '+';
00533 }
00534 preadd = cp - tword2;
00535 icharcpy (cp, tword);
00536 cp += tlen;
00537 if ((optflags & FF_CROSSPRODUCT)
00538 && pfxent->stripl != 0)
00539 {
00540 *cp++ = '-';
00541 icharcpy (cp, pfxent->strip);
00542 cp += pfxent->stripl;
00543 }
00544 if (flent->stripl)
00545 {
00546 *cp++ = '-';
00547 icharcpy (cp, flent->strip);
00548 cp += flent->stripl;
00549 }
00550 if (flent->affl)
00551 {
00552 *cp++ = '+';
00553 icharcpy (cp, flent->affix);
00554 cp += flent->affl;
00555 }
00556 }
00557 }
00558 else if ((dent = ispell_lookup (tword, 1)) != NULL
00559 && TSTMASKBIT (dent->mask, flent->flagbit)
00560 && ((optflags & FF_CROSSPRODUCT) == 0
00561 || TSTMASKBIT (dent->mask, pfxent->flagbit)))
00562 {
00563 if (m_numhits < MAX_HITS)
00564 {
00565 m_hits[m_numhits].dictent = dent;
00566 m_hits[m_numhits].prefix = pfxent;
00567 m_hits[m_numhits].suffix = flent;
00568 m_numhits++;
00569 }
00570 if (!allhits)
00571 {
00572 #ifndef NO_CAPITALIZATION_SUPPORT
00573 if (cap_ok (word, &m_hits[0], len))
00574 return;
00575 m_numhits = 0;
00576 #else
00577 return;
00578 #endif
00579 }
00580 }
00581 }
00582 }
00583 }
00584 }
00585
00597 int ISpellChecker::expand_pre (char *croot, ichar_t *rootword, MASKTYPE mask[],
00598 int option, char *extra)
00599 {
00600 int entcount;
00601 int explength;
00602 register struct flagent *
00603 flent;
00604
00605 for (flent = m_pflaglist, entcount = m_numpflags, explength = 0;
00606 entcount > 0;
00607 flent++, entcount--)
00608 {
00609 if (TSTMASKBIT (mask, flent->flagbit))
00610 explength +=
00611 pr_pre_expansion (croot, rootword, flent, mask, option, extra);
00612 }
00613 return explength;
00614 }
00615
00628 int ISpellChecker::pr_pre_expansion ( char *croot, ichar_t *rootword,
00629 struct flagent *flent, MASKTYPE mask[], int option,
00630 char *extra)
00631 {
00632 int cond;
00633 register ichar_t * nextc;
00634 int tlen;
00635 ichar_t tword[INPUTWORDLEN + MAXAFFIXLEN];
00636
00637 tlen = icharlen (rootword);
00638 if (flent->numconds > tlen)
00639 return 0;
00640 tlen -= flent->stripl;
00641 if (tlen <= 0)
00642 return 0;
00643 tlen += flent->affl;
00644 for (cond = 0, nextc = rootword; cond < flent->numconds; cond++)
00645 {
00646 if ((flent->conds[mytoupper (*nextc++)] & (1 << cond)) == 0)
00647 return 0;
00648 }
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662 if (flent->affl)
00663 {
00664 icharcpy (tword, flent->affix);
00665 nextc = tword + flent->affl;
00666 }
00667 icharcpy (nextc, rootword + flent->stripl);
00668 if (myupper (rootword[0]))
00669 {
00670
00671 for (nextc = rootword + 1; *nextc; nextc++)
00672 {
00673 if (!myupper (*nextc))
00674 break;
00675 }
00676 if (*nextc)
00677 {
00678
00679 for ( ; *nextc; nextc++)
00680 {
00681 if (myupper (*nextc))
00682 break;
00683 }
00684 if (*nextc)
00685 {
00686
00687 if (!myupper (tword[flent->affl]))
00688 forcelc (tword, flent->affl);
00689 }
00690 else
00691 {
00692
00693 forcelc (tword + 1, tlen - 1);
00694 }
00695 }
00696 }
00697 else
00698 {
00699
00700 if (!myupper (*nextc))
00701 forcelc (tword, flent->affl);
00702 }
00703 if (option == 3)
00704 printf ("\n%s", croot);
00705 if (option != 4)
00706 printf (" %s%s", ichartosstr (tword, 1), extra);
00707 if (flent->flagflags & FF_CROSSPRODUCT)
00708 return tlen
00709 + expand_suf (croot, tword, mask, FF_CROSSPRODUCT, option, extra);
00710 else
00711 return tlen;
00712 }
00713
00726 int ISpellChecker::expand_suf (char *croot, ichar_t *rootword, MASKTYPE mask[],
00727 int optflags, int option, char *extra)
00728 {
00729 int entcount;
00730 int explength;
00731 register struct flagent *
00732 flent;
00733
00734 for (flent = m_sflaglist, entcount = m_numsflags, explength = 0;
00735 entcount > 0;
00736 flent++, entcount--)
00737 {
00738 if (TSTMASKBIT (mask, flent->flagbit))
00739 {
00740 if ((optflags & FF_CROSSPRODUCT) == 0
00741 || (flent->flagflags & FF_CROSSPRODUCT))
00742 explength +=
00743 pr_suf_expansion (croot, rootword, flent, option, extra);
00744 }
00745 }
00746 return explength;
00747 }
00748
00760 int ISpellChecker::pr_suf_expansion (char *croot, ichar_t *rootword,
00761 struct flagent *flent, int option, char *extra)
00762 {
00763 int cond;
00764 register ichar_t * nextc;
00765 int tlen;
00766 ichar_t tword[INPUTWORDLEN + MAXAFFIXLEN];
00767
00768 tlen = icharlen (rootword);
00769 cond = flent->numconds;
00770 if (cond > tlen)
00771 return 0;
00772 if (tlen - flent->stripl <= 0)
00773 return 0;
00774 for (nextc = rootword + tlen; --cond >= 0; )
00775 {
00776 if ((flent->conds[mytoupper (*--nextc)] & (1 << cond)) == 0)
00777 return 0;
00778 }
00779
00780
00781
00782
00783
00784 icharcpy (tword, rootword);
00785 nextc = tword + tlen - flent->stripl;
00786 if (flent->affl)
00787 {
00788 icharcpy (nextc, flent->affix);
00789 if (!myupper (nextc[-1]))
00790 forcelc (nextc, flent->affl);
00791 }
00792 else
00793 *nextc = 0;
00794 if (option == 3)
00795 printf ("\n%s", croot);
00796 if (option != 4)
00797 printf (" %s%s", ichartosstr (tword, 1), extra);
00798 return tlen + flent->affl - flent->stripl;
00799 }
00800
00805 void ISpellChecker::forcelc (ichar_t *dst, int len)
00806 {
00807
00808 for ( ; --len >= 0; dst++)
00809 *dst = mytolower (*dst);
00810 }