209 #include "ispell_checker.h"
212 int makedent P ((
char * lbuf,
int lbuflen,
struct dent * ent));
225 void toutent P ((FILE * outfile,
struct dent * hent,
231 #ifndef ICHAR_IS_CHAR
232 ichar_t * icharcpy P ((ichar_t * out, ichar_t * in));
233 int icharlen P ((ichar_t * str));
234 int icharcmp P ((ichar_t * s1, ichar_t * s2));
235 int icharncmp P ((ichar_t * s1, ichar_t * s2,
int n));
249 #ifndef NO_CAPITALIZATION_SUPPORT
259 ISpellChecker::whatcap (ichar_t *word)
263 for (p = word; *p; p++)
286 if (myupper (word[0]))
288 for (p = word + 1; *p !=
'\0'; p++)
311 int ISpellChecker::addvheader (
struct dent *dp)
319 tdent =
static_cast<struct dent *
>(malloc(
sizeof (
struct dent)));
322 fprintf (stderr, MAKEDENT_C_NO_WORD_SPACE, dp->word);
326 if (captype (tdent->flagfield) != FOLLOWCASE)
331 tdent->word =
static_cast<char *
>(malloc (
static_cast<unsigned int>(strlen(tdent->word)) + 1));
332 if (tdent->word == NULL)
334 fprintf (stderr, MAKEDENT_C_NO_WORD_SPACE, dp->word);
335 free (
reinterpret_cast<char *
>(tdent));
338 strcpy (tdent->word, dp->word);
342 dp->flagfield &= ~CAPTYPEMASK;
343 dp->flagfield |= (ALLCAPS | MOREVARIANTS);
425 ISpellChecker::upcase (ichar_t *s)
439 ISpellChecker::lowcase (ichar_t *s)
456 ISpellChecker::chupcase (
char *s)
460 is = strtosichar (s, 1);
462 ichartostr (s, is, strlen (s) + 1, 1);
498 ISpellChecker::stringcharlen (
char *bufp,
int canonical)
501 static char * sp[MAXSTRINGCHARS];
502 static int inited = 0;
515 for (stringno = 0; stringno < MAXSTRINGCHARS; stringno++)
516 sp[stringno] = &hashheader.stringchars[stringno][0];
520 highstringno = m_hashheader.nstrchars - 1;
521 dupwanted = canonical ? 0 : m_defdupchar;
522 while (lowstringno <= highstringno)
524 stringno = (lowstringno + highstringno) >> 1;
526 stringcur = sp[stringno];
528 stringcur = &m_hashheader.stringchars[stringno][0];
534 if (((*bufcur++ ^ *stringcur) & 0x7F) != 0)
536 if (*bufcur++ != *stringcur)
545 if (*stringcur ==
'\0')
547 if (m_hashheader.dupnos[stringno] == dupwanted)
550 m_laststringch = m_hashheader.stringdups[stringno];
552 return stringcur - sp[stringno];
554 return stringcur - &m_hashheader.stringchars[stringno][0];
562 if ((*--bufcur & 0x7F) < (*stringcur & 0x7F))
563 highstringno = stringno - 1;
564 else if ((*bufcur & 0x7F) > (*stringcur & 0x7F))
565 lowstringno = stringno + 1;
567 if (*--bufcur < *stringcur)
568 highstringno = stringno - 1;
569 else if (*bufcur > *stringcur)
570 lowstringno = stringno + 1;
572 else if (dupwanted < m_hashheader.dupnos[stringno])
573 highstringno = stringno - 1;
575 lowstringno = stringno + 1;
577 m_laststringch =
static_cast<unsigned int>(-1);
595 #define isstringch(ptr, canon) (isstringstart (*(ptr)) \
596 && stringcharlen ((ptr), (canon)) > 0)
603 #define l_isstringch(ptr, len, canon) \
604 (isstringstart (*(ptr)) \
605 && (len = stringcharlen ((ptr), (canon))) \
613 #define l1_isstringch(ptr, len, canon) \
615 isstringstart ((unsigned char)(*(ptr))) \
617 stringcharlen ((ptr), (canon))) \
641 ISpellChecker::strtoichar (ichar_t *out,
char *in,
int outlen,
int canonical)
645 outlen /=
sizeof (ichar_t);
646 for ( ; --outlen > 0 && *in !=
'\0'; in += len)
648 if (l1_isstringch (in, len , canonical)) {
649 *out++ = SET_SIZE + m_laststringch;
651 *out++ = (
unsigned char)( *in );
674 ISpellChecker::ichartostr (
char *out, ichar_t *in,
int outlen,
int canonical)
680 while (--outlen > 0 && (ch = *in++) != 0)
683 *out++ =
static_cast<char>(ch);
689 for (i = m_hashheader.nstrchars; --i >= 0; )
691 if (m_hashheader.dupnos[i] == m_defdupchar
692 && (
static_cast<int>(m_hashheader.stringdups[i])) == ch)
699 scharp = m_hashheader.stringchars[
static_cast<unsigned>(ch)];
700 while ((*out++ = *scharp++) !=
'\0')
718 ISpellChecker::strtosichar (
char *in,
int canonical)
720 static ichar_t out[STRTOSICHAR_SIZE /
sizeof (ichar_t)];
722 if (strtoichar (out, in,
sizeof out, canonical))
723 fprintf (stderr, WORD_TOO_LONG (in));
736 ISpellChecker::ichartosstr (ichar_t *in,
int canonical)
738 static char out[ICHARTOSSTR_SIZE];
740 if (ichartostr (out, in,
sizeof out, canonical))
741 fprintf (stderr, WORD_TOO_LONG (out));
754 ISpellChecker::printichar (
int in)
756 static char out[MAXSTRINGCHARLEN + 1];
760 out[0] =
static_cast<char>(in);
764 strcpy (out, m_hashheader.stringchars[
static_cast<unsigned>(in) - SET_SIZE]);
768 #ifndef ICHAR_IS_CHAR
778 icharcpy (ichar_t *out, ichar_t *in)
783 while ((*out++ = *in++) != 0)
796 icharlen (ichar_t * in)
800 for (len = 0; *in++ != 0; len++)
814 icharcmp (ichar_t * s1, ichar_t * s2)
820 return *--s1 - *--s2;
835 icharncmp (ichar_t *s1, ichar_t *s2,
int n)
838 while (--n >= 0 && *s1 != 0)
841 return *--s1 - *--s2;
860 ISpellChecker::findfiletype (
const char *name,
int searchnames,
int *deformatter)
875 for (i = 0; i < m_hashheader.nstrchartype; i++)
877 if (strcmp (name, m_chartypes[i].name) == 0)
879 if (deformatter != NULL)
881 (strcmp (m_chartypes[i].deformatter,
"tex") == 0);
886 for (i = 0; i < m_hashheader.nstrchartype; i++)
888 for (cp = m_chartypes[i].suffixes; *cp !=
'\0'; cp += cplen + 1)
891 if (len >= cplen && strcmp (&name[len - cplen], cp) == 0)
893 if (deformatter != NULL)
895 (strcmp (m_chartypes[i].deformatter,
"tex") == 0);
911 char ISpellChecker::myupper(ichar_t c)
913 if (c < (SET_SIZE + MAXSTRINGCHARS))
914 return m_hashheader.upperchars[c];
919 char ISpellChecker::mylower(ichar_t c)
921 if (c < (SET_SIZE + MAXSTRINGCHARS))
922 return m_hashheader.lowerchars[c];
927 int myspace(ichar_t c)
929 return ((c > 0) && (c < 0x80) && isspace(
static_cast<unsigned char>(c)));
932 char ISpellChecker::iswordch(ichar_t c)
934 if (c < (SET_SIZE + MAXSTRINGCHARS))
935 return m_hashheader.wordchars[c];
940 char ISpellChecker::isboundarych(ichar_t c)
942 if (c < (SET_SIZE + MAXSTRINGCHARS))
943 return m_hashheader.boundarychars[c];
948 char ISpellChecker::isstringstart(ichar_t c)
951 return m_hashheader.stringstarts[
static_cast<unsigned char>(c)];
956 ichar_t ISpellChecker::mytolower(ichar_t c)
958 if (c < (SET_SIZE + MAXSTRINGCHARS))
959 return m_hashheader.lowerconv[c];
964 ichar_t ISpellChecker::mytoupper (ichar_t c)
966 if (c < (SET_SIZE + MAXSTRINGCHARS))
967 return m_hashheader.upperconv[c];