/*! * Print a prefix expansion * * \param croot Char version of rootword * \param rootword Root word to expand * \param flent Current table entry * \param mask Mask bits to expand on * \param option Option, see expandmode * \param extra Extra info to add to line * * \return */ int ISpellChecker::pr_pre_expansion ( char *croot, ichar_t *rootword, struct flagent *flent, MASKTYPE mask[], int option, char *extra) { int cond; /* Current condition number */ register ichar_t * nextc; /* Next case choice */ int tlen; /* Length of tword */ ichar_t tword[INPUTWORDLEN + MAXAFFIXLEN]; /* Temp */ tlen = icharlen (rootword); if (flent->numconds > tlen) return 0; tlen -= flent->stripl; if (tlen <= 0) return 0; tlen += flent->affl; for (cond = 0, nextc = rootword; cond < flent->numconds; cond++) { if ((flent->conds[mytoupper (*nextc++)] & (1 << cond)) == 0) return 0; } /* * The conditions are satisfied. Copy the word, add the prefix, * and make it the proper case. This code is carefully written * to match that ins_cap and cap_ok. Note that the affix, as * inserted, is uppercase. * * There is a tricky bit here: if the root is capitalized, we * want a capitalized result. If the root is followcase, however, * we want to duplicate the case of the first remaining letter * of the root. In other words, "Loved/U" should generate "Unloved", * but "LOved/U" should generate "UNLOved" and "lOved/U" should * produce "unlOved". */ if (flent->affl) { icharcpy (tword, flent->affix); nextc = tword + flent->affl; } icharcpy (nextc, rootword + flent->stripl); if (myupper (rootword[0])) { /* We must distinguish followcase from capitalized and all-upper */ for (nextc = rootword + 1; *nextc; nextc++) { if (!myupper (*nextc)) break; } if (*nextc) { /* It's a followcase or capitalized word. Figure out which. */ for ( ; *nextc; nextc++) { if (myupper (*nextc)) break; } if (*nextc) { /* It's followcase. */ if (!myupper (tword[flent->affl])) forcelc (tword, flent->affl); } else { /* It's capitalized */ forcelc (tword + 1, tlen - 1); } } } else { /* Followcase or all-lower, we don't care which */ if (!myupper (*nextc)) forcelc (tword, flent->affl); } if (option == 3) printf ("\n%s", croot); if (option != 4) printf (" %s%s", ichartosstr (tword, 1), extra); if (flent->flagflags & FF_CROSSPRODUCT) return tlen + expand_suf (croot, tword, mask, FF_CROSSPRODUCT, option, extra); else return tlen; }
/* How to print: * 1 = expansions only * 2 = original line + expansions * 3 = original paired w/ expansions * 4 = add length ratio */ static void expandmode(int option) { char buf[BUFSIZ]; int explength; /* Total length of all expansions */ register char *flagp; /* Pointer to next flag char */ ichar_t ibuf[BUFSIZ]; MASKTYPE mask[MASKSIZE]; char origbuf[BUFSIZ]; /* Original contents of buf */ char ratiobuf[20]; /* Expansion/root length ratio */ int rootlength; /* Length of root word */ register int temp; /* char strg_out[MAXSOLLEN]; */ while (xgets(buf, sizeof buf, stdin) != NULL) { rootlength = strlen(buf); if (buf[rootlength - 1] == '\n') buf[--rootlength] = '\0'; strcpy(origbuf, buf); if ((flagp = index(buf, hashheader.flagmarker)) != NULL) { rootlength = flagp - buf; *flagp++ = '\0'; } if (option == 2 || option == 3 || option == 4) printf("%s ", origbuf); if (flagp != NULL) { if (flagp - buf > INPUTWORDLEN) buf[INPUTWORDLEN] = '\0'; } else { if ((int) strlen(buf) > INPUTWORDLEN - 1) buf[INPUTWORDLEN] = '\0'; } fputs(buf, stdout); fputc(' ', stdout); /* strtoichar(ibuf, buf, sizeof ibuf, 1); if (good(ibuf, 0, 0, 0)) { get_info(hits[0]); sprintf(strg_out, o_form, root, macro(root_class), pre_class, macro(suf_class), suf2_class); printf("%s ", strg_out); } */ if (flagp != NULL) { bzero((char *) mask, sizeof(mask)); while (*flagp != '\0' && *flagp != '\n') { #if MASKBITS <= 32 temp = CHARTOBIT(mytoupper(chartoichar(*flagp))); #else temp = CHARTOBIT((unsigned char) *flagp); #endif if (temp >= 0 && temp <= LARGESTFLAG) SETMASKBIT (mask, temp); flagp++; /* Accept old-format dicts with extra slashes */ if (*flagp == hashheader.flagmarker) flagp++; } if (strtoichar(ibuf, buf, sizeof ibuf, 1)) fprintf(stderr, WORD_TOO_LONG(buf)); explength = expand_pre(origbuf, ibuf, mask, option, ""); explength += expand_suf(origbuf, ibuf, mask, 0, option, "", ""); explength += rootlength; if (option == 4) { sprintf(ratiobuf, " %f", (double) explength / (double) rootlength); fputs(ratiobuf, stdout); expand_pre(origbuf, ibuf, mask, 3, ratiobuf); expand_suf(origbuf, ibuf, mask, 0, 3, ratiobuf, ""); } } printf(SEP4); } }