Esempio n. 1
0
/*!
 * Convert a string to an ichar_t, storing the result in a static area.
 *
 * \param in String to convert
 * \param canonical NZ if input is in canonical form
 *
 * \return
 */
ichar_t *ISpellChecker::strtosichar(char *in, int canonical)
{
    static ichar_t out[STRTOSICHAR_SIZE / sizeof(ichar_t)];

    if(strtoichar(out, in, sizeof out, canonical))
        fprintf(stderr, WORD_TOO_LONG(in));
    return out;
}
Esempio n. 2
0
/*
 * \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;
}
Esempio n. 3
0
bool
ISpellChecker::checkWord(const char * const utf8Word, size_t length)
{	
	ichar_t iWord[INPUTWORDLEN + MAXAFFIXLEN];
	char szWord[INPUTWORDLEN + MAXAFFIXLEN];
	
	if (!m_bSuccessfulInit)
		return false;
	
	if (!utf8Word || length >= (INPUTWORDLEN + MAXAFFIXLEN) || length == 0)
		return false;
	
	bool retVal = false;

	if (!g_iconv_is_valid(m_translate_in))
		return false;	
	else
		{
			/* convert to 8bit string and null terminate */
			size_t len_in, len_out, result;
			// the 8bit encodings use precomposed forms
			char *normalizedWord = g_utf8_normalize (utf8Word, length, G_NORMALIZE_NFC);
			char *In = normalizedWord;
			char *Out = szWord;
			
			len_in = strlen(In);
			len_out = sizeof( szWord ) - 1;
			result = g_iconv(m_translate_in, &In, &len_in, &Out, &len_out);
			g_free(normalizedWord);
			if ((size_t)-1 == result)
				return false;
			*Out = '\0';
		}
	
	if (!strtoichar(iWord, szWord, sizeof(iWord), 0))
		{
			if (good(iWord, 0, 0, 1, 0) == 1 ||
			    compoundgood(iWord, 1) == 1)
				{
					retVal = true;
				}
		}
	
	return retVal;
}
Esempio n. 4
0
/*
 * \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;
}
Esempio n. 5
0
/* 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);
    }
}