static char *strlwr(char *s) { for (; *s; s++) *s = mylower(*s); return s; }
/* * \param a * \param b * \param canonical NZ for canonical string chars * * \return */ int ISpellChecker::casecmp (char *a, char *b, int canonical) { register ichar_t * ap; register ichar_t * bp; ichar_t inta[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4]; ichar_t intb[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4]; strtoichar (inta, a, sizeof inta, canonical); strtoichar (intb, b, sizeof intb, canonical); for (ap = inta, bp = intb; *ap != 0; ap++, bp++) { if (*ap != *bp) { if (*bp == '\0') return m_hashheader.sortorder[*ap]; else if (mylower (*ap)) { if (mylower (*bp) || mytoupper (*ap) != *bp) return static_cast<int>(m_hashheader.sortorder[*ap]) - static_cast<int>(m_hashheader.sortorder[*bp]); } else { if (myupper (*bp) || mytolower (*ap) != *bp) return static_cast<int>(m_hashheader.sortorder[*ap]) - static_cast<int>(m_hashheader.sortorder[*bp]); } } } if (*bp != '\0') return -static_cast<int>(m_hashheader.sortorder[*bp]); for (ap = inta, bp = intb; *ap; ap++, bp++) { if (*ap != *bp) { return static_cast<int>(m_hashheader.sortorder[*ap]) - static_cast<int>(m_hashheader.sortorder[*bp]); } } return 0; }
/*! ** Classify the capitalization of a sample entry. Returns one of the ** four capitalization codes ANYCASE, ALLCAPS, CAPITALIZED, or FOLLOWCASE. ** ** \param word ** ** \return */ long ISpellChecker::whatcap (ichar_t *word) { register ichar_t * p; for (p = word; *p; p++) { if (mylower (*p)) break; } if (*p == '\0') return ALLCAPS; else { for ( ; *p; p++) { if (myupper (*p)) break; } if (*p == '\0') { /* ** No uppercase letters follow the lowercase ones. ** If there is more than one uppercase letter, it's ** "followcase". If only the first one is capitalized, ** it's "capitalize". If there are no capitals ** at all, it's ANYCASE. */ if (myupper (word[0])) { for (p = word + 1; *p != '\0'; p++) { if (myupper (*p)) return FOLLOWCASE; } return CAPITALIZED; } else return ANYCASE; } else return FOLLOWCASE; /* .../lower/upper */ } }
/*! * \param word Word to be saved * \param pattern Capitalization pattern * \param prestrip No. chars stripped from front * \param preadd No. chars added to front of root * \param sufstrip No. chars stripped from back * \param sufadd No. chars added to back of root * \param firstdent First dent for root * \param pfxent Pfx-flag entry for word * \param sufent Sfx-flag entry for word * \param savearea Room to save words * \param nsaved Number saved so far (updated) */ void ISpellChecker::save_root_cap (ichar_t *word, ichar_t *pattern, int prestrip, int preadd, int sufstrip, int sufadd, struct dent *firstdent, struct flagent *pfxent, struct flagent *sufent, ichar_t savearea[MAX_CAPS][INPUTWORDLEN + MAXAFFIXLEN], int * nsaved) { #ifndef NO_CAPITALIZATION_SUPPORT register struct dent * dent; #endif /* NO_CAPITALIZATION_SUPPORT */ int firstisupper; ichar_t newword[INPUTWORDLEN + 4 * MAXAFFIXLEN + 4]; #ifndef NO_CAPITALIZATION_SUPPORT register ichar_t * p; int len; int i; int limit; #endif /* NO_CAPITALIZATION_SUPPORT */ if (*nsaved >= MAX_CAPS) return; icharcpy (newword, word); firstisupper = myupper (pattern[0]); #ifdef NO_CAPITALIZATION_SUPPORT /* ** Apply the old, simple-minded capitalization rules. */ if (firstisupper) { if (myupper (pattern[1])) upcase (newword); else { lowcase (newword); newword[0] = mytoupper (newword[0]); } } else lowcase (newword); icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; #else /* NO_CAPITALIZATION_SUPPORT */ #define flagsareok(dent) \ ((pfxent == NULL \ || TSTMASKBIT (dent->mask, pfxent->flagbit)) \ && (sufent == NULL \ || TSTMASKBIT (dent->mask, sufent->flagbit))) dent = firstdent; if ((dent->flagfield & (CAPTYPEMASK | MOREVARIANTS)) == ALLCAPS) { upcase (newword); /* Uppercase required */ icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } for (p = pattern; *p; p++) { if (mylower (*p)) break; } if (*p == 0) { upcase (newword); /* Pattern was all caps */ icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } for (p = pattern + 1; *p; p++) { if (myupper (*p)) break; } if (*p == 0) { /* ** The pattern was all-lower or capitalized. If that's ** legal, insert only that version. */ if (firstisupper) { if (captype (dent->flagfield) == CAPITALIZED || captype (dent->flagfield) == ANYCASE) { lowcase (newword); newword[0] = mytoupper (newword[0]); icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } } else { if (captype (dent->flagfield) == ANYCASE) { lowcase (newword); icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } } while (dent->flagfield & MOREVARIANTS) { dent = dent->next; if (captype (dent->flagfield) == FOLLOWCASE || !flagsareok (dent)) continue; if (firstisupper) { if (captype (dent->flagfield) == CAPITALIZED) { lowcase (newword); newword[0] = mytoupper (newword[0]); icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } } else { if (captype (dent->flagfield) == ANYCASE) { lowcase (newword); icharcpy (savearea[*nsaved], newword); (*nsaved)++; return; } } } } /* ** Either the sample had complex capitalization, or the simple ** capitalizations (all-lower or capitalized) are illegal. ** Insert all legal capitalizations, including those that are ** all-lower or capitalized. If the prototype is capitalized, ** capitalized all-lower samples. Watch out for affixes. */ dent = firstdent; p = strtosichar (dent->word, 1); len = icharlen (p); if (dent->flagfield & MOREVARIANTS) dent = dent->next; /* Skip place-holder entry */ for ( ; ; ) { if (flagsareok (dent)) { if (captype (dent->flagfield) != FOLLOWCASE) { lowcase (newword); if (firstisupper || captype (dent->flagfield) == CAPITALIZED) newword[0] = mytoupper (newword[0]); icharcpy (savearea[*nsaved], newword); (*nsaved)++; if (*nsaved >= MAX_CAPS) return; } else { /* Followcase is the tough one. */ p = strtosichar (dent->word, 1); memmove ( reinterpret_cast<char *>(newword + preadd), reinterpret_cast<char *>(p + prestrip), (len - prestrip - sufstrip) * sizeof (ichar_t)); if (myupper (p[prestrip])) { for (i = 0; i < preadd; i++) newword[i] = mytoupper (newword[i]); } else { for (i = 0; i < preadd; i++) newword[i] = mytolower (newword[i]); } limit = len + preadd + sufadd - prestrip - sufstrip; i = len + preadd - prestrip - sufstrip; p += len - sufstrip - 1; if (myupper (*p)) { for (p = newword + i; i < limit; i++, p++) *p = mytoupper (*p); } else { for (p = newword + i; i < limit; i++, p++) *p = mytolower (*p); } icharcpy (savearea[*nsaved], newword); (*nsaved)++; if (*nsaved >= MAX_CAPS) return; } } if ((dent->flagfield & MOREVARIANTS) == 0) break; /* End of the line */ dent = dent->next; } return; #endif /* NO_CAPITALIZATION_SUPPORT */ }
/*! * \param wchars Characters in -w option, if any */ void ISpellChecker::initckch(char *wchars) { register ichar_t c; char num[4]; for(c = 0; c < static_cast< ichar_t >(SET_SIZE + m_hashheader.nstrchars); ++c) { if(iswordch(c)) { if(!mylower(c)) { m_Try[m_Trynum] = c; ++m_Trynum; } } else if(isboundarych(c)) { m_Try[m_Trynum] = c; ++m_Trynum; } } if(wchars != NULL) { while(m_Trynum < SET_SIZE && *wchars != '\0') { if(*wchars != 'n' && *wchars != '\\') { c = *wchars; ++wchars; } else { ++wchars; num[0] = '\0'; num[1] = '\0'; num[2] = '\0'; num[3] = '\0'; if(isdigit(wchars[0])) { num[0] = wchars[0]; if(isdigit(wchars[1])) { num[1] = wchars[1]; if(isdigit(wchars[2])) num[2] = wchars[2]; } } if(wchars[-1] == 'n') { wchars += strlen(num); c = atoi(num); } else { wchars += strlen(num); c = 0; if(num[0]) c = num[0] - '0'; if(num[1]) { c <<= 3; c += num[1] - '0'; } if(num[2]) { c <<= 3; c += num[2] - '0'; } } } /* c &= NOPARITY;*/ if(!m_hashheader.wordchars[c]) { m_hashheader.wordchars[c] = 1; m_hashheader.sortorder[c] = m_hashheader.sortval++; m_Try[m_Trynum] = c; ++m_Trynum; } } } }
/* * \param word * \param hit * \param len * * \return */ int ISpellChecker::cap_ok(ichar_t *word, struct success *hit, int len) { register ichar_t *dword; register ichar_t *w; register struct dent *dent; ichar_t dentword[INPUTWORDLEN + MAXAFFIXLEN]; int preadd; int prestrip; int sufadd; ichar_t *limit; long thiscap; long dentcap; thiscap = whatcap(word); /* ** All caps is always legal, regardless of affixes. */ preadd = prestrip = sufadd = 0; if(thiscap == ALLCAPS) return 1; else if(thiscap == FOLLOWCASE) { /* Set up some constants for the while(1) loop below */ if(hit->prefix) { preadd = hit->prefix->affl; prestrip = hit->prefix->stripl; } else preadd = prestrip = 0; sufadd = hit->suffix ? hit->suffix->affl : 0; } /* ** Search the variants for one that matches what we have. Note ** that thiscap can't be ALLCAPS, since we already returned ** for that case. */ dent = hit->dictent; for(;;) { dentcap = captype(dent->flagfield); if(dentcap != thiscap) { if(dentcap == ANYCASE && thiscap == CAPITALIZED && entryhasaffixes(dent, hit)) return 1; } else /* captypes match */ { if(thiscap != FOLLOWCASE) { if(entryhasaffixes(dent, hit)) return 1; } else { /* ** Make sure followcase matches exactly. ** Life is made more difficult by the ** possibility of affixes. Start with ** the prefix. */ strtoichar(dentword, dent->word, INPUTWORDLEN, 1); dword = dentword; limit = word + preadd; if(myupper(dword[prestrip])) { for(w = word; w < limit; w++) { if(mylower(*w)) goto doublecontinue; } } else { for(w = word; w < limit; w++) { if(myupper(*w)) goto doublecontinue; } } dword += prestrip; /* Do root part of word */ limit = dword + len - preadd - sufadd; while(dword < limit) { if(*dword++ != *w++) goto doublecontinue; } /* Do suffix */ dword = limit - 1; if(myupper(*dword)) { for(; *w; w++) { if(mylower(*w)) goto doublecontinue; } } else { for(; *w; w++) { if(myupper(*w)) goto doublecontinue; } } /* ** All failure paths go to "doublecontinue," ** so if we get here it must match. */ if(entryhasaffixes(dent, hit)) return 1; doublecontinue:; } } if((dent->flagfield & MOREVARIANTS) == 0) break; dent = dent->next; } /* No matches found */ return 0; }
/* wchars - Characters in -w option, if any * -w: may be used to specify characters other than * alphabetics which may also appear in words */ static void initckch(char *wchars) { register ichar_t c; char num[4]; for (c = 0; c < (ichar_t)(SET_SIZE + hashheader.nstrchars); ++c) { if (iswordch(c)) { if (!mylower(c)) { Try[Trynum] = c; ++Trynum; } } } if (wchars != NULL) { while (Trynum < SET_SIZE && *wchars != '\0') { if (*wchars != 'n' && *wchars != '\\') { c = *wchars; ++wchars; } else { ++wchars; num[0] = '\0'; num[1] = '\0'; num[2] = '\0'; num[3] = '\0'; if (isdigit (wchars[0])) { num[0] = wchars[0]; if (isdigit (wchars[1])) { num[1] = wchars[1]; if (isdigit(wchars[2])) num[2] = wchars[2]; } } if (wchars[-1] == 'n') { wchars += strlen(num); c = atoi(num); } else { wchars += strlen(num); c = 0; if (num[0]) c = num[0] - '0'; if (num[1]) { c <<= 3; c += num[1] - '0'; } if (num[2]) { c <<= 3; c += num[2] - '0'; } } } c &= NOPARITY; if (!hashheader.wordchars[c]) { hashheader.wordchars[c] = 1; hashheader.sortorder[c] = hashheader.sortval++; Try[Trynum] = c; ++Trynum; } } } }